From c715fbaf95cf866e0f47eed77562c5ebe2d0e775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Thu, 30 May 2024 01:37:07 +0000 Subject: [PATCH] WIP --- README.md | 28 +++--------- attributes/default.rb | 25 +++------- recipes/_common.rb | 4 -- recipes/_systemd.rb | 58 ++++++++++++------------ recipes/binary.rb | 2 +- recipes/package.rb | 47 ------------------- recipes/source.rb | 2 +- templates/default/bitcoind.service.erb | 21 --------- test.sh | 2 +- test/integration/default/bitcoin_spec.rb | 2 +- 10 files changed, 44 insertions(+), 147 deletions(-) delete mode 100644 recipes/package.rb delete mode 100644 templates/default/bitcoind.service.erb diff --git a/README.md b/README.md index 968a6d7..c603f18 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Bitcoin Cookbook ================ + +[![Funding](https://img.shields.io/liberapay/patrons/infertux.svg?logo=liberapay)](https://liberapay.com/infertux/donate) [![Cookbook](https://img.shields.io/cookbook/v/bitcoin.svg)](https://supermarket.getchef.com/cookbooks/bitcoin) -[![Build Status](https://api.travis-ci.org/infertux/chef-bitcoin.svg?branch=master)](https://travis-ci.org/infertux/chef-bitcoin) +[![Build Status](https://github.com/infertux/chef-bitcoin/actions/workflows/test.yml/badge.svg)](https://github.com/infertux/chef-bitcoin/actions) This cookbook downloads, installs and configures Bitcoin as a full node. @@ -16,33 +18,15 @@ This cookbook does *not* make sure your port 8333 is open since this is very muc Usage ----- -### Comparison table - -| recipe: | package | binary | source | -| :--- | :---: | :---: | :---: | -| supported distributions | RHEL & CentOS | **any** | **any** | -| supported architectures | x86_64 & aarch64 | x86_64 | **any** | -| supported variants | ABC, Core & XT | ABC, Core & Unlimited (Cash) | ABC, Core & Unlimited (Cash) | - -The matrix of supported configurations can be found [there](https://travis-ci.org/infertux/chef-bitcoin). - -You must select a Bitcoin fork/variant using `node['bitcoin']['variant'] = 'foobar'`. - -The valid variants are `abc`, `bucash`, `core`, `unlimited`, and `xt`. - -### `bitcoin::package` recipe - -Configures repository from http://www.ringingliberty.com/bitcoin/ and installs pre-packaged binary with `bitcoin` systemd service. - ### `bitcoin::binary` recipe -Downloads the binary and copies it along with an systemd service script. +Downloads the binary and copies it along with an systemd service unit. ### `bitcoin::source` recipe -Downloads the release from GitHub and compiles it along with an systemd service script. +Downloads the source code and compiles it along with an systemd service unit. -Caution: you'll need at least 1 GB of free RAM to compile it (setting `make_options` to `-j1` can help too). +Caution: you'll need at least 1 GB of free RAM to compile it (setting `make_options` to `-j1` can help on low-end machines). License ------- diff --git a/attributes/default.rb b/attributes/default.rb index b17425e..86a1b4a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -10,10 +10,9 @@ default['bitcoin']['binary_name'] = 'bitcoind' default['bitcoin']['binary_cli_name'] = 'bitcoin-cli' default['bitcoin']['user'] = 'bitcoin' -default['bitcoin']['home'] = "/home/#{node['bitcoin']['user']}" +default['bitcoin']['home'] = "/var/lib/#{node['bitcoin']['user']}" default['bitcoin']['conf_dir'] = "#{node['bitcoin']['home']}/.bitcoin" default['bitcoin']['conf_file'] = "#{node['bitcoin']['conf_dir']}/bitcoin.conf" -default['bitcoin']['service_file'] = "/usr/lib/systemd/system/#{node['bitcoin']['binary_name']}.service" default['bitcoin']['archive_file'] = "#{node['bitcoin']['variant']}.tar.gz" default['bitcoin']['archive_path'] = "#{Chef::Config['file_cache_path']}/bitcoin/#{node['bitcoin']['archive_file']}" default['bitcoin']['extract_path'] = "#{Chef::Config['file_cache_path']}/bitcoin/#{node['bitcoin']['variant']}" @@ -28,30 +27,18 @@ default['bitcoin']['binary']['url']['core'] = "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['binary']['version']['core']}/bitcoin-#{node['bitcoin']['binary']['version']['core']}-x86_64-linux-gnu.tar.gz" default['bitcoin']['binary']['checksum']['core'] = '2a6974c5486f528793c79d42694b5987401e4a43c97f62b1383abf35bcee44a8' -# 'package' recipe - -default['bitcoin']['package']['repo_url']['rhel'] = 'https://linux.ringingliberty.com/bitcoin/el7/x86_64/bitcoin-release-4-1.noarch.rpm' -default['bitcoin']['package']['repo_checksum']['rhel'] = 'dcba5cb150b8af5a2c1ebec2c9d0255c8b5221c1002469f2170a679e60908ec5' -default['bitcoin']['package']['repo_url']['fedora'] = 'https://linux.ringingliberty.com/bitcoin/f27/x86_64/bitcoin-release-4-1.noarch.rpm' -default['bitcoin']['package']['repo_checksum']['fedora'] = 'cac67430e1e76b1b740cd7967e0038ba7989c3fde0660a30bfd22a233e33f708' - # 'source' recipe default['bitcoin']['source']['version']['core'] = '27.0' -default['bitcoin']['source']['url']['core'] = "https://github.com/bitcoin/bitcoin/archive/#{node['bitcoin']['source']['version']['core']}.tar.gz" +default['bitcoin']['source']['url']['core'] = "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['binary']['version']['core']}/bitcoin-#{node['bitcoin']['source']['version']['core']}.tar.gz" default['bitcoin']['source']['checksum']['core'] = '9c1ee651d3b157baccc3388be28b8cf3bfcefcd2493b943725ad6040ca6b146b' default['bitcoin']['source']['dependencies']['debian'] = %w( - build-essential libtool autoconf pkg-config libssl-dev libevent-dev - libboost-system-dev libboost-filesystem-dev libboost-chrono-dev - libboost-program-options-dev libboost-test-dev libboost-thread-dev - libboost-system-dev libboost-test-dev libboost-thread-dev -) -default['bitcoin']['source']['dependencies']['rhel'] = %w( - gcc-c++ libtool make file autoconf automake openssl-devel libevent-devel - boost-devel + build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 + libevent-dev libboost-dev + systemtap-sdt-devel ) default['bitcoin']['source']['dependencies']['freebsd'] = %w( autoconf automake libtool pkgconf gmake boost-all openssl ).join(' ') default['bitcoin']['source']['configure_options'] = "--with-gui=no --disable-wallet --without-miniupnpc --disable-zmq --disable-tests --prefix=#{node['bitcoin']['prefix']}" -default['bitcoin']['source']['make_options'] = '-j1' +default['bitcoin']['source']['make_options'] = '-j $(nproc)' diff --git a/recipes/_common.rb b/recipes/_common.rb index 8b78547..b82ea29 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -3,10 +3,6 @@ # Recipe:: _common # -unless node['bitcoin']['variant'] - raise "You must select the variant you wish to install with `node['bitcoin']['variant'] = $variant'. Possible variants are abc, bucash, core, unlimited, and xt." -end - user node['bitcoin']['user'] do home node['bitcoin']['home'] shell '/bin/sh' diff --git a/recipes/_systemd.rb b/recipes/_systemd.rb index 938eb73..49b84d2 100644 --- a/recipes/_systemd.rb +++ b/recipes/_systemd.rb @@ -3,37 +3,35 @@ # Recipe:: _systemd # -directory File.dirname(node['bitcoin']['service_file']) do - user 'root' - group 'root' - mode '0755' - only_if 'test -f /bin/systemctl && /bin/systemctl' -end +systemd_unit "#{node['bitcoin']['binary_name']}.service" do + content <<~SYSTEMD + [Unit] + Description=Bitcoin daemon + After=network.target -template node['bitcoin']['service_file'] do - source "#{node['bitcoin']['binary_name']}.service.erb" - owner 'root' - group 'root' - mode '0644' - variables( - user: node['bitcoin']['user'], - binary_path: node['bitcoin']['binary_path'], - conf_dir: node['bitcoin']['conf_dir'], - ) - notifies :run, 'execute[systemd-daemon-reload]', :immediately - only_if 'test -f /bin/systemctl && /bin/systemctl' -end + [Service] + User=#{node['bitcoin']['user']} + Group=#{node['bitcoin']['user']} -service node['bitcoin']['binary_name'] do - provider Chef::Provider::Service::Systemd - action [:enable] - subscribes :restart, "template[#{node['bitcoin']['service_file']}]", :delayed - subscribes :restart, "template[#{node['bitcoin']['conf_file']}]", :delayed - only_if 'test -f /bin/systemctl && /bin/systemctl' -end + Type=forking + PIDFile=#{node['bitcoin']['conf_dir']}/bitcoind.pid + ExecStart=#{node['bitcoin']['binary_path']} -daemon -pid=#{node['bitcoin']['conf_dir']}/bitcoind.pid + + PrivateTmp=true + ProtectHome=true + ProtectProc=invisible + ProtectSystem=full + + Restart=on-failure + TimeoutStopSec=60 + TimeoutStartSec=5 + StartLimitInterval=120 + StartLimitBurst=5 + + [Install] + WantedBy=multi-user.target + SYSTEMD -execute 'systemd-daemon-reload' do - action :nothing - command 'systemctl daemon-reload' - only_if 'test -f /bin/systemctl && /bin/systemctl' + action %i(create enable) + notifies :restart, "systemd_unit[#{node['bitcoin']['binary_name']}.service]" end diff --git a/recipes/binary.rb b/recipes/binary.rb index d91d510..ff431c8 100644 --- a/recipes/binary.rb +++ b/recipes/binary.rb @@ -33,4 +33,4 @@ SCRIPT end -include_recipe 'bitcoin::_systemd' +include_recipe 'bitcoin::_systemd' if systemd? diff --git a/recipes/package.rb b/recipes/package.rb deleted file mode 100644 index 12c983e..0000000 --- a/recipes/package.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# Cookbook:: bitcoin -# Recipe:: package -# - -include_recipe 'bitcoin::_common' - -repo_url = node['bitcoin']['package']['repo_url'][node['platform_family']] -repo_file = ::File.basename(repo_url) -repo_path = "#{Chef::Config['file_cache_path']}/bitcoin/#{repo_file}" - -directory ::File.dirname(repo_path) do - recursive true -end - -remote_file repo_path do - source repo_url - checksum node['bitcoin']['package']['repo_checksum'][node['platform_family']] -end - -package 'bitcoin-release' do - source repo_path -end - -variant = \ - case node['bitcoin']['variant'] - when 'abc' then 'bitcoin-abc' - when 'core' then 'bitcoin' - when 'xt' then 'bitcoinxt' - else raise 'Valid variants are abc, core and xt.' - end - -package "#{variant}-server" do - only_if do - Chef::Log.warn('The installation of bitcoin may take several minutes while the SELinux policies are being built.') - - true # NOTE: just a hack to display the above message at the right time - end -end - -package "#{variant}-utils" - -service node['bitcoin']['binary_name'] do - provider Chef::Provider::Service::Systemd - action [:enable] - only_if 'test -f /bin/systemctl && /bin/systemctl' -end diff --git a/recipes/source.rb b/recipes/source.rb index d2612d6..4f91929 100644 --- a/recipes/source.rb +++ b/recipes/source.rb @@ -50,4 +50,4 @@ SCRIPT end -include_recipe 'bitcoin::_systemd' +include_recipe 'bitcoin::_systemd' if systemd? diff --git a/templates/default/bitcoind.service.erb b/templates/default/bitcoind.service.erb deleted file mode 100644 index b7c5344..0000000 --- a/templates/default/bitcoind.service.erb +++ /dev/null @@ -1,21 +0,0 @@ -[Unit] -Description=Bitcoin daemon -After=network.target - -[Service] -User=<%= @user %> -Group=<%= @user %> - -Type=forking -PIDFile=<%= @conf_dir %>/bitcoind.pid -ExecStart=<%= @binary_path %> -daemon -pid=<%= @conf_dir %>/bitcoind.pid - -Restart=always -PrivateTmp=true -TimeoutStopSec=60s -TimeoutStartSec=5s -StartLimitInterval=120s -StartLimitBurst=5 - -[Install] -WantedBy=multi-user.target diff --git a/test.sh b/test.sh index 080491f..bf35e3a 100755 --- a/test.sh +++ b/test.sh @@ -2,7 +2,7 @@ set -o pipefail -# e.g. to use filter: ./test.sh KITCHEN_VARIANT=abc +# e.g. to use filter: ./test.sh KITCHEN_VARIANT=core filter="${1:-}" envs="$(grep -Eo 'KITCHEN_PLATFORM=.*$' .travis.yml | grep -v 'KITCHEN_PLATFORM=ubuntu')" diff --git a/test/integration/default/bitcoin_spec.rb b/test/integration/default/bitcoin_spec.rb index 9b5eb2e..39197b1 100644 --- a/test/integration/default/bitcoin_spec.rb +++ b/test/integration/default/bitcoin_spec.rb @@ -1,4 +1,4 @@ describe command('sudo -u bitcoin -- bitcoin-cli -version') do its('exit_status') { should eq 0 } - its('stdout') { should include "Bitcoin Core RPC client" } + its('stdout') { should include 'Bitcoin Core RPC client' } end