I have 4 scripts in crontab that start on server boot. After 12 hours or so, some throw an exception and stop running. At that point, I want my server to just start the script again, so each script is always running.

I can run:

ps ax | grep python

And I see which one it usually is that stops running.

  • Do you have something against a third party software ? If not, i was thinking about Monit, that can monitor processes and restart them if they are down – krisFR Aug 2 '14 at 14:20
  • Which Linux distribution? This is much easier on, e.g. Fedora and CentOS 7 than on Ubuntu or Debian. – Michael Hampton Aug 2 '14 at 14:47
  • CentOS 6 64Bits – User Aug 2 '14 at 14:57
  • Maybe you can give supervisord (supervisord.org) a chance. This little tool will restart your app, script, whatever after a crash. – deagh Aug 2 '14 at 16:26

For me it looks that you are trying to solve a wrong problem here.

If your script acts as a daemon and needs to be running all the time, then it shouldn't crash periodically and expect to be restarted. Of course, unexpected crashes can happen, and yes, there are tools to monitor and restart services when they fail. However, if some service is crashing for you once or twice a day, then you better look what's wrong with it, instead of simply restarting it and pretending that it's fine.

If your script runs as a batch job and for some reason can't complete it's task, then again, it shouldn't just throw an exception, exit and wait to be restarted.

Find a reason why your script crashes and fix it. Use monitoring software to restart it, if unexpected failure happens, but not as a fix to a periodical crash.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.