简体   繁体   中英

Watchdog for specific python process

I am working on Ubuntu 16.04 and I have a python running process in the background

python myFunction.py

From time to time, myFunction process gets killed for unknown reason, however, I want to restart it automatically. I have multiple python process running in the background, and I do not know which one runs myFunctions.py (eg by using the pgrep command).

Is it possible? Can I make a bash or python script to restart the command python myFunction.py whenever the python process running it gets killed?

You can look at Supervisord which is (from its own documentation) :

a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems

Supervisord will keep your script in check. If it crashes, it will restart it again. If your raspberry reboots it will make sure the scripts starts automically after booting.

It works based on a config file formatted like this (more info in the docs ) :

[program:myFunction]
command=/path_to_script/myFunction.py
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/myFunction.log
stderr_logfile=/var/log/myFunction.error.log
directory=/path_to_script

I hope this will help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM