Reputation: 5039
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
(e.g. 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?
Upvotes: 0
Views: 2150
Reputation: 176
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
Upvotes: 2