128 lines
3.4 KiB
Ruby

#
# Cookbook:: kosmos-bitcoin
# Recipe:: bitcoind
#
build_essential
include_recipe 'ark'
include_recipe 'kosmos-bitcoin::user'
if node["bitcoin"]["blocksdir_mount_type"]
include_recipe "kosmos-bitcoin::blocksdir-mount"
end
apt_repository "ubuntu-toolchain-r" do
# provides g++-13, needed for better c++-20 support
uri "ppa:ubuntu-toolchain-r/test"
end
%w{
gcc-13 g++-13 libtool autotools-dev make automake cmake curl bison
binutils-gold pkg-config python3 patch
}.each do |pkg|
apt_package pkg
end
ark 'bitcoind' do
url "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['version']}/bitcoin-#{node['bitcoin']['version']}.tar.gz"
checksum node['bitcoin']['checksum']
action :put
notifies :run, 'execute[compile_bitcoin-core_dependencies]', :immediately
end
execute "compile_bitcoin-core_dependencies" do
cwd "/usr/local/bitcoind/depends"
environment ({'CC' => 'gcc-13', 'CXX' => 'g++-13', 'NO_QT' => '1'})
command "make -j $(($(nproc)/2))"
action :nothing
notifies :run, 'bash[compile_bitcoin-core]', :immediately
end
bash "compile_bitcoin-core" do
cwd "/usr/local/bitcoind"
environment ({'CC' => 'gcc-13', 'CXX' => 'g++-13', 'NO_QT' => '1'})
code <<-EOH
cmake -B build --toolchain depends/x86_64-pc-linux-gnu/toolchain.cmake
cmake --build build -j $(($(nproc)/2))
cmake --install build
EOH
action :nothing
end
bitcoin_user = node['bitcoin']['username']
bitcoin_group = node['bitcoin']['usergroup']
bitcoin_datadir = node['bitcoin']['datadir']
bitcoin_walletdir = node['bitcoin']['walletdir']
bitcoin_conf_path = node['bitcoin']['conf_path']
credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin')
if node['bitcoin']['tor_enabled']
group 'debian-tor' do
action :modify
members bitcoin_user
append true
end
end
[bitcoin_datadir, bitcoin_walletdir].each do |path|
directory path do
owner bitcoin_user
group bitcoin_group
mode '0750'
recursive true
action :create
end
end
if bitcoin_blocksdir = node["bitcoin"]["blocksdir"]
bitcoind_blocksdir_argument = "-blocksdir=#{bitcoin_blocksdir}"
end
bitcoin_config = node['bitcoin']['conf'].merge({
rpcpassword: credentials["rpcpassword"]
})
template bitcoin_conf_path do
owner bitcoin_user
group bitcoin_group
mode '0640'
variables conf: bitcoin_config,
mainnet_conf: node['bitcoin']['mainnet_conf'],
testnet_conf: node['bitcoin']['testnet_conf'],
regtest_conf: node['bitcoin']['regtest_conf']
action :create
notifies :restart, "systemd_unit[bitcoind.service]", :delayed
end
systemd_unit 'bitcoind.service' do
content({
Unit: {
Description: 'Bitcoin Core daemon',
Documentation: ['https://bitcoincore.org'],
After: 'network.target'
},
Service: {
User: bitcoin_user,
Type: 'simple',
ExecStart: "bitcoind -conf=#{bitcoin_conf_path} -datadir=#{bitcoin_datadir} -walletdir=#{bitcoin_walletdir} #{bitcoind_blocksdir_argument} -pid=#{bitcoin_datadir}/bitcoind.pid",
PIDFile: "#{bitcoin_datadir}/bitcoind.pid",
Restart: 'always',
PrivateTmp: true,
LimitNOFILE: 'infinity',
TimeoutStopSec: '60s',
TimeoutStartSec: '20s',
StartLimitInterval: '60s',
StartLimitBurst: '2'
},
Install: {
WantedBy: 'multi-user.target'
}
})
verify false
triggers_reload true
action [:create, :enable, :start]
end
include_recipe "kosmos-bitcoin::firewall"