Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd please sign up again. Thanks!

How to restart a script after crash ? (Sickbeard)

Discussion in 'Command Line' started by alexagna, Mar 5, 2013.

  1. alexagna

    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 !
     
  2. KenJackson

    KenJackson Guest

    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.
     
  3. 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}
     
    #3 AliReza Taleghani, Jul 14, 2013
    Last edited: Nov 29, 2014

Share This Page