I have a Python script that I wish to keep running all the time on an Ubuntu 12.04 machine, and I am doing so by adding an init job that runs a short script that checks for a screen session and if not present creates one.



case "$1" in

exit 0





# Make sure we are in the working directory.
cd /usr/local/bin

if ! screen -list | grep -q "${SCREEN_NAME}"; then
    screen -dmS "${SCREEN_NAME}" "${INVOCATION}"

The problem is that the screen is not being created when I run /etc/init.d/my-script start. It runs fine when I execute ./start.sh and when I debugged it, it definitely executes the screen statement inside the if statement, and the exit code from screen is 0.

So why doesn't it create the screen?

  • I switched to using cron to run start.sh every half hour but I get the same problem. – DanielGibbs Dec 9 '13 at 7:04

I'd guess that there's a failure running your my-script.py script, rather than a problem with screen. I see that you're referencing it from the current directory - which may not be the current directory when running from init and/or cron.

Can you try using the full path to the script in the INVOCATION variable?

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.