Skip to content

Commit b0c7b54

Browse files
committed
init: Use systemd automatic directory creation
Tell systemd to create, set, and ensure the right mode for the PID, configuration, and data directories. Only the exec bit is set for groups for the aforementioned directories. This is the least privilege perm that allows for the reading/writing/execing of files under the directory _if_ the files themselves give permission to its group to do so (e.g. when -sysperms is specified). Note that this does not allow for the listing of files under the directory.
1 parent fe5a70b commit b0c7b54

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
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

0 commit comments

Comments
 (0)