How to make sure an application keeps running on Linux

前端 未结 16 1372
清歌不尽
清歌不尽 2020-11-28 18:51

I\'m trying to ensure a script remains running on a development server. It collates stats and provides a web service so it\'s supposed to persist, yet a few times a day, it

16条回答
  •  甜味超标
    2020-11-28 19:27

    I have used a simple script with cron to make sure that the program is running. If it is not, then it will start it up. This may not be the perfect solution you are looking for, but it is simple and works rather well.

    #!/bin/bash
    #make-run.sh
    #make sure a process is always running.
    
    export DISPLAY=:0 #needed if you are running a simple gui app.
    
    process=YourProcessName
    makerun="/usr/bin/program"
    
    if ps ax | grep -v grep | grep $process > /dev/null
    then
        exit
    else
        $makerun &
    fi
    
    exit
    

    Then add a cron job every minute, or every 5 minutes.

提交回复
热议问题