Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set up a number of processes that start during boot (servers for games) with the below command as the cron item:

@reboot /usr/bin/screen -fa -d -m -S NAME COMMAND

However if the server crashes for what ever reason screen closes and the server doesn't get a chance to run it's auto restart (as far as I understand; screen sees no processes in the socket and so closes).

Is there a way that I can get around this so screen will sit there even if nothing is running in it? Like opening a shell?

share|improve this question
How is the auto-restart implemented? Part of the server code itself, or an external script? – grawity Jan 8 '11 at 20:55
It's part of the server itself I think, srcds_run opens the server and that is what the cron is starting – Pez Cuckow Jan 8 '11 at 21:16
up vote 0 down vote accepted

The command given is the child of screen, so when it exits, the window is dead.

You can get around this by starting a shell and then pushing input into the window to run the command, but this just changes the problem so that you'll be left with a lingering shell prompt and the server won't auto-restart.

Really, you want to run a keep-alive command, which then runs the server you're interested in. There are many tools out there, but the simplest is to write something in shell yourself (unless you want the full power of the dedicated tools.

while [ ! -f /home/servicename/shutdown-flagfile ]; do
  echo "Starting server [$(date)]"
  server-binary-name "$@"
  sleep 1

Line 2 lets you break out of the loop by creating a special file (with "touch"), the server-binary-name is the program to really run, "$@" is to pass through the options that the wrapper was invoked with, and sleep 1 is so that if the server is dying on start-up, you don't chew all the CPU repeatedly restarting it thousands of times per second, so that it's hard to get in and see what's happening. The echo line just lets you see when the server last had to be restarted.

share|improve this answer

Your Answer


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.