News

Back to Horms' Home Page

screenshell

[Chiz]

I recently wanted a way to set up a machine as a serial console server. That is to connect two of its serial ports to serial ports on two other machines using a null-modem. The idea being that these other machines would put their console on their serial port which would be accessable remotely. Good for debugging, good for handling crashes.

Reading Matt Palmer's recent post SheevaPlug-based serial console concentrators, I decided to write up how I achieved this goal.

Rather than users logging into the console server and then executing a command to access the relevant serial port, I wanted access to be I wanted access to the consoles by telneting to a designated port, one port per serial console that is available.

To achieve this I wrote a small script, screenshell and put it in /usr/local/bin. It is pretty simple, it creates a new screen session for the requested TTY if one doesn't already exist, else it connects to the existing session. I couldn't find an argument to screen that would do this in one hit, so the script looks at what screen sessions are running and acts accordingly - some room for improvement here (see update).

In order to accept connections via telnet, I just added the following lines to /etc/inetd.conf:

8000		stream	tcp	nowait	scs.scs	/usr/sbin/tcpd /usr/sbin/in.telnetd -h -L/usr/local/bin/screenshell-ttyS0
8001		stream	tcp	nowait	scs.scs	/usr/sbin/tcpd /usr/sbin/in.telnetd -h -L/usr/local/bin/screenshell-ttyS1

This basically says, listen for connections on port 8000, if you get a connection, invoke /usr/sbin/in.telnetd and use /usr/local/bin/screenshell-ttyS0 to handle their session. Similarly for port 80001. scs.scs denotes that /usr/sbin/in.telnetd should be invoked as user scs, group scs. The scs (Serial Console Server) user and group were created for this sole purpose, though that is really just a matter of taste.

I couldn't work out how to determine which port the user was connecting to from within screenshell when it is invoked in this way, nor could I work out how to pass extra arguments to screenshell. So instead I just symlinked screenshell to screenshell-ttyS0 and screenshell-ttyS1, which allowed the command name to be used to determine which TTY was being used. Again, room for improvement.

For the problem at hand telnet was sufficient so I didn't investigate how well ssh would work with the solution that I cam up with. For the task at hand, the solution above seems to work quite well.

Download: screenshell
Home: ~horms/junk/

Update: 4th May 2009
Kfish pointed out that screen -xRR -S NAME will attach to an existing session or start a new one as necessary. I have slimmed down the script accordingly.

Fri, 01 May 2009 11:10:34 +1000| Permalink