Skip to content

Commit 2a87b1b

Browse files
author
ctp-tsteenholdt
committed
Add systemd service for bitcoind
Adding systemd service for bitcoind, to provide for a simpler out-of-the-box experience. Configuration file is /etc/bitcoin/bitcoin.conf. This file is a copy of the sample configuration file. The service user 'bitcoin' is added during install. Its homedir is in '/var/lib/bitcoin'. bitcoind.service is disabled by default to allow the user to configure it, before starting it the first time. On package purge, the 'bitcoin' user as well as its homedir is left intact, to not accidentally remove a wallet or something of equal importance. Instead the user is presented with information on how to perform the cleanup manually, after making sure all important data has been backed up.
1 parent 9085532 commit 2a87b1b

File tree

7 files changed

+133
-3
lines changed

7 files changed

+133
-3
lines changed

contrib/debian/bitcoind.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
usr/local/bin/bitcoind usr/bin
22
usr/local/bin/bitcoin-cli usr/bin
3+
debian/examples/bitcoin.conf etc/bitcoin

contrib/debian/bitcoind.postinst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# setup bitcoin account, homedir etc
4+
5+
set -e
6+
7+
BCUSER="bitcoin"
8+
BCHOME="/var/lib/bitcoin"
9+
10+
if [ "$1" = "configure" ]; then
11+
12+
# Add bitcoin user/group - this will gracefully abort if the user already exists.
13+
# A homedir is never created.
14+
adduser --system --home "${BCHOME}" --no-create-home --group "${BCUSER}"
15+
16+
# If the homedir does not already exist, create it with proper
17+
# ownership and permissions.
18+
if [ ! -d "${BCHOME}" ]; then
19+
mkdir -m 0750 -p "${BCHOME}"
20+
chown "${BCUSER}:${BCUSER}" "${BCHOME}"
21+
fi
22+
23+
fi
24+
25+
#DEBHELPER#
26+
27+
exit 0

contrib/debian/bitcoind.postrm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
# setup bitcoin account, homedir etc
4+
5+
set -e
6+
7+
BCUSER="bitcoin"
8+
BCHOME="/var/lib/bitcoin"
9+
10+
if [ "$1" = "purge" ]; then
11+
12+
# The bitcoin user is left in place for now - This is to ensure that a new user
13+
# will not inherit the users UID/GID and inadvertently gain access to wallets etc
14+
15+
# The homedir is also left intact to ensure that we don't accidentally delete a
16+
# wallet or something equally important
17+
18+
echo
19+
echo "#"
20+
echo "# The bitcoin user (${BCUSER}) and data dir (${BCHOME})"
21+
echo "# were left intact."
22+
echo "#"
23+
echo "# Make sure to check \"${BCHOME}\" for wallets and other"
24+
echo "# important bits."
25+
echo "#"
26+
echo "# After backing up all vital data, cleanup can be completed"
27+
echo "# by running: sudo userdel -r ${BCUSER}"
28+
echo "#"
29+
echo
30+
31+
fi
32+
33+
#DEBHELPER#
34+
35+
exit 0

contrib/debian/bitcoind.service

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# It is not recommended to modify this file in-place, because it will
2+
# be overwritten during package upgrades. If you want to add further
3+
# options or overwrite existing ones then use
4+
# $ systemctl edit bitcoind.service
5+
# See "man systemd.service" for details.
6+
7+
# Note that almost all daemon options could be specified in
8+
# /etc/bitcoin/bitcoin.conf
9+
10+
[Unit]
11+
Description=Bitcoin daemon
12+
After=network.target
13+
14+
[Service]
15+
ExecStart=/usr/bin/bitcoind -daemon -datadir=/var/lib/bitcoin -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid
16+
# Creates /run/bitcoind owned by bitcoin
17+
RuntimeDirectory=bitcoind
18+
User=bitcoin
19+
Type=forking
20+
PIDFile=/run/bitcoind/bitcoind.pid
21+
Restart=on-failure
22+
23+
# Hardening measures
24+
####################
25+
26+
# Provide a private /tmp and /var/tmp.
27+
PrivateTmp=true
28+
29+
# Mount /usr, /boot/ and /etc read-only for the process.
30+
ProtectSystem=full
31+
32+
# Disallow the process and all of its children to gain
33+
# new privileges through execve().
34+
NoNewPrivileges=true
35+
36+
# Use a new /dev namespace only populated with API pseudo devices
37+
# such as /dev/null, /dev/zero and /dev/random.
38+
PrivateDevices=true
39+
40+
# Deny the creation of writable and executable memory mappings.
41+
# Commented out as it's not supported on Debian 8 or Ubuntu 16.04 LTS
42+
#MemoryDenyWriteExecute=true
43+
44+
[Install]
45+
WantedBy=multi-user.target

contrib/debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
bitcoin (0.16.0-trusty2) trusty; urgency=medium
2+
3+
* Add systemd service to bitcoind
4+
5+
-- Thomas M Steenholdt <[email protected]> Wed, 18 Apr 2018 16:40:00 -0200
6+
17
bitcoin (0.16.0-xenial1) xenial; urgency=medium
28

39
* Mark for xenial.

contrib/debian/control

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ Build-Depends: debhelper,
2525
libqrencode-dev,
2626
libprotobuf-dev, protobuf-compiler,
2727
python,
28-
libzmq3-dev
28+
libzmq3-dev,
29+
dh-systemd
2930
Standards-Version: 3.9.2
3031
Homepage: https://bitcoincore.org/
3132
Vcs-Git: git://github.com/bitcoin/bitcoin.git
3233
Vcs-Browser: https://github.com/bitcoin/bitcoin
3334

3435
Package: bitcoind
3536
Architecture: any
36-
Depends: ${shlibs:Depends}, ${misc:Depends}
37+
Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
3738
Description: peer-to-peer network based digital currency - daemon
3839
Bitcoin is a free open source peer-to-peer electronic cash system that
3940
is completely decentralized, without the need for a central server or

contrib/debian/rules

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# $(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),,src/test_bitcoin)
77

88
%:
9-
dh --with bash-completion $@
9+
dh --with bash-completion --with systemd $@
1010

1111
override_dh_auto_clean:
1212
if [ -f Makefile ]; then $(MAKE) distclean; fi
@@ -32,3 +32,18 @@ ifeq ($(QT), qt4)
3232
else
3333
make check
3434
endif
35+
36+
# No SysV or Upstart init scripts included
37+
override_dh_installinit:
38+
dh_installinit \
39+
--noscripts
40+
41+
# Don’t enable service by default
42+
override_dh_systemd_enable:
43+
dh_systemd_enable \
44+
--no-enable
45+
46+
# Restart after upgrade
47+
override_dh_systemd_start:
48+
dh_systemd_start \
49+
--restart-after-upgrade

0 commit comments

Comments
 (0)