Skip to content

Commit 049a301

Browse files
committed
WIP
1 parent 00f2f7c commit 049a301

File tree

10 files changed

+41
-143
lines changed

10 files changed

+41
-143
lines changed

README.md

+6-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Bitcoin Cookbook
22
================
3+
4+
[![Funding](https://img.shields.io/liberapay/patrons/infertux.svg?logo=liberapay)](https://liberapay.com/infertux/donate)
35
[![Cookbook](https://img.shields.io/cookbook/v/bitcoin.svg)](https://supermarket.getchef.com/cookbooks/bitcoin)
4-
[![Build Status](https://api.travis-ci.org/infertux/chef-bitcoin.svg?branch=master)](https://travis-ci.org/infertux/chef-bitcoin)
6+
[![Build Status](https://github.com/infertux/chef-bitcoin/actions/workflows/test.yml/badge.svg)](https://github.com/infertux/chef-bitcoin/actions)
57

68
This cookbook downloads, installs and configures Bitcoin as a full node.
79

@@ -16,33 +18,15 @@ This cookbook does *not* make sure your port 8333 is open since this is very muc
1618
Usage
1719
-----
1820

19-
### Comparison table
20-
21-
| recipe: | package | binary | source |
22-
| :--- | :---: | :---: | :---: |
23-
| supported distributions | RHEL & CentOS | **any** | **any** |
24-
| supported architectures | x86_64 & aarch64 | x86_64 | **any** |
25-
| supported variants | ABC, Core & XT | ABC, Core & Unlimited (Cash) | ABC, Core & Unlimited (Cash) |
26-
27-
The matrix of supported configurations can be found [there](https://travis-ci.org/infertux/chef-bitcoin).
28-
29-
You must select a Bitcoin fork/variant using `node['bitcoin']['variant'] = 'foobar'`.
30-
31-
The valid variants are `abc`, `bucash`, `core`, `unlimited`, and `xt`.
32-
33-
### `bitcoin::package` recipe
34-
35-
Configures repository from http://www.ringingliberty.com/bitcoin/ and installs pre-packaged binary with `bitcoin` systemd service.
36-
3721
### `bitcoin::binary` recipe
3822

39-
Downloads the binary and copies it along with an systemd service script.
23+
Downloads the binary and copies it along with an systemd service unit.
4024

4125
### `bitcoin::source` recipe
4226

43-
Downloads the release from GitHub and compiles it along with an systemd service script.
27+
Downloads the source code and compiles it along with an systemd service unit.
4428

45-
Caution: you'll need at least 1 GB of free RAM to compile it (setting `make_options` to `-j1` can help too).
29+
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).
4630

4731
License
4832
-------

attributes/default.rb

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
default['bitcoin']['binary_name'] = 'bitcoind'
1111
default['bitcoin']['binary_cli_name'] = 'bitcoin-cli'
1212
default['bitcoin']['user'] = 'bitcoin'
13-
default['bitcoin']['home'] = "/home/#{node['bitcoin']['user']}"
13+
default['bitcoin']['home'] = "/var/lib/#{node['bitcoin']['user']}"
1414
default['bitcoin']['conf_dir'] = "#{node['bitcoin']['home']}/.bitcoin"
1515
default['bitcoin']['conf_file'] = "#{node['bitcoin']['conf_dir']}/bitcoin.conf"
16-
default['bitcoin']['service_file'] = "/usr/lib/systemd/system/#{node['bitcoin']['binary_name']}.service"
1716
default['bitcoin']['archive_file'] = "#{node['bitcoin']['variant']}.tar.gz"
1817
default['bitcoin']['archive_path'] = "#{Chef::Config['file_cache_path']}/bitcoin/#{node['bitcoin']['archive_file']}"
1918
default['bitcoin']['extract_path'] = "#{Chef::Config['file_cache_path']}/bitcoin/#{node['bitcoin']['variant']}"
@@ -28,30 +27,19 @@
2827
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"
2928
default['bitcoin']['binary']['checksum']['core'] = '2a6974c5486f528793c79d42694b5987401e4a43c97f62b1383abf35bcee44a8'
3029

31-
# 'package' recipe
32-
33-
default['bitcoin']['package']['repo_url']['rhel'] = 'https://linux.ringingliberty.com/bitcoin/el7/x86_64/bitcoin-release-4-1.noarch.rpm'
34-
default['bitcoin']['package']['repo_checksum']['rhel'] = 'dcba5cb150b8af5a2c1ebec2c9d0255c8b5221c1002469f2170a679e60908ec5'
35-
default['bitcoin']['package']['repo_url']['fedora'] = 'https://linux.ringingliberty.com/bitcoin/f27/x86_64/bitcoin-release-4-1.noarch.rpm'
36-
default['bitcoin']['package']['repo_checksum']['fedora'] = 'cac67430e1e76b1b740cd7967e0038ba7989c3fde0660a30bfd22a233e33f708'
37-
3830
# 'source' recipe
3931

4032
default['bitcoin']['source']['version']['core'] = '27.0'
41-
default['bitcoin']['source']['url']['core'] = "https://github.com/bitcoin/bitcoin/archive/#{node['bitcoin']['source']['version']['core']}.tar.gz"
33+
default['bitcoin']['source']['url']['core'] = "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['binary']['version']['core']}/bitcoin-#{node['bitcoin']['source']['version']['core']}.tar.gz"
4234
default['bitcoin']['source']['checksum']['core'] = '9c1ee651d3b157baccc3388be28b8cf3bfcefcd2493b943725ad6040ca6b146b'
4335
default['bitcoin']['source']['dependencies']['debian'] = %w(
4436
build-essential libtool autoconf pkg-config libssl-dev libevent-dev
4537
libboost-system-dev libboost-filesystem-dev libboost-chrono-dev
4638
libboost-program-options-dev libboost-test-dev libboost-thread-dev
4739
libboost-system-dev libboost-test-dev libboost-thread-dev
4840
)
49-
default['bitcoin']['source']['dependencies']['rhel'] = %w(
50-
gcc-c++ libtool make file autoconf automake openssl-devel libevent-devel
51-
boost-devel
52-
)
5341
default['bitcoin']['source']['dependencies']['freebsd'] = %w(
5442
autoconf automake libtool pkgconf gmake boost-all openssl
5543
).join(' ')
5644
default['bitcoin']['source']['configure_options'] = "--with-gui=no --disable-wallet --without-miniupnpc --disable-zmq --disable-tests --prefix=#{node['bitcoin']['prefix']}"
57-
default['bitcoin']['source']['make_options'] = '-j1'
45+
default['bitcoin']['source']['make_options'] = '-j $(nproc)'

recipes/_common.rb

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# Recipe:: _common
44
#
55

6-
unless node['bitcoin']['variant']
7-
raise "You must select the variant you wish to install with `node['bitcoin']['variant'] = $variant'. Possible variants are abc, bucash, core, unlimited, and xt."
8-
end
9-
106
user node['bitcoin']['user'] do
117
home node['bitcoin']['home']
128
shell '/bin/sh'

recipes/_systemd.rb

+28-30
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,35 @@
33
# Recipe:: _systemd
44
#
55

6-
directory File.dirname(node['bitcoin']['service_file']) do
7-
user 'root'
8-
group 'root'
9-
mode '0755'
10-
only_if 'test -f /bin/systemctl && /bin/systemctl'
11-
end
6+
systemd_unit "#{node['bitcoin']['binary_name']}.service" do
7+
content <<~SYSTEMD
8+
[Unit]
9+
Description=Bitcoin daemon
10+
After=network.target
1211
13-
template node['bitcoin']['service_file'] do
14-
source "#{node['bitcoin']['binary_name']}.service.erb"
15-
owner 'root'
16-
group 'root'
17-
mode '0644'
18-
variables(
19-
user: node['bitcoin']['user'],
20-
binary_path: node['bitcoin']['binary_path'],
21-
conf_dir: node['bitcoin']['conf_dir'],
22-
)
23-
notifies :run, 'execute[systemd-daemon-reload]', :immediately
24-
only_if 'test -f /bin/systemctl && /bin/systemctl'
25-
end
12+
[Service]
13+
User=#{node['bitcoin']['user']}
14+
Group=#{node['bitcoin']['user']}
2615
27-
service node['bitcoin']['binary_name'] do
28-
provider Chef::Provider::Service::Systemd
29-
action [:enable]
30-
subscribes :restart, "template[#{node['bitcoin']['service_file']}]", :delayed
31-
subscribes :restart, "template[#{node['bitcoin']['conf_file']}]", :delayed
32-
only_if 'test -f /bin/systemctl && /bin/systemctl'
33-
end
16+
Type=forking
17+
PIDFile=#{node['bitcoin']['conf_dir']}/bitcoind.pid
18+
ExecStart=#{node['bitcoin']['binary_path']} -daemon -pid=#{node['bitcoin']['conf_dir']}/bitcoind.pid
19+
20+
PrivateTmp=true
21+
ProtectHome=true
22+
ProtectProc=invisible
23+
ProtectSystem=full
24+
25+
Restart=on-failure
26+
TimeoutStopSec=60
27+
TimeoutStartSec=5
28+
StartLimitInterval=120
29+
StartLimitBurst=5
30+
31+
[Install]
32+
WantedBy=multi-user.target
33+
SYSTEMD
3434

35-
execute 'systemd-daemon-reload' do
36-
action :nothing
37-
command 'systemctl daemon-reload'
38-
only_if 'test -f /bin/systemctl && /bin/systemctl'
35+
action %i(create enable)
36+
notifies :restart, "systemd_unit[#{node['bitcoin']['binary_name']}.service]"
3937
end

recipes/binary.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
SCRIPT
3434
end
3535

36-
include_recipe 'bitcoin::_systemd'
36+
include_recipe 'bitcoin::_systemd' if systemd?

recipes/package.rb

-47
This file was deleted.

recipes/source.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
SCRIPT
5151
end
5252

53-
include_recipe 'bitcoin::_systemd'
53+
include_recipe 'bitcoin::_systemd' if systemd?

templates/default/bitcoind.service.erb

-21
This file was deleted.

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -o pipefail
44

5-
# e.g. to use filter: ./test.sh KITCHEN_VARIANT=abc
5+
# e.g. to use filter: ./test.sh KITCHEN_VARIANT=core
66
filter="${1:-}"
77

88
envs="$(grep -Eo 'KITCHEN_PLATFORM=.*$' .travis.yml | grep -v 'KITCHEN_PLATFORM=ubuntu')"
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
describe command('sudo -u bitcoin -- bitcoin-cli -version') do
22
its('exit_status') { should eq 0 }
3-
its('stdout') { should include "Bitcoin Core RPC client" }
3+
its('stdout') { should include 'Bitcoin Core RPC client' }
44
end

0 commit comments

Comments
 (0)