Storing all chain data in encfs caused unsolvable issues with leveldb. So now we're only storing wallet data in the encrypted dir.
152 lines
4.4 KiB
Ruby
152 lines
4.4 KiB
Ruby
#
|
|
# Cookbook:: kosmos-bitcoin
|
|
# Recipe:: source
|
|
#
|
|
# The MIT License (MIT)
|
|
#
|
|
# Copyright:: 2020, Kosmos Developers
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
# THE SOFTWARE.
|
|
#
|
|
|
|
include_recipe 'ark'
|
|
|
|
build_essential
|
|
|
|
%w{ libtool autotools-dev make automake cmake curl g++-multilib libtool
|
|
binutils-gold bsdmainutils 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
|
|
end
|
|
|
|
execute "Compile bitcoin-core dependencies" do
|
|
cwd "/usr/local/bitcoind/depends"
|
|
command "make NO_QT=1"
|
|
not_if { ::File.directory?("/usr/local/bitcoind/depends/x86_64-pc-linux-gnu") }
|
|
end
|
|
|
|
execute "Configure bitcoin-core" do
|
|
cwd "/usr/local/bitcoind"
|
|
command [
|
|
"./autogen.sh",
|
|
"./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu"
|
|
]
|
|
not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") }
|
|
end
|
|
|
|
execute "Compile bitcoin-core" do
|
|
cwd "/usr/local/bitcoind"
|
|
command "make"
|
|
not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") }
|
|
end
|
|
|
|
link "/usr/local/bin/bitcoind" do
|
|
to "/usr/local/bitcoind/src/bitcoind"
|
|
end
|
|
|
|
link "/usr/local/bin/bitcoin-cli" do
|
|
to "/usr/local/bitcoind/src/bitcoin-cli"
|
|
end
|
|
|
|
bitcoin_user = node['bitcoin']['username']
|
|
bitcoin_group = node['bitcoin']['usergroup']
|
|
bitcoin_datadir = node['bitcoin']['datadir']
|
|
bitcoin_walletdir = node['bitcoin']['walletdir']
|
|
credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin')
|
|
|
|
group bitcoin_group
|
|
|
|
user bitcoin_user do
|
|
manage_home true
|
|
gid bitcoin_group
|
|
shell "/bin/bash"
|
|
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
|
|
|
|
config = node['bitcoin']['conf'].merge({
|
|
rpcpassword: credentials["rpcpassword"]
|
|
})
|
|
|
|
template "#{bitcoin_datadir}/bitcoin.conf" do
|
|
owner bitcoin_user
|
|
group bitcoin_group
|
|
mode '0640'
|
|
variables conf: 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 -datadir=#{bitcoin_datadir} -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, :start]
|
|
end
|
|
|
|
# Creates/starts a Path unit which starts the bitcoind service when the
|
|
# encrypted data directory is mounted
|
|
# TODO move to custom kosmos cookbook before publishing bitcoin cookbook
|
|
encfs_path_activation_unit 'bitcoind.service'
|
|
|
|
# TODO move to custom kosmos cookbook before publishing bitcoin cookbook
|
|
firewall_rule 'bitcoind' do
|
|
port [8333] # TODO adjust for testnet
|
|
protocol :tcp
|
|
command :allow
|
|
end
|