Hi
I've tried to use this script and it works fine for starting the daemon on system boot, but doesn't help to restart it if process fails, although it should, as it has "respawn" stanza. I've tried numerous ways to do that and sorted a few minor issues on the way, but this is still not working for me. Any ideas how to make it restart automatically with upstart?
regards
Alex
So I finally got things working on an Ubuntu 14.04 server. Here's what the final, working
/etc/init/bitcoind.conf looks like:
description "bitcoind"
start on filesystem
stop on runlevel [!2345]
oom score -500
expect fork
respawn
respawn limit 10 60 # 10 times in 60 seconds
script
user=bitcoind
home=/home/$user
cmd=$home/bin/bitcoind
pidfile=$home/bitcoind.pid
# Don't change anything below here unless you know what you're doing
[[ -e $pidfile && ! -d "/proc/$(cat $pidfile)" ]] && rm $pidfile
[[ -e $pidfile && "$(cat /proc/$(cat $pidfile)/cmdline)" != $cmd* ]] && rm $pidfile
exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile -m --startas $cmd
end script
Once you've added/updated your
/etc/init/bitcoin.conf file, be sure to run the following:
initctl reload-configuration
Basically this was just a lot of guess and check to make this finally work. Here's the important bit:
expect fork
Essentially, this is telling upstart how many times the target process will be forked while starting. If you tell it wrong, it'll hang while starting. Read
here for the specifics on this.
You should be able to manually start bitcoind as a service, like this:
service bitcoind start
Or stop it, like this:
service bitcoind stop
If you restart your server, the bitcoind service should be started automatically. And, if the bitcoind process is killed or crashes, it will be automatically respawned. You can test that part out on your server by first finding the PID of the bitcoind process:
ps cax | grep bitcoind
Then, kill the process manually:
kill -9 PID_OF_BITCOIND
Then, try to get the PID of the bitcoind process again:
ps cax | grep bitcoind
It should still be running and with a new PID.