Watchdog script to keep an application running

23,104

Solution 1

Rather than check every few minutes, write a loop that relaunches the program when it terminates abnormally. But don't roll your own, there are plenty of existing programs to do that. See Ensure a process is always running

Solution 2

Consider to let your app to be spawn by init... see init(8) - keep things simple

Share:
23,104

Related videos on Youtube

EnderShadow
Author by

EnderShadow

Updated on September 18, 2022

Comments

  • EnderShadow
    EnderShadow over 1 year

    I currently use an application called MxEasy on my linux servers to display video from a couple of IP cameras. The software is rather buggy and crashes occasionally. I've wrote a script that checks to see if the application is running and if its not... it launches the application.

    I've tried adding this line to my crontab to have it run the script. It's running the script but not launching MxEasy. Any thing I'm over looking?

    0,15,30,45,50 * * * * root  export DISPLAY=:0 && /etc/cron.hourly/MxEasyCheck.sh 
    

    BTW Ubuntu Server 12.04 is the OS

    Here is MxEasyCheck.sh

    MXEASY=$(ps -A | grep -w MxEasy)
    
    if ! [ -n "$MXEASY" ] ; then
        /home/emuser/bin/MxEasy/startMxEasy.sh &
        exit
    fi
    

    Here is my crontab

    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow user  command
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    0  *    * * *   root    /etc/cron.hourly/rsynccheck.sh
    0,15,30,45,50 * * * * root  export DISPLAY=:0 && /etc/cron.hourly/MxEasyCheck.sh 
    #
    
    • text
      text over 11 years
      Error messages (likely sent to root mailbox)? Are you sure MxEasyCheck.sh is set to be executable as root? What does MxEasyCheck.sh look like? What about providing a FULL ip address with the DISPLAY variable? Without any of this type of information, nobody will be able to help you.
    • text
      text over 11 years
      I'm saying to try putting the full IP address in the assignment and trying that. Without seeing the script, about the only comment we might make is that what happens if the service the scripting calls gets called again when active? Other than that, there is nothing we could tell you. You have not indicated that you have searched the various error logs out there.
    • text
      text over 11 years
      Where does this entry come from? If it is in the root crontab, (ie. using crontab -e), then it has a syntax error by including root in the line.
    • EnderShadow
      EnderShadow over 11 years
      Root is included in all the other entries.. Also I've checked the syslog and script is being executed. "Nov 9 11:00:01 EMserver1 CRON[10533]: (root) CMD ( export DISPLAY=:0 && /etc/cron.hourly/MxEasyCheck.sh )"
    • EnderShadow
      EnderShadow over 11 years
      What other logs should I look into?
    • text
      text over 11 years
      check the root mailbox for the results of this cron run.