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.
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.
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
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 likescreen -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 futurescreen -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.