Run cron job only if it isn't already running

后端 未结 16 935
执笔经年
执笔经年 2020-11-29 14:53

I\'m trying to set up a cron job as a sort of watchdog for a daemon that I\'ve created. If the daemon errors out and fails, I want the cron job to periodically restart it...

16条回答
  •  旧巷少年郎
    2020-11-29 15:18

    Consider using pgrep (if available) rather than ps piped through grep if you're going to go that route. Though, personally, I've got a lot of mileage out of scripts of the form

    while(1){
      call script_that_must_run
      sleep 5
    }
    

    Though this can fail and cron jobs are often the best way for essential stuff. Just another alternative.

提交回复
热议问题