Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

System is Debian Whezy x64. I currently use screen to start programs as user rather than root. It looks like this: In /etc/rc.local, I call

su -c "/home/user/scripts/startup" user

Then, in /home/user/scripts/startup, I call a few python programs like this:

screen -dmS my_program python /home/user/my_program.py 

They all start fine. The problem is that these programs tend to update themselves every week or so. When the program updates, it tries to restart itself. Upon the program's restart, the screen session terminates, and the program does not start again. So, after a few days, I notice the program isn't working and need to start it again by hand.

Is there something I can do to ensure that the program will start itself again after a program restart?

Edit: I've read something about screen's "zombie mode" that allows it to stay active, but I don't know how to invoke it at boot.

Thanks

share|improve this question
1  
Within screen and within a shell script: ‛while : ; do myprogram ; done‛ –  ott-- Jan 24 '13 at 22:51
add comment

1 Answer

up vote 1 down vote accepted

Create a script that runs in infinite loop and watches that program is running.

#!/bin/bash
while true; do ps aux | grep -v grep | grep -q <program> || <start_program>; sleep 5; done

Start the script in screen.

share|improve this answer
    
I used the same idea, but was not as fancy. Just used Ott's While Do Done example. Thanks! –  Oddworld Jan 29 '13 at 16:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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