How to restart a python program in raspberry automatically?

0

Very good everyone, I have a python program running on raspberry pi 3 that uses request to communicate with a web script and I want to know if in case the raspberry program crashes, there is a way to know if it hangs and if you can rerun the program automatically without the user's supervisor

    
asked by Jo3krJP 20.06.2018 в 23:34
source

1 answer

0

I would have the script you want to monitor write a file as a heartbeat. You have to have another script in cron to see if the heartbeat file exists, if so, then delete the file, if it does not exist, leave it a couple of cycles just in case and if it still does not have heartbeat, then kill the process and you relaunch it

The second script, which monitors must be as simple as possible so that it can not crack.

Look also in the / etc / inittab file, that's where the demons that you want the OS to be waiting for are put in. If they die or kill them, they relaunch themselves.

    
answered by 25.06.2018 в 12:23