Navigation Menu

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
@bartenbach
Copy link

Good looking out. Is this really not provided by bitcoin core??

@jeffrade
Copy link
Author

@bartenbach What in particular? This gist is mostly (if not all) a subset from files in the init directory: https://github.com/bitcoin/bitcoin/tree/master/contrib/init

@bartenbach
Copy link

Oh, weird. The tgz for Linux on bitcoin.org doesn't contain those files.

@jeffrade
Copy link
Author

Oh, weird. The tgz for Linux on bitcoin.org doesn't contain those files.

@bartenbach As they shouldn't since the compiled binary doesn't know anything more than the OS architecture is is supposed to run on. See following link for more details https://github.com/bitcoin/bitcoin/blob/master/doc/init.md

I won't be much help, so join IRC or other forums if you have any more questions https://github.com/bitcoin/bitcoin/blob/216f4ca9e7ccb1f0fcb9bab0f9940992a87ae55f/doc/README.md#need-help

@bartenbach
Copy link

Yes, it could be any one of those three 2 kilobyte files. Might as well just not package any of them and let the user source them manually. Makes perfect sense 🙄

@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