Screen is one of my favourite Unix/Linux command line tools. In a nutshell it lets you spawn an interactive terminal session, disconnect from it, and connect back to it at a later date (particularly useful over ssh!).
For a while I had been toying with the idea of using screen to daemonise startup processes at boot time - for example, I wanted to start a couple of tomcat instances and a python notebook server.
As these were only going to run on my development workstation, it seemed a bit overkill writing a systemd (or upstart) wrapper around these services.
Turns out that screen makes it trivial to launch these processes at boot time. Note that the following example works on Fedora/RHEL Linux flavours - but should be pretty easy to port to your favourite Linux distribution.
Add the following content to /etc/rc.d/rc.local (modern Fedora distributions do not have this file by default, you will have to create it and make it executable as root.
#!/bin/bash
su - -c "/bin/screen -dmS /path/to/shell/startupscript.sh"
exit 0
Important: you must have the #!/bin/bash and exit 0 lines in this file, otherwise it won't work.
If all goes well, next time you reboot and log in as , you will see the screen session named "" when next you log in and execute screen -list. You can then reattach to the terminal session (using screen -r ).
The -dm option tells screen to launch a screen session, execute a script and detach (the same as hitting ctrl-ad).
Tomcat gotcha - for some reason $TOMCAT_HOME/bin/startup.sh wasn't working for me in screen, instead I had to create another shell script that executes $TOMCAT_HOME/bin/catalina.sh run.
