I've edited my rc.local
to start my python script when the Pi boots up (like here).
How can it be done to restart the script automatically if it crashes? It would be best if a re-start would be logged somewhere.
I've edited my rc.local
to start my python script when the Pi boots up (like here).
How can it be done to restart the script automatically if it crashes? It would be best if a re-start would be logged somewhere.
Write another simpler, less-prone-to-bugs python program that monitors if the original is running?
in a similar situation a long time back, I had my "main" python program "touch" (update timestamp) of a particular file after every main operation. Then, I had a second program which would keep monitoring the timestamp of the file. If the file wasn't updated in the last 20 minutes, it meant my original program had crashed.
Another instance, I wrapped my 'main' program around a script that went like this
#!/bin/bash
/path/to/my/code
email "Ok something went wrong, starting again in 5 minutes"
at now + 5 minutes -f /path/to/this/shell/script
That way, if the program crashed, it would send me an email and restart the program again.