How can I run bitcoind automatically five minutes after restart?

So far I have crontab set up to reboot my computer every morning at 4AM (it runs into issues when it stays on for more than a couple days). I also have tried to use crontab to restart bitcoind on @reboot, but haven't had any success with that.

I am currently using Ubuntu 18.10, and bitcoind v0.18.0.0. Here is my current crontab:

0 4 * * * /sbin/shutdown -r +5
@reboot /usr/bin/bitcoind -daemon -conf=/home/<username>/.bitcoin/bitcoin.conf
  • 1
    Don't you mean @reboot /path/to/bitcoind -daemon ...? You left out the command name. – Nate Eldredge Nov 3 '19 at 14:07
  • If you want to wait five minutes, you can do @reboot sleep 5m ; /path/to/bitcoind -daemon ... – Nate Eldredge Nov 3 '19 at 14:10
  • Fixed to reflect actual crontab. I think I've diagnosed the problem: looking at debug.log, bitcoind can't start an http server on reboot because when my computer shuts down, it doesn't kill the original bitcoind process. As a result, when I start up, bitcoind doesn't have access to port 8332. As a result, I added the following to the first crontab entry: 0 4 * * * bitcoin-cli stop; /sbin/shutdown -r +5 I added the sleep 5m. Appears to do the job. – Marty Nov 3 '19 at 18:33
  • If you just need it to shut down and start as your computer reboots, why not use the systemd service? – Raghav Sood Nov 3 '19 at 22:22
  • @Marty When the computer shuts down the original bitcoind process does get killed. There's something else causing the issue. You may want to look at the at command and trigger it at startup. unix.stackexchange.com/questions/146615/… – Jose Fonseca Nov 4 '19 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.