Running IMAPProxy from Daemontools

IMAPProxy is a proxy server for connections between an IMAP client and an IMAP server. IMAPProxy caches the server connections helping to grant a performance boost for non-stateful clients such as Horde IMP and Squirrelmail.

Daemontools is a collection of tools for managing Unix services. It provides a means of monitoring a service, starting and stopping it and logging any debug and/or error messages. Daemontools provides easy service installation and removal, easy first time service startup, reliable restarts, easy, reliable signalling, clean process state and OS portability.

When attempting to compile imapproxy, you may receive the following error:

src/imapcommon.c: In function 'Get_Server_conn':
src/imapcommon.c:380: error: 'MD5_DIGEST_LENGTH' undeclared (first use in this function)

The solution to the problem can be found here .


Setting up the Service Directories

First verify the daemontools "svscan" process is running. Choose a location where you want the physical service directories. I usually use "/var/service", however any directory may be used as long as it is not "/service".

Create the service directories with the following commands.

# mkdir -m 1755 /var/service/imapproxy
# mkdir -m 755 /var/service/imapproxy/log

Download the "run" scripts for imapproxy and its log.

# cd /var/service/imapproxy
# wget -c http://www.antagonism.org/scripts/imapproxy-run
# mv imapproxy-run run
# chmod 755 run
# cd log
# wget -c http://www.antagonism.org/scripts/log-run
# mv log-run run
# chmod 755 run

Warning, before using either of the imapproxy "run" scripts, make sure you understand what the commands do.

The "log" run script rotates the logs every 1MB, keeps the latest 20 logs and writes them to the "main" directory under the "log" directory.

Configuring IMAPProxy

IMAPProxy only requires one directive to allow daemontools to manage it. The foreground_mode option must be set to "yes". This prevents imapproxy from forking into the background a requirement for daemontools management. Below is a section of an example imapproxy.conf listing the directive.

## foreground mode
foreground_mode yes


Activating the Service

(The below section is taken almost verbatim from the following page created by John Simpson. I felt that his description on what happens when you activate a service was the most clear and easy to understand, so why change a thing?)

Once the directories are set up, you need to make them start running. This is done by creating a symbolic link from /service/(whatever) to the physical directory where the service lives. The "svscan" program checks /service every five seconds, and when it sees a new directory (or symbolic link) there, it starts a "supervise" process for that directory. In addition, if the directory has the sticky bit set and a child directory called "log", it starts a "supervise" process for the "log" child directory and sets up a pipe between the two processes (so that the main process's logs end up being sent to the log process).

The "supervise" program works by running the "run" script inside of whatever directory it's watching. If that child process (either the "run" script itself, or whatever process it runs using "exec") stops, it starts it back up by running the "run" script again.

The following command will create the symbolic link needed to start the imapproxy service.

# ln -s /var/service/imapproxy /service/

After running this command, wait ten seconds (to give it time to start) and then run the "svstat" command to see what's running:

# svstat /service/imapproxy /service/imapproxy/log
/service/imapproxy: up (pid 2508) 7 seconds
/service/imapproxy/log: up (pid 2510) 7 seconds

As long as the new services show "up" with a timer of more than one second, the services are running correctly. If the timer on a service is 0 or 1 second, then wait about five seconds and run the same command - it should now be higher than 1 second. If it's still 0 or 1, then the service is having a problem and you need to fix it. This page provides some steps to troubleshoot daemontools service installations.


Downloads

File: imapproxy-run
Size: 79 bytes
Date: 2008-05-02 14:49:56 -0700
MD5: df2b17080d7b5b442578f60ebbc26e2c
SHA-1: ef4fe371bebc3956edc0d3cf57b6a594bcf08a68
RIPEMD-160: b29ff5e860137abe301dca72badc56a992e63915
PGP Signature: imapproxy-run.asc
File: log-run
Size: 47 bytes
Date: 2008-05-02 14:49:56 -0700
MD5: 1cc7ef3d56be3ec766a9b382d19d1604
SHA-1: d04a2286a41bddd77577443253ac67654f0b7425
RIPEMD-160: 4df90694ac5cb454b6e360c69278e244c6cdf924
PGP Signature: log-run.asc