How do I write a bash script to restart a process if it dies?

后端 未结 8 2267
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:47

I have a python script that\'ll be checking a queue and performing an action on each item:

# checkqueue.py
while True:
  check_queue()
  do_something()
         


        
8条回答
  •  猫巷女王i
    2020-11-22 03:27

    You should use monit, a standard unix tool that can monitor different things on the system and react accordingly.

    From the docs: http://mmonit.com/monit/documentation/monit.html#pid_testing

    check process checkqueue.py with pidfile /var/run/checkqueue.pid
           if changed pid then exec "checkqueue_restart.sh"
    

    You can also configure monit to email you when it does do a restart.

提交回复
热议问题