How to make sure an application keeps running on Linux

前端 未结 16 1364
清歌不尽
清歌不尽 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:30

    first of all, how do you start this app? Does it fork itself to the background? Is it started with nohup .. & etc? If it's the latter, check why it died in nohup.out, if it's the first, build logging.

    As for your main question: you could cron it, or run another process on the background (not the best choice) and use pidof in a bashscript, easy enough:

    if [ `pidof -s app` -eq 0 ]; then
        nohup app &
    fi
    

提交回复
热议问题