1---2title: 'Ghetto startup services using screen'3date: '2013-11-19'4published_at: '2013-11-19T14:17:00.000+11:00'5tags: ['daemon', 'fedora', 'ipython notebook', 'linux', 'rhel', 'screen', 'tomcat', 'unix']6author: 'Gavin Jackson'7excerpt: '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 u...'8updated_at: '2013-11-19T14:17:43.909+11:00'9legacy_url: 'http://www.gavinj.net/2013/11/ghetto-startup-services-using-screen.html'10---1112[](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs56yJ0cZXBV9kbyAuazQH0QjFMghq1zA6QoOzzpzpLC-9CioGGI75_3BLh5zu6gGteXNaym2mJz8dTvGzE-TwyXl2k21_hiOTo2keDX0RcyjMgzJPgvBXEEn_Jb76-oLcErSMIFxTVWk/s1600/screen_list.png)1314Screen 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!).1516For 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.1718As these were only going to run on my development workstation, it seemed a bit overkill writing a systemd (or upstart) wrapper around these services.1920Turns 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.2122Add 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.2324**#!/bin/bash**2526**su - -c "/bin/screen -dmS /path/to/shell/startupscript.sh"**2728**exit 0**2930Important: you must have the #!/bin/bash and exit 0 lines in this file, otherwise it won't work.3132If 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 **).3334The -dm option tells screen to launch a screen session, execute a script and detach (the same as hitting ctrl-ad).3536**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.373839