Last active
March 20, 2018 22:08
-
-
Save davidlj95/8f8fec01f6ae05035fa8235ddb15891c to your computer and use it in GitHub Desktop.
bitcoind Systemd Unit service (with templates)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Bitcoin's [%i] distributed currency daemon | |
After=network.target | |
[Service] | |
User=bitcoin-%i | |
Group=bitcoin-%i | |
Type=forking | |
PIDFile=/var/blockchain/bitcoin/bitcoind_%i.pid | |
ExecStart=/usr/local/bin/bitcoind -daemon -pid=/var/blockchain/bitcoin/bitcoind_%i.pid \ | |
-conf=/etc/bitcoin/%i.conf -datadir=/var/blockchain/bitcoin | |
# IMPORTANT!: You must include datadir even if it's specified in the configuration | |
RuntimeDirectory=bitcoind | |
Restart=on-failure | |
PrivateTmp=true | |
ProtectSystem=full | |
NoNewPrivileges=true | |
PrivateDevices=true | |
MemoryDenyWriteExecute=true | |
TimeoutStopSec=60s | |
TimeoutStartSec=2s | |
StartLimitInterval=120s | |
StartLimitBurst=5 | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bitcoin Core's systemd unit
Explanation
This systemd unit file improves the official systemd unit file present in the Bitcoin Core GitHub repository by allowing several daemons of bitcoind run in the same machine, with different configurations (ie: two daemons that sync both mainnet and testnet blockchains).
Because it's a template unit file, you can run more than one daemon with the same configuration, just modifying the necessary fields so that both daemons do different things. In order to do that, you must name each daemon when instancing the template file
Source
Based on official bitcoin/bitcoin GitHub repository init file for systemd
Requirements
Before using this systemd unit, you must have the following requirements:
User and group
Create a user and group for each bitcoin daemon (one user and group per mainnet, another by testnet).
Users and group must be prefixed with the prefix
bitcoin-
. The name specified after the prefix will be the name of the configuration you are creating for the unit file (ie:bitcoin-mainnet
)Data folders
Create the data folders where the blockchain of each daemon will be stored. Remember to set the permissions properly so that the folder specified in the unit file can be read by the user and group specified in the same unit file.
Configuration files
We use the
%i
variable so we can specify the configuration file for the daemon dynamically. We store all of them in/etc/bitcoin
.So you can create multiple configuration files there and depending on the instance of the unit file, your daemon will use one or another
Usage
In order to use this systemd service unit, you have to make sure the requirements are fulfilled.
Then, copy the file into a
systemd
units directory, like/etc/systemd/system
Edit the file and make sure all users, groups, folders exist. Finally, reload the daemons from disk so you can control it.
sudo systemctl daemon-reload
To start an instance of the template unit file (ie: named
mainnet
), use the following commandsudo systemctl start bitcoind@mainnet