AOLserver+Daemontools Mini-HOWTO


Introduction

Daemontools is a collection of programs written and maintained by Dan Bernstein. Togeather the programs can be used to start, supervise and control other programs. Daemontools can be used as a robust replacement for inetd.

AOLserver is a multi-threaded, high-performance webserver. Like any piece of software it occasionally gets out of wack and needs to be restarted. Sometimes it just needs to be stopped so a bigger problem can be fixed. AOLserver is usually used on larger websites where multiple developers need to restart or otherwise control the server.

The following document will detail how to install and configure the daemontools to allow members of a given unix/linux group to control an AOLserver.

Obtaining the software

The newest release of daemontools is available from: http://cr.yp.to/daemontools/install.html As of this writing, the latest version was daemontools-0.70.tar.gz.

Installing the Daemontools Package

Unpack the daemontools package:

  gunzip daemontools-0.70.tar.gz
  tar -xf daemontools-0.70.tar
  cd daemontools-0.70

The default installation directory is /usr/local. You can change this by editing the first line of the conf-home file at this time.

Compile the programs:

  $ make

And, as root install the daemontools programs:

  # make setup check

Run a test to check if everything is working so far:

  $ ./rts > rts.out
  $ cmp rts.out rts.exp

Which should not produce any output if things are working. According to DJB, some SVR4 varients fail the 'already locked' tests. You can ignore this failure.

svscan looks for programs to start by examining the /service directory. You need to create this directory if it doesn't already exist.

  # mkdir /service
  # chmod 755 /service

Starting svscan at boot time

Daemontools includes the supervise program, which is directly responsible for watching over your AOLserver. Another program called svscan is responsible for starting supervise. This is convenient, because you only have to arrange for svscan to start at boot time. Adding more than one AOLserver does not require you to modify your startup scripts. Here is how you can install svscan to startup at boot time. Place the following at the end of your /etc/rc.d/rc.local file.

   env - PATH=/usr/local/bin:/usr/sbin:/usr/bin:/bin csh -cf 'svscan /service &'

This file is usually one of the last files to be sourced during startup, so networking and other required services, like your databases, will have already started up. You should reboot to verify that svscan is running. If you changed the default installation directory, you will need to modify the above command.

Creating the run startup script

The next step is to decide where to place your startup script for AOLserver. If you are using the ArsDigita Community System, a likely choice might be /web/servername/. AOLserver is usually installed in /usr/local/aolserver, so a good location for the run script would be in /usr/local/aolserver/servers/servername/.

The run script will contain at least the following lines:

#!/bin/sh 

exec /usr/local/aolserver/bin/nsd -ic /usr/local/aolserver/servername.ini -u username -g group

Where you substitute the correct path to your nsd and configuration file. The above line is for the older .ini format file. The newer tcl format would look more like this:

#!/bin/sh 

exec /usr/local/aolserver/bin/nsd -it /usr/local/aolserver/servername.tcl -u username -g group

Once setup change the permission to 700, with owner and group set to root:

-rwx------   1 root     root          435 Oct  1 20:00 run 

Shutdown your AOLserver process, and you will be ready to try out your script.

Telling svscan about AOLserver

With the startup script ready, you need to tell svscan about your AOLserver run script. You do this by creating a symbolic link from the directory where your run script lives, to the /service directory you created. For a run script in /usr/local/aolserver/servers/server1 use:

 $ ln -s /usr/local/aolserver/servers/server1/ /service

AOLserver should start, if everything went alright.

Controlling AOLserver with svc

Another daemontools program, svc, is used to control AOLserver once it is started. Here is a summary of the relevent commands:

  • svc -d If the service is running, send it a TERM signal, do not restart.

  • svc -u If the service is not running, start it. If is stops, restart it.

  • svc -t Send the service a TERM signal. This allows AOLserver to make an orderly exit. It may take several minutes for a busy server to exit. Once the server stops, it is immediately restarted.

  • svc -k Sends the server a KILL signal. This is like KILL -9. AOLserver exits immediately. If svc -t fails to fully kill AOLserver, use this option.

  • svc -o The server is started. If it exits, it is not restarted. This might be useful for debugging a startup script.

Allowing others to restart AOLserver

If you look again at the directory where run resides, you will see a new directory called supervise . This is the control directory. Normally the permissions do not allow anyone other than the owner of the run script to control the server. However, svc will allow a group to also control the server. The following script, saved as /usr/sbin/svgroup changes the permissions to allow group control :

#! /bin/sh
if test $# -lt 2 ; then
    echo svgroup groupname directories ... >&2
    echo for example: >&2
    echo svgroup wheel /service/\* >&2
    exit 2
fi
g="$1" ; shift
for i in $* ; do
    chgrp $g $i/supervise/control
    chmod g+w $i/supervise/control
    chgrp $g $i/supervise/ok
    chmod g+w $i/supervise/ok
    # just in case
    chgrp $g $i/supervise/status
    chmod g+r $i/supervise/status
    chgrp $g $i/supervise
    chmod g+x $i/supervise
done 

For a group web, and a directory /service/server1, you would run:

 $ /usr/sbin/svgroup web /service/server1

Startup file for Oracle

Oracle has a few special requirements. Here is a startup file for AOLserver using the Oracle driver provided by ArsDigita.

#!/bin/sh

export ORACLE_HOME="/ora8/m01/app/oracle/product/8.1.6"
export ORACLE_BASE="/ora8/m01/app/oracle"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib:/usr/lib:/lib:/usr/X11R6/lib
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/ctx/lib:$PATH
export ORACLE_SID='ora8'
export ORACLE_TERM='vt100'
export ORAENV_ASK=NO
export NLS_DATE_FORMAT="YYYY-MM-DD"

exec /home/aol31/bin/nsd -ic /home/aol31/multi.ini -u nsadmin -g web 

You should adjust any values that may be different for your installation.

Acknowledgements

Dan Bernstein's Daemontools Package provides a very stable and secure method of monitoring and controlling AOLserver. Most of this HOWTO is derived from his literature, or from newsgroups he has setup to discuss his software.