How to restart a script after crash ? (Sickbeard)

A

alexagna

Guest
Hello,
I have a script, Sickbeard, being launched on boot(in /etc/rc.local ) on my NAS which I launch like this:

sudo /home/opt/bin/python2.5 /home/user/pathtosickbeard/SickBeard.py -d



Unfortunately, sickbeard crashes after the files have been downloaded on SAB, and, while I'm not able to fix this, I noticed that if I start the script again, everything goes well and my video files are post processed.
So, Is there any way to automatically relaunch the daemon if it happens to crash?
Thanks in advance !
 


Is there any way to automatically relaunch the daemon if it happens to crash?

There may be, but I don't know of any way.

However, you can use a cron script that does effectively the same thing. Create a new little script for cron to run, maybe /usr/local/sbin/cron_restart_SicBeard.
Code:
#!/bin/sh
if ! ps -auw | grep -q '[/]home/user/pathtosickbeard/SickBeard.py'; then
    /home/opt/bin/python2.5 /home/user/pathtosickbeard/SickBeard.py -d
fi

If you need sudo to run it, you'll need to run this as a cronjob of root since you can't type in a password. And since it's a very lightweight script, you can run it very frequently.

The brackets around one character ('[/]home...') are crucial when grepping the output of ps, otherwise you may be fooled by the grep command itself.
 
I had wrote this before, and it's still in waiting for approve state...
by the way this will be use full for u:
#!/bin/bash
LOCKFILE=/var/run/$(basename ${0}).lock
if [ -e ${LOCKFILE} ] && kill -0 $(cat ${LOCKFILE})
then
exit
fi
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
#

##############################
while :
do
# running mail loop here....
done
##############################
#
rm -f ${LOCKFILE}
 
Last edited:

Members online


Top