Can't get a script to run on startup in Debian 7

0

I want to get this script to run on startup on my Debian Wheezy server:

/usr/bin/bitcoind

so I go:

$ sudo crontab -e
@reboot /usr/bin/bitcoind 2>&1 >/tmp/bitcoind.out &

Then save and exit the file. crontab notifies me:

crontab: installing new crontab

Then I restart:

$ sudo shutdown -r 0

but when I boot back up, the script is not running:

$ ps aux | grep bitcoind
# *blank*

however I do see this entry in /var/log/syslog:

Dec 15 22:25:02 mypcname /USR/SBIN/CRON[2886]: (root) CMD (/usr/bin/bitcoind 2>&1 >/tmp/bitcoind.out &)

Any ideas why this is not working?

mulllhausen

Posted 2013-12-15T12:08:13.323

Reputation: 460

Any interesting in the /tmp/bitcoind.out file? – Braiam – 2013-12-15T12:44:17.080

nope. its blank. i think the problem would be the same with any executable. i will test this... – mulllhausen – 2013-12-15T12:49:50.030

Answers

0

it turned out the problem was with bitcoind not cron. i had not configured bitcoind to run as root so it was bombing out at boot. i'm not sure why but the die message was not showing up in /tmp/bitcoind.out. anyway when i tried just from the command line running bitcoind as root i got:

$ sudo bitcoind
Error: To use bitcoind, you must set a rpcpassword in the configuration file:
/root/.bitcoin/bitcoin.conf
It is recommended you use the following random password:
rpcuser=bitcoinrpc
rpcpassword=xxxxxxxxxxxxxxxxxxxxxxxxx
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Bitcoin Alert" admin@foo.com

so i fixed it by running bitcoind as my user:

$ sudo crontab -e # note that this is still root's crontab!
@reboot sudo -u myusername /usr/bin/bitcoind 2>&1 >/tmp/bitcoind.cron-out

and now it runs at boot. maybe it would have been better to put this in my own crontab? i'm not sure if this would mean that it only runs when i log in as my user through? i'll test it again later on today and update the answer if this works...

update

yes it does still run even when i don't login if i delete the entry from root's crontab and then add it to my user's crontab:

$ sudo crontab -e # note that this is still root's crontab!
<delete last line/>
<save and exit/>
crontab: installing new crontab
$ crontab -e
@reboot /usr/bin/bitcoind 2>&1 >/tmp/bitcoind.cron-out
crontab: installing new crontab

mulllhausen

Posted 2013-12-15T12:08:13.323

Reputation: 460