Bitcoin Forum
May 05, 2024, 05:30:31 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Systemd, bitcoind and bitcoin node  (Read 2786 times)
Reynaldo (OP)
Legendary
*
Offline Offline

Activity: 1143
Merit: 1000


View Profile
February 07, 2015, 07:37:38 PM
Last edit: February 13, 2015, 10:33:16 PM by Reynaldo
 #1

I'm running a bitcoin node on my raspberry pi b+, the thing is that the daemon sometimes just die and i need to restart it
is there any way to check for it using systemd?

the process bitcoind starts at boot with this systemd configuration as bitcoind.service

Code:
[Unit]
Description=Bitcoin daemon service
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
User=HEREGOESYOURUSER
ExecStart=/usr/bin/bitcoind

[Install]
WantedBy=multi-user.target


can anyone post their systemd files so i can take a look?

edit: configuration that worked

Code:
[Unit]
Description=Bitcoin daemon service
Wants=network.target

[Service]
Type=forking
User=HEREGOESYOURUSER
ExecStart=/usr/bin/bitcoind --daemon
Restart=on-failure

[Install]
WantedBy=multi-user.target
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
1714930231
Hero Member
*
Offline Offline

Posts: 1714930231

View Profile Personal Message (Offline)

Ignore
1714930231
Reply with quote  #2

1714930231
Report to moderator
Newar
Legendary
*
Offline Offline

Activity: 1358
Merit: 1000


https://gliph.me/hUF


View Profile
February 08, 2015, 05:17:28 AM
 #2


Didn't realise systemd is already available in Raspian?

My quick and dirty hack: A crontab that starts the process every x Minutes. If bitcoind already runs it will do nothing, but a log entry. Another crontab takes care removing that log file every so often.

OTC rating | GPG keyid 1DC91318EE785FDE | Gliph: lightning bicycle tree music | Mycelium, a swift & secure Bitcoin client for Android | LocalBitcoins
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
February 08, 2015, 09:06:48 AM
 #3

Try the following in your "[Service]" section:
Code:
RestartSec=60
Restart=on-failure

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Reynaldo (OP)
Legendary
*
Offline Offline

Activity: 1143
Merit: 1000


View Profile
February 10, 2015, 01:36:15 PM
 #4


Didn't realise systemd is already available in Raspian?

My quick and dirty hack: A crontab that starts the process every x Minutes. If bitcoind already runs it will do nothing, but a log entry. Another crontab takes care removing that log file every so often.

Not using raspbian, using arch linux arm; I added the Restart=on-failure and will try to add the RestartSec=60; I've fixed it i think, ill update this post with the configuration later Smiley, thanks Bitsky

Btw can you give me the command for the crontab? i've never used it.
Newar
Legendary
*
Offline Offline

Activity: 1358
Merit: 1000


https://gliph.me/hUF


View Profile
February 10, 2015, 02:35:36 PM
 #5

[...]
Btw can you give me the command for the crontab? i've never used it.

As the user who you usually use to run bitcoind, do:
Code:
crontab -e

Add the following lines:
Code:
@reboot /path/to/your/bitcoind
*/30 * * * * /path/to/your/bitcoind
@weekly rm -rf /var/mail/root

The first line starts bitcoind at boot time, the second one starts it every 30 minutes again. In my system this causes a message to be sent to root informing that bitcoind is already running (if it is), so I added the third line to it to save a bit of space. Note that I solely run this system as a node, if you use yours for other stuff your /var/mail/root might be useful for other things and you wouldn't want it deleted once a week. Like I said, it's not the prettiest of hacks, but works fine in this case.

OTC rating | GPG keyid 1DC91318EE785FDE | Gliph: lightning bicycle tree music | Mycelium, a swift & secure Bitcoin client for Android | LocalBitcoins
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
February 10, 2015, 06:13:55 PM
 #6

Instead of dealing with excess messages, you could write two wrappers. One which starts bitcoind and puts the pid into a file (unless bitcoind already places a pidfile in /var/run/), and a second one which sends a kill -0 to the pid every 5 min and restart if it's gone. That also has the benefit that you don't delete maybe important mails.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Reynaldo (OP)
Legendary
*
Offline Offline

Activity: 1143
Merit: 1000


View Profile
February 10, 2015, 06:23:33 PM
 #7

Instead of dealing with excess messages, you could write two wrappers. One which starts bitcoind and puts the pid into a file (unless bitcoind already places a pidfile in /var/run/), and a second one which sends a kill -0 to the pid every 5 min and restart if it's gone. That also has the benefit that you don't delete maybe important mails.

Sorry I've not updated, yesterday had a rough evening, will try to do it tonight. Killing using the pid its not recommended because you might kill someone that you do not want to, it will depend on Type=xx on the systemd file or if you do not use systemd it will relie on how you started it at startup. For the pid i think its safe to use "pidof bitcoind" to get the pid. Thanks again Bitsky and Newar
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
February 10, 2015, 10:16:02 PM
 #8

Sorry I've not updated, yesterday had a rough evening, will try to do it tonight. Killing using the pid its not recommended because you might kill someone that you do not want to, it will depend on Type=xx on the systemd file or if you do not use systemd it will relie on how you started it at startup. For the pid i think its safe to use "pidof bitcoind" to get the pid. Thanks again Bitsky and Newar
Using -0 will not kill anything. It just does a check on the process behind the pid. Based on the retval you can then determine what to do.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Reynaldo (OP)
Legendary
*
Offline Offline

Activity: 1143
Merit: 1000


View Profile
February 16, 2015, 09:37:49 PM
 #9

Code:
[Unit]
Description=Bitcoin Daemon
Conflicts=bitcoin-reindex.service
After=network.target

[Service]
User=bitcoin
Group=bitcoin
ExecStart=/usr/bin/bitcoind -daemon=0                       \
                            -conf=/etc/bitcoin/bitcoin.conf \
                            -datadir=/srv/bitcoin           \
                            -pid=/run/bitcoind.pid
ExecReload=/usr/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/bitcoind stop

[Install]
WantedBy=multi-user.target

this is the new systemd file that comes with the new 0.10 release. I suppose that to change my configuration file should be as easy as change -conf=/home/user/.bitcoin/bitcoin.conf
but for datadir how should i list it?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!