Skip to content

Commit 76deb30

Browse files
committed
Merge #12255: Update bitcoin.service to conform to init.md
bad1716 init: Modify docs and add release note for 12255 (Carl Dong) b0c7b54 init: Use systemd automatic directory creation (Carl Dong) Pull request description: - `-datadir` option specified. - Ask systemd to create and set the right mode for PID directory, configuration directory, and data directory. - Tell systemd our group so it will set the right owner for aforementioned directories. More information: https://www.freedesktop.org/software/systemd/man/systemd.exec.html Tree-SHA512: a6fad1efa2be433c1fdd863df3ff232736ed709a9e281f51a003b40987d8c213dc64a52bc13a19c85bf85680e78f0be112ecaf32ac274b1ff93bac84a1208845
2 parents cf8aa5c + bad1716 commit 76deb30

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

contrib/init/bitcoind.service

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,45 @@
55
# See "man systemd.service" for details.
66

77
# Note that almost all daemon options could be specified in
8-
# /etc/bitcoin/bitcoin.conf
8+
# /etc/bitcoin/bitcoin.conf, except for those explicitly specified as arguments
9+
# in ExecStart=
910

1011
[Unit]
1112
Description=Bitcoin daemon
1213
After=network.target
1314

1415
[Service]
15-
ExecStart=/usr/bin/bitcoind -daemon -conf=/etc/bitcoin/bitcoin.conf -pid=/run/bitcoind/bitcoind.pid
16-
# Creates /run/bitcoind owned by bitcoin
17-
RuntimeDirectory=bitcoind
18-
User=bitcoin
16+
ExecStart=/usr/bin/bitcoind -daemon \
17+
-pid=/run/bitcoind/bitcoind.pid \
18+
-conf=/etc/bitcoin/bitcoin.conf \
19+
-datadir=/var/lib/bitcoind
20+
21+
# Process management
22+
####################
23+
1924
Type=forking
2025
PIDFile=/run/bitcoind/bitcoind.pid
2126
Restart=on-failure
2227

28+
# Directory creation and permissions
29+
####################################
30+
31+
# Run as bitcoin:bitcoin
32+
User=bitcoin
33+
Group=bitcoin
34+
35+
# /run/bitcoind
36+
RuntimeDirectory=bitcoind
37+
RuntimeDirectoryMode=0710
38+
39+
# /etc/bitcoin
40+
ConfigurationDirectory=bitcoin
41+
ConfigurationDirectoryMode=0710
42+
43+
# /var/lib/bitcoind
44+
StateDirectory=bitcoind
45+
StateDirectoryMode=0710
46+
2347
# Hardening measures
2448
####################
2549

doc/init.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ All three configurations assume several paths that might need to be adjusted.
5656
Binary: `/usr/bin/bitcoind`
5757
Configuration file: `/etc/bitcoin/bitcoin.conf`
5858
Data directory: `/var/lib/bitcoind`
59-
PID file: `/var/run/bitcoind/bitcoind.pid` (OpenRC and Upstart) or `/var/lib/bitcoind/bitcoind.pid` (systemd)
59+
PID file: `/var/run/bitcoind/bitcoind.pid` (OpenRC and Upstart) or `/run/bitcoind/bitcoind.pid` (systemd)
6060
Lock file: `/var/lock/subsys/bitcoind` (CentOS)
6161

6262
The configuration file, PID directory (if applicable) and data directory
@@ -65,6 +65,22 @@ reasons to make the configuration file and data directory only readable by the
6565
bitcoin user and group. Access to bitcoin-cli and other bitcoind rpc clients
6666
can then be controlled by group membership.
6767

68+
NOTE: When using the systemd .service file, the creation of the aforementioned
69+
directories and the setting of their permissions is automatically handled by
70+
systemd. Directories are given a permission of 710, giving the bitcoin group
71+
access to files under it _if_ the files themselves give permission to the
72+
bitcoin group to do so (e.g. when `-sysperms` is specified). This does not allow
73+
for the listing of files under the directory.
74+
75+
NOTE: It is not currently possible to override `datadir` in
76+
`/etc/bitcoin/bitcoin.conf` with the current systemd, OpenRC, and Upstart init
77+
files out-of-the-box. This is because the command line options specified in the
78+
init files take precedence over the configurations in
79+
`/etc/bitcoin/bitcoin.conf`. However, some init systems have their own
80+
configuration mechanisms that would allow for overriding the command line
81+
options specified in the init files (e.g. setting `BITCOIND_DATADIR` for
82+
OpenRC).
83+
6884
### macOS
6985

7086
Binary: `/usr/local/bin/bitcoind`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
systemd init file
2+
=========
3+
4+
The systemd init file (`contrib/init/bitcoind.service`) has been changed to use
5+
`/var/lib/bitcoind` as the data directory instead of `~bitcoin/.bitcoin`. This
6+
change makes Bitcoin Core more consistent with other services, and makes the
7+
systemd init config more consistent with existing Upstart and OpenRC configs.
8+
9+
The configuration, PID, and data directories are now completely managed by
10+
systemd, which will take care of their creation, permissions, etc. See
11+
[`systemd.exec (5)`](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory=)
12+
for more details.
13+
14+
When using the provided init files under `contrib/init`, overriding the
15+
`datadir` option in `/etc/bitcoin/bitcoin.conf` will have no effect. This is
16+
because the command line arguments specified in the init files take precedence
17+
over the options specified in `/etc/bitcoin/bitcoin.conf`.

0 commit comments

Comments
 (0)