Boy, don't you hate it when you want to write something but then it leaves your mind utterly?

Jul 02, 2007

I do.

I've got a laundry list of stuff that I want to say, but every time I sit down to do so, they vanish utterly from my brain and it's really starting to piss me off. I don't know what's wrong with me lately.

Okay. Let's start with something that I picked up a while ago and never got around to writing up - it has to do with some software that Daniel J. Bernstein wrote a couple of years ago, namely, daemontools. Daemontools is a suite of utilities that was designed to keep tabs on network services running on a Unix server, in particular those that nobody had gotten around to debugging, and so have to be restarted periodically. I haven't seen anything this flaky since I set up a beta version of Windows Server 2003, but DJB has pretty strong opinions about software in general, and he's got the coding skills to back it up, so what are you going to do?

Anyway, daemontools includes a trusted (by DJB, because he wrote it) daemon called supervise that starts up an instance of some other daemon, like an IMAP or SMTP server. If the daemon it's in charge of ever dies, it picks up on the abnormal termination and spawns another instance so that there's always a running copy. The down side is that it can be tricky to set up. Until I installed it from Gentoo Portage last week, I'd never gotten it to work because it had always spun out of control, eaten up all of the memory on the box, and then crashed the whole shebang. When you install Qmail or BincIMAP on a Gentoo machine it's assumed that you'll be using daemontools out of the gate, but if you try to install it by hand (say, on an OpenBSD or Slackware Linux machine) you have to assemble the components yourself, and it might not be the method that you want to take for many reasons, for example, low memory.

On top of all of this, it's almost assumed that you'll be running Qmail with UCSPI-TCP to hook it into the network so it can do its thing.. that's actually not terribly difficult to do if you read the documentation before attempting to use it. If you really want to keep using inetd to run the Qmail daemons you can, but as a technology it seems to be falling out of use and aside from everything else it doesn't give you very good control over the behavior of the daemons. One thing that UCSPI-TCP is good for, I'll note in passing, is turning random utilities into network services because it connects the input and output file descriptors to network sockets, but I'll leave that as an exercise to the reader.

At the heart of a supervised network service is a little shell script called run that contains a couple of environment variables that set up some of the minutiae of the service, the locations of executables, and sundry things like that. Finally, there is also the command that actually kicks off the daemon. Observe:

/usr/bin/tcpserver ${TCPSERVER_OPTS} -x ${TCPSERVER_RULESCDB} \
-c ${MAXCONN} -u ${QMAILDUID} -g ${NOFILESGID} \
${TCPSERVER_HOST} ${TCPSERVER_PORT} \
${QMAIL_SMTP_PRE} /var/qmail/bin/qmail-${SERVICE}d ${QMAIL_SMTP_POST} \
2>&1

That's it. A call to tcpserver, some command line options, and the call to the actual Qmail SMTP daemon. If you install other daemons that require daemontools and TCPserver, they'll come with run scripts of their own that you can cut apart and use for your own purposes, such as adding to your /etc/init.d/rc.local script so that it'll be started at boot-time. Once you know where to look and what you're looking at, it's actually pretty simple, but like a lot of things you have to sit down and read the documentation to know what it is that you're looking at.

There.

While that's one thing out of many that I wanted to write about, somehow, it's not very satisfying.

It seems very disconnected. I had to write it over a couple of hours because I've been busy doing other things, which is probably why it feels that way.

I feel scatterbrained, and have for a couple of weeks now: Lots of things going on, and I don't have the energy to concentrate on them for very long. I hate how that feels, and I'm trying to fix it.



Creative Commons License
This work by The Doctor [412/724/301/703] is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.