Add systemd service

Plus some refactoring
This commit is contained in:
Basti 2020-01-22 13:37:00 -05:00
parent 4a6a02c137
commit c8122a44f1
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
3 changed files with 35 additions and 78 deletions

View File

@ -32,9 +32,11 @@ execute "snap install bitcoin-core --channel=0.19/stable"
bitcoin_user = node['bitcoin']['username']
bitcoin_group = node['bitcoin']['usergroup']
bitcoin_datadir = node['bitcoin']['datadir']
bitcoin_snapdir = "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin"
user bitcoin_user do
manage_home true
shell "/bin/bash"
end
directory bitcoin_datadir do
@ -53,10 +55,10 @@ template "#{bitcoin_datadir}/bitcoin.conf" do
testnet_conf: node['bitcoin']['testnet_conf'],
regtest_conf: node['bitcoin']['regtest_conf']
action :create
# notifies :reload, "service[bitcoin]", :delayed
# notifies :reload, "service[bitcoind]", :delayed
end
directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do
directory bitcoin_snapdir do
owner bitcoin_user
group bitcoin_group
mode '0750'
@ -64,11 +66,35 @@ directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do
action :create
end
mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do
device node['bitcoin']['datadir']
execute "chown -R #{bitcoin_user}:#{bitcoin_group} /home/#{bitcoin_user}/snap"
mount bitcoin_snapdir do
device bitcoin_datadir
fstype 'none'
options 'bind'
action [:mount]
end
# TODO create systemd service for bitcoin-core.daemon
systemd_unit 'bitcoind.service' do
content({
Unit: {
Description: 'Bitcoin Core daemon',
Documentation: ['https://bitcoincore.org'],
After: 'network.target'
},
Service: {
User: bitcoin_user,
Type: 'exec',
ExecStart: '/snap/bin/bitcoin-core.daemon',
PIDFile: "#{bitcoin_snapdir}/bitcoind.pid",
Restart: 'on-failure',
},
Install: {
WantedBy: 'multi-user.target'
}
})
verify false
triggers_reload true
action :create
end

View File

@ -1,69 +0,0 @@
# Network-related settings:
testnet=0
irc=1
dnsseed=1
upnp=1
checkblocks=10
checklevel=1
txindex=1
whitelist=127.0.0.1
# Maximum number of inbound+outbound connections.
#maxconnections=
listen=1
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
# server=1 tells Bitcoin to accept JSON-RPC commands.
server=1
# You must set rpcuser and rpcpassword to secure the JSON-RPC api
rpcuser=kosmos
rpcpassword=yunobuttcoin
# By default, only RPC connections from localhost are allowed. Specify
# as many rpcallowip= settings as you like to allow connections from
# other hosts (and you may use * as a wildcard character):
#rpcallowip=192.168.1.*
rpcallowip=127.0.0.1
# Listen for RPC connections on this TCP port:
rpcbind=127.0.0.1:8336
# Listen for P2P connections on this TCP port:
port=8335
# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate
# with Bitcoin -server or bitcoind
rpcssl=0
# OpenSSL settings used when rpcssl=1
#rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH
# Miscellaneous options
# Set gen=1 to attempt to generate bitcoins
gen=0
# Use SSE instructions to try to generate bitcoins faster.
#4way=1
# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.
#keypool=100
# Pay an optional transaction fee every time you send bitcoins. Transactions with fees
# are more likely than free transactions to be included in generated blocks, so may
# be validated sooner.
#paytxfee=0.00
# Allow direct connections for the 'pay via IP address' feature.
#allowreceivebyip=1
zmqpubrawblock=tcp://127.0.0.1:8337
zmqpubrawtx=tcp://127.0.0.1:8338

View File

@ -6,14 +6,14 @@
##
<% @conf.each do |key, value| %>
<%= "#{key}=#{value}" %>
<%= "#{key}=#{value}" %>
<% end %>
<% if @mainnet_conf %>
# Options only for mainnet
[main]
<% @mainnet_conf.each do |key, value| %>
<%= "#{key}=#{value}" %>
<%= "#{key}=#{value}" %>
<% end %>
<% end %>
@ -21,7 +21,7 @@
# Options only for testnet
[test]
<% @testnet_conf.each do |key, value| %>
<%= "#{key}=#{value}" %>
<%= "#{key}=#{value}" %>
<% end %>
<% end %>
@ -29,6 +29,6 @@
# Options only for regtest
[regtest]
<% @regtest_conf.each do |key, value| %>
<%= "#{key}=#{value}" %>
<%= "#{key}=#{value}" %>
<% end %>
<% end %>