I have a home 24/7 small bitcoin node and time to time i have to restart it manual for several reasons like a suddenly power of etc. I try to create a script to auro restart the programme especially with restart but with no luck. Everything i have try was a failure.
My system is Ubuntu server 14.04 with upstart and i will describe as better as i can what i have done so far until now.
1)First i try to type this in contrab -e
@reboot bitcoind -daemon
and then this
@reboot /usr/bin/bitcoind -daemon
but bitcoind didnt start at all and i have again to start it manual.
2) then i try to type a script in the /etc/rc0.d or to rc.local. The script was that
#!/bin/bash
while true; do
sleep 5
if [ ! "$(pidof bitcoind)" ]; then
bitcoind
fi
done
the script was working alone if i run it, was working after restart but was not able to start bitcoind.
3) then i try this
http://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automaticallydescription "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=mobinmob
home=/home/$user
cmd=/usr/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 --startas $cmd -b -m
end script
i have add it to /etc/init as bitcoind.conf i restart my server but again bitcoind was not running.
The strange is that if i try to manual start it with this command
sudo service bitcoind start
it returns
start: Job is already running: bitcoind
but when i check it with bitcoin-cli getinfo the system say error: couldn't connect to server and i have again to start it manual or i have to stop the service and the again type sudo service bitcoind start.
I dont know but bitcoind it seems that cant start before the login in the system or something like that. I cant find any other explanation