Skip to content

Instantly share code, notes, and snippets.

@jeffrade
Last active April 13, 2024 21:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeffrade/0b730d226ff6f6b985f802d3c9191023 to your computer and use it in GitHub Desktop.
Save jeffrade/0b730d226ff6f6b985f802d3c9191023 to your computer and use it in GitHub Desktop.
bitcoind systemd service and start script.
#!/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!"
# 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
@sebapi747
Copy link

sebapi747 commented May 20, 2022

Thanks for sharing this.

To get it working on raspberry pi 4, with non root user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment