0

I have a Python script that uses Twitter's streaming API, but it usually crashes after a day or two. I have not been able to pinpoint the cause, and after more than a month of trying, I've stopped trying to do so. Instead, I occasionally SSH into the Pi, check the list of screen sessions and start the script again if it has crashed.

Obviously, this isn't very effective, as the script sometimes stops running and hours pass until I'm able to check the Pi again, which is why I want to automate all that. I checked out Monit, which seems to be able to do what I want, but I don't know how to do it, and its ~100 man pages don't help.

So: How do I get Monit to check whether my script is running in a screen instance and restart it if it isn't? I had the idea of somehow grepping the output of screen -list and using that, because all my screen sessions have names set, but I'm not proficient enough with all that Terminal stuff to do that.

closed as off-topic by lenik, syb0rg, Impulss, John La Rooy, nc4pk Oct 4 '13 at 22:09

  • This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Let me get this straight, you are too lazy to read 100+ pages of the manual (that has nothing to do with Raspberry Pi, BTW) and would prefer someone else to do this and explain everything to you in just a few words? – lenik Oct 3 '13 at 23:34
  • Lengthy research is sometimes required before asking a question on this site. Show that you have performed such research in your question so that you get better help more quickly. – syb0rg Oct 4 '13 at 0:09
  • 1
    @lenik From what I've seen, there are only two types of Linux users, those that don't know jack and try to get help from those who condescendingly talk down to them. I doubt this is more than 20 seconds of work for someone who knows what they're doing, so why even bother answering if all you're gonna do is point and laugh? I do understand that reading a giant wall of text is helpful if you know what you're looking for, but I don't and I need help from someone who does. – Peter W. Oct 4 '13 at 13:41
  • @PeterW. again, i want to note this has absolutely nothing with Raspberry Pi. other than that, you have a few options: 1) fix the script until it does not crash, 2) don't run the script continuously, start it from the cron, every few minutes/hours, this way nobody cares if it has crashed or not. – lenik Oct 6 '13 at 23:42
3

A good option for managing a service like this is Supervisor.

Install the package with apt-get install supervisor. Then you will need to create a configuration for your script in /etc/supervisor/conf.d/

For details about the configuration read the program section in the supervisor docs. Specifically you can specify autorestart=true and Supervisor will automatically restart the process if it stops.

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