Screen Sessions at Boot

by Ross Patterson last modified 2008-02-11T08:22:12+02:00
start screen sessions during init

I've long wanted to configure my server to start my screen session on system boot rather than waiting until I first logged in via SSH.  I use ERC and bitlbee in a screen session for always on logged IRC and IM.  By starting my screen session on boot, my online presence is re-established as soon as the server finishes booting.

My research led me to "Power Sessions with Screen" which details how to do this.  The key is two screen options, "-dm".  This tells screen to start the session detached. 

The article above actually details how to setup a  screen session to capture serial console output which also seems tres cool. I, however, wanted user screen sessions to be started up on system boot.  One might call it the screen equivalent of doing auto-login with X.

First I created a script with executable permissions at /usr/local/sbin/screen-sessions.  It simply launches a detached screen session for each user passed  in as an argument:


for user in "$@"; do
    su $user -c 'screen -dm'

My server runs Debian, so I created /etc/default/screen-sessions where USERS contains a space separated list of users for whom to start screen sessions:

USERS="foo bar"

Then I created /etc/init.d/screen-sessions based on /etc/init.d/skeleton.  I removed the stop runlevels which are unnecessary:

# Default-Stop:

I added the /usr/local/bin and /usr/local/sbin paths so that the above script is accessible:


I gave a description, the name, and corrected the /usr/local path for the script:

DESC="Startup screen sessions at boot"

I moved DAEMON_ARGS below the part of the init script that sources the default file to make use of USERS:

# Read configuration variable file if it is present                                                                                                                                                                 
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

 Finally, I installed the init symlinks:

update-rc.d screen-sessions defaults

There you have it, now my session starts on boot as do those of any other users I configure.  Next I'd like to setup X with VNC on my server so I can run Skype and then I can do Skype IM through bitlbee as well.  Online omnipresence is neigh!  :)