Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
infertux committed May 30, 2024
1 parent 00f2f7c commit c715fba
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 147 deletions.
28 changes: 6 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
-------
Expand Down
25 changes: 6 additions & 19 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"
Expand All @@ -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)'
4 changes: 0 additions & 4 deletions recipes/_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
58 changes: 28 additions & 30 deletions recipes/_systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion recipes/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
SCRIPT
end

include_recipe 'bitcoin::_systemd'
include_recipe 'bitcoin::_systemd' if systemd?
47 changes: 0 additions & 47 deletions recipes/package.rb

This file was deleted.

2 changes: 1 addition & 1 deletion recipes/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
SCRIPT
end

include_recipe 'bitcoin::_systemd'
include_recipe 'bitcoin::_systemd' if systemd?
21 changes: 0 additions & 21 deletions templates/default/bitcoind.service.erb

This file was deleted.

2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/default/bitcoin_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c715fba

Please sign in to comment.