Last active
April 13, 2024 21:08
-
-
Save jeffrade/0b730d226ff6f6b985f802d3c9191023 to your computer and use it in GitHub Desktop.
bitcoind systemd service and start script.
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
#!/bin/bash | |
# Just a simple wrapper to start bitcoind. | |
# | |
# If using systemd, simply create a file (e.g. /etc/systemd/system/bitcoind.service) | |
# from example file below and add this script in ExecStart. | |
# https://raw.githubusercontent.com-/bitcoin/bitcoin/76deb30550b2492f9c8d9f0302da32025166e0c5/contrib/init/bitcoind.service | |
# | |
# Then run following to always start: | |
# systemctl enable bitcoind | |
# | |
# and the following to start immediately: | |
# systemctl start bitcoind | |
# If you are mounting a secondary disk, find the UUID of your | |
# disk and a line entry in /etc/fstab e.g. | |
# | |
# UUID=foo-bar-1234 /path-to-dir/.bitcoin ext4 defaults 0 0 | |
set -e | |
# Let's wait for 30 seconds in case other processes need to come up first. | |
sleep 30 | |
echo "Starting bitcoind..." | |
bitcoind --daemon --server -pid=/path-to-dir/.bitcoin/bitcoind.pid | |
echo "Done!" |
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
# Install this in /etc/systemd/system/ | |
# See below for more details and options | |
# https://raw.githubusercontent.com-/bitcoin/bitcoin/76deb30550b2492f9c8d9f0302da32025166e0c5/contrib/init/bitcoind.service | |
# Then run following to always start: | |
# systemctl enable bitcoind | |
# | |
# and the following to start immediately: | |
# systemctl start bitcoind | |
[Unit] | |
Description=Bitcoin daemon | |
After=network.target | |
[Service] | |
ExecStart=/path-to-script/bitcoind-start.sh | |
# Process management | |
#################### | |
Type=forking | |
PIDFile=/path-to-dir/.bitcoin/bitcoind.pid | |
Restart=on-failure | |
# Directory creation and permissions | |
#################################### | |
# Run as bitcoin:bitcoin or <youruser> | |
User=youruser | |
Group=youruser | |
# Hardening measures | |
#################### | |
# Provide a private /tmp and /var/tmp. | |
PrivateTmp=true | |
# Use a new /dev namespace only populated with API pseudo devices | |
# such as /dev/null, /dev/zero and /dev/random. | |
PrivateDevices=true | |
# Deny the creation of writable and executable memory mappings. | |
MemoryDenyWriteExecute=true | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this.
To get it working on raspberry pi 4, with non root user
then run
systemctl --user daemon-reload
systemctl --user enable bitcoind.service
systemctl --user start bitcoind.service
as explained in https://unix.stackexchange.com/questions/559753/how-to-make-systemd-services-run-automatically-after-reboot
for service to restart on reboot, user needs to be lingering on the machine: sudo loginctl enable-linger myusername