How to restart a script after crash ? (Sickbeard)

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

  1. alexagna

    alexagna New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 Active Member

    Messages:
    129
    Likes Received:
    28
    Trophy Points:
    28
    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. AliReza Taleghani

    AliReza Taleghani New Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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/${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: May 18, 2014

Share This Page