Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a program that runs in the foreground so I run it via a 'screen'. Is there a good start/stop/restart template for 'screen'? I need it to pass the commands to the screen and create it if it doesn't exist.

share|improve this question

2 Answers 2

I think you're slightly confused.

All screen does is allow you to detach it from the current terminal, and reattach at a later date.

You can however, start a process within screen, detached.

screen -d -m your_command_here

share|improve this answer
    
I know, I am mainly looking for a basic template that would easy to modify to use screen. Along with how to create the screen if it doesn't exist. –  Will Oct 12 '10 at 23:50

I'm not sure what you mean by "template for screen" but the -R option means "connect me to an existing screen or start a new one". To be useful you'll want something like screen -d -R -S myscreen. The -d option will detach it if it was already attached somewhere else, and "-S myscreen" will name your screen session so future screen -d -R -S myscreen commands will know which screen you're talking about.

Unfortunately, -d -R -S can't be used with -d -m, so you can't say "start a screen named myscreen in detached mode unless there's already a screen named myscreen". Once it's started, you'll have to use the ctrl-a ctrl-d command to detach it if you don't want it running in the foreground.

Anything after the options will be executed as a command in a new screen only, so you can execute screen -d -R -S myscreen /some/program to:
1) If a screen named myscreen exists, detach it from wherever it is and reattach it here
2) If the screen does not exist, create it and execute /some/program in it.

Note that if you run a command in screen, when that command exits so will screen.

share|improve this answer
    
I need a basic easy to edit start/stop/restart init.d script. –  Will Oct 13 '10 at 5:19

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.