Title: bitcoind systemd service unit file Post by: darkv0rt3x on April 17, 2021, 11:30:31 PM Hello,
I need some help because I don't fully understand all options being used in the unit service file of bitcoin core daemon taken from here: https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service I have bitcoin core daemon running on a RockPro64 board. I have compiled but I have not installed the daemon (I didn't run the `make install`command). The directory structure is like this: Code: ~/.bitcoind All resides in this directory but the ./blocks folder which is in an external USB drive. This directory is pointed to by a symlink inside ~/.bitcoind like this: Code: lrwxrwxrwx 1 darkv0rt3x darkv0rt3x 24 Apr 4 00:58 .bitcoin/blocks -> /media/WdElements/blocks I think some of the lines inside the unit file needs to be adapted to this folder structure, right? So, this is my current unit file: Code: # It is not recommended to modify this file in-place, because it will Thanks for helping dark Title: Re: bitcoind systemd service unit file Post by: darkv0rt3x on April 21, 2021, 08:29:10 PM Finally I think I have my unit file running. Here it is, in case someone has similar issues.
This is only needed because I didn't install bitcoin core in my system. Rather I ran only: Code: ./configure && make So, some of the options needed to be changed. I also omitted some options because either they didn't work or I didn't know if I should/could have them in my particular case (bitcoin core not instlled with sudo make install). Another particular situation of mine is that I'm running bitcoin as my own user. I didn't create a user specific for running bitcoind as it is running on a dedicated SBC. Code: [Unit] For instance, the option Type doesn't work for me if I use the value forking. Therefore, I used simple. Title: Re: bitcoind systemd service unit file Post by: DireWolfM14 on April 21, 2021, 09:32:47 PM Here's a link to the standard bitcoind.system file included with the source code:
https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service If you want to use it as-is you'll have to create a system user named "bitcoin." Also note the directories and their permissions: Code: # Directory creation and permissions To install bitcoin core to the specified directory use this code: Code: sudo install -m 0755 -o root -g root -t /usr/bin bitcoin-0.21.0/bin/* You'll have to create two directories (/etc/bitcoin and /var/lib/bitcoind) and set the ownership/group to bitcoin:bitcoin and permissions to -rwx--x--- (chmod 710.) Bitcoin core will create the runtime directory as needed. You can now copy your bitcoin.conf file to /etc/bitcoin and set ownership/permission the same as the directory. You should be able to use systemctl to enable and start bitcoind now, but of course it'll start downloading the blockchain from the start. If you change your simlink and use the same directory on the USB drive, you'll need to start bitcoind manually the first time with -reindex. I find this is the most reliable way to run bitcoind with systemd. Title: Re: bitcoind systemd service unit file Post by: darkv0rt3x on April 21, 2021, 09:42:19 PM Here's a link to the standard bitcoind.system file included with the source code: https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service If you want to use it as-is you'll have to create a system user named "bitcoin." Also note the directories and their permissions: Code: # Directory creation and permissions To install bitcoin core to the specified directory use this code: Code: sudo install -m 0755 -o root -g root -t /usr/bin bitcoin-0.21.0/bin/* You'll have to create two directories (/etc/bitcoind and /var/lib/bitcoind) and set the ownership/group to bitcoin:bitcoin and permissions to -rwx--x--- (chmod 710.) Bitcoin core will create the runtime directory as needed. You can now copy your bitcoin.conf file to /etc/bitcoind and set ownership/permission the same as the directory. You should be able to use systemctl to enable and start bitcoind now, but of course it'll start downloading the blockchain from the start. If you change your simlink and use the same directory on the USB drive, you'll need to start bitcoind manually the first time with -reindex. I find this is the most reliable way to run bitcoind with systemd. I don't want any of that. I explicitly mentioned what my situation was. It is what is is and I had to adapt! I don't have bitcoin core installed, I don't have a bitcoin user in my system, I don't know what is that sudo install -m .... command is and I don't need it because, as I also mentioned, I didn't install bitcoin core. I didn't create and nobody needs to create those directories. If you run bitcoind right after you install it, you don't need those. So, why one would need, to use a unit file? I think it is running bitcoind quite reliably, but I'll see how it goes in the next days. But I needed help before I got this working. Now, it's a bit late. :p Thanks to someone in IRC channel, I got it working the way I wanted! Title: Re: bitcoind systemd service unit file Post by: NotATether on April 22, 2021, 10:32:39 AM All those lines where you noted whether it needs to be changed are system folders for bitcoind's configuration, logging, and the folder where it puts its PID file (so you don't run duplicate bitcoind's by accident) so they need to be changed to other folders because the "bitcoin" user, and everybody but root for the matter, does not have permissions to access your home folder. There isn't even a bitcoin user automatically created.
Rather than mucking with the permissions with your home folder, which ends up with bad results as I've tried, you should just change the bitcoin user/group to whatever your own user and group are. Then you need to change some of the entries to remove the system wide folders: Code: ExecStartPre=/bin/chgrp bitcoin /etc/bitcoin < ------ You don't need this The Hardening entries are security measures to reduce damage someone with a crazy-looking ZMQ message (think blocks and transactions from other peers) can do to your node. I know this isn't relevant to your problem, but in an ideal case if you have different bitcoin core builds, each would be in a different folder directly under your home folder, each with the stuff that would've normally been under ~/.bitcoin be in their own folder, so for instance a bitcoin.conf file under ./etc, a bitcoind.pid file under ./run, your wallets, blocks and chainstate and stuff under ./var instead of it using the system wide paths. Basically such a topology would look like his: home / notatether / bitcoin-0.21 / etc / bitcoin.conf bin / ... lib / ... run / bitcoind.pid var / <-- Symlink this to your external disk using this kind of folder structure wallets/ chainstate/ blocks/ debug.log ... bitcoin-0.20 / ... This allows you to have multiple systemd unit files to launch each of these different bitcoind folders. |