Skip to content

Commit

Permalink
contrib/init: Better systemd integration
Browse files Browse the repository at this point in the history
1. Make logs available to journalctl (systemd's logging system) by not
   specifying -daemonwait, which rightfully has its own set of stdout
   and stderr descriptors (a user invoking with -daemonwait on the
   command line should not see any logs). It makes more sense not to
   daemonize in the systemd context anyway.

2. Make systemd aware of when bitcoind is started and in steady state by
   specifying -startupnotify='systemd-notify --ready' and Type=notify.
   NotifyAccess=all is necessary so that the spawned thread for
   startupnotify is allowed to inform systemd of bitcoind's readiness.

   Note that NotifyAccess=exec won't work because it only allows
   sd_notify readiness signalling from Exec*= declarations in the
   .service file.

3. Also make systemd aware of when bitcoind is stopping by specifying
   -shutdownnotify='systemd-notify --stopping'

Note that we currently don't allow multiple *notify commands, but users
can override it in systemd via:

  # systemctl edit bitcoind

By specifying something like:

  [Service]
  ExecStart=/usr/bin/bitcoind -pid=/run/bitcoind/bitcoind.pid \
                              -conf=/etc/bitcoin/bitcoin.conf \
                              -datadir=/var/lib/bitcoind \
                              -startupnotify='systemd-notify --ready; mystartupcommandhere' \
                              -shutdownnotify='systemd-notify --stopping; myshutdowncommandhere'
  • Loading branch information
dongcarl authored and janus committed Sep 5, 2023
1 parent bec52d0 commit 7fe7f96
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions contrib/init/BGLd.service
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/BGLd -daemon \
-pid=/run/BGLd/BGLd.pid \
ExecStart=/usr/bin/BGLd -pid=/run/BGLd/BGLd.pid \
-conf=/etc/BGL/BGL.conf \
-datadir=/var/lib/BGLd
-datadir=/var/lib/BGLd \
-startupnotify='systemd-notify --ready' \
-shutdownnotify='systemd-notify --stopping'

# Make sure the config directory is readable by the service user
PermissionsStartOnly=true
Expand All @@ -30,8 +31,10 @@ ExecStartPre=/bin/chgrp BGL /etc/BGL
# Process management
####################

Type=forking
Type=notify
NotifyAccess=all
PIDFile=/run/BGLd/BGLd.pid

Restart=on-failure
TimeoutStartSec=infinity
TimeoutStopSec=600
Expand Down

0 comments on commit 7fe7f96

Please sign in to comment.