0

i got a python script to collect data from a few connected sensors. This script runs in background from starting the PI. The script is working fine but irregular it fells in 'Sl' state. If i restart the PI it works again for a few days, but then it happens again.

Is there a way to monitor the state of the script (kill it and start it again if this happens) or any idea why this happen?

Lukas
  • 490
  • 3
  • 15
  • You can write another program that checks if the script is in currently running or not. If it isn't, just restart it. You can setup a cron job for running this program at appropriate regular intervals. – shad0w_wa1k3r Mar 22 '17 at 08:37

1 Answers1

1

You have a few options (somewhat related):

  1. Run your script as per normal, but have another script (bash works good) that checks for the state of your script. If it's stalled, kill it, and restart. This second script can be called from a regular cron job.

  2. Change your python script into a linux service (see here for an example), and either monitor this service with a second script (similar to 1), OR, do a service restart at regular intervals with a cron job.

roelofs
  • 2,132
  • 20
  • 25