Ghetto startup services using screen Source

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---
11
12[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs56yJ0cZXBV9kbyAuazQH0QjFMghq1zA6QoOzzpzpLC-9CioGGI75_3BLh5zu6gGteXNaym2mJz8dTvGzE-TwyXl2k21_hiOTo2keDX0RcyjMgzJPgvBXEEn_Jb76-oLcErSMIFxTVWk/s1600/screen_list.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs56yJ0cZXBV9kbyAuazQH0QjFMghq1zA6QoOzzpzpLC-9CioGGI75_3BLh5zu6gGteXNaym2mJz8dTvGzE-TwyXl2k21_hiOTo2keDX0RcyjMgzJPgvBXEEn_Jb76-oLcErSMIFxTVWk/s1600/screen_list.png)
13
14Screen 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!).
15
16For 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.
17
18As these were only going to run on my development workstation, it seemed a bit overkill writing a systemd (or upstart) wrapper around these services.
19
20Turns 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.
21
22Add 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.
23
24**#!/bin/bash**
25
26**su - -c "/bin/screen -dmS /path/to/shell/startupscript.sh"**
27
28**exit 0**
29
30Important: you must have the #!/bin/bash and exit 0 lines in this file, otherwise it won't work.
31
32If 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 **).
33
34The -dm option tells screen to launch a screen session, execute a script and detach (the same as hitting ctrl-ad).
35
36**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.
37
38
39