Archive for November, 2005

A Mac OS X Startup Item for Sympa

Wednesday, November 23rd, 2005

Just so I don’t lose it if I forget and wipe my dev box…

This is a Mac OS X StartupItem for Sympa, which is essentially just the standard init script they distribute, but with the non-OS X stuff pulled out and redone with StartService() etc for the StartupItem format.

Note that you need to add “SYMPA=-YES-” to /etc/hostconfig for this to work, and that this assumes sympa is all installed in /usr/local/sympa as per the coming entry…

#!/bin/sh

. /etc/rc.common

sympadir="/usr/local/sympa/bin"
sympaconf="/usr/local/sympa/etc/sympa.conf"
wwsympaconf="/usr/local/sympa/etc/wwsympa.conf"

sympa_status()
{
    if [ -f /var/run/$1.pid ] ; then
        pid=`head -1 /var/run/$1.pid`
        if [ "$pid" != "" ] ; then
            running=`ps -A | grep "$pid"`
            if [ "$running" != "" ]; then
                ConsoleMessage "Sympa: $1 (pid $pid) is active..."
                return 0
            else
                ConsoleMessage "Sympa: $1 died, pid file remains."
                return 1
            fi
        fi
    fi
    echo "$1 is stopped."
    return 3
}

sympa_module_start() {
    $sympadir/$1.pl || ConsoleMessage "Sympa: failure starting $1"
}

sympa_start() {
    sympa_status $1 > /dev/null
    case "$?" in
        3)
            ConsoleMessage "Sympa: Starting module $1.pl: "
            sympa_module_start $1
            ;;
        1)
            ConsoleMessage "Sympa: Starting $1, overwritting old pid file."
            sympa_module_start $1
            ;;
        0)
            ConsoleMessage "Sympa: $1 seems active. No action will be taken."
            ;;
    esac
}

sympa_stop() {
    if [ -f /var/run/$1.pid ]; then
        ConsoleMessage "Sympa: Stopping module $1.pl: "
        pid=`head -1 /var/run/$1.pid`
        running=`ps -A | grep "$pid"`
        if [ "$running" != "" ]; then
            kill -TERM $pid
        else
            ConsoleMessage "Sympa: $1 died"
        fi
    else
        ConsoleMessage "Sympa: Module $1.pl not running"
    fi
}

StartService ()
{
    if [ "${SYMPA:=-NO-}" = "-YES-" ]; then
        if [ ! -f /var/sympa ]; then
            ConsoleMessage "Sympa: Starting service:"
            sympa_start sympa
            sympa_start archived
            sympa_start bounced
            sympa_start task_manager
            touch /var/sympa
        else
            ConsoleMessage "Sympa seems active. No action will be taken."
        fi
    fi
}

StopService ()
{
    if [ "${SYMPA:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Sympa: Stopping service:"
        sympa_stop bounced
        sympa_stop archived
        sympa_stop sympa
        sympa_stop sympa-distribute
        sympa_stop task_manager
        if [ -f /var/sympa ]; then
            rm -f /var/sympa
        fi
    fi
}

RestartService ()
{
	if [ "${SYMPA:=-NO-}" = "-YES-" ]; then
		StopService
		StartService
	fi
}

RunService "$1"

Installing suexec on Mac OS X

Tuesday, November 22nd, 2005

Apple don’t ship suexec for Apache with OS X or OS X Server, but it’s quite simple to install yourself. Here’s how:

1. Check the version of Apache httpd that you have installed.

httpd -v

In 10.4.3, this will show I have version 1.3.33:

Server version: Apache/1.3.33 (Darwin)
Server built:   Mar 20 2005 15:08:27

2. Grab the source for the corresponding version of Apache httpd and compile it with suexec support, then copy the suexec binary to the expected location. You’ll see in this case I’ve added the sympa install path to the docroot setting, as I’m using this for installing Sympa, which will be covered in a forthcoming post. If you need suexec to work in another docroot, like /Library/WebServer/Documents, then substitute that instead. I don’t think the docroot setting is absolutely required for Sympa, as it gets used via a ScriptAlias, so you probably don’t need to stress about this if you’re using suexec for cgi-bin/fast-cgi scripts.

mkdir -p /usr/local/src
cd /usr/local/src
curl -O http://apache.planetmirror.com.au/dist/httpd/apache_1.3.33.tar.gz
cd apache_1.3.33
./configure \
--enable-suexec \
--suexec-caller=www \
--suexec-docroot=/usr/local/sympa \
--suexec-safepath="/usr/local/bin:/usr/bin:/bin"
make
cp src/support/suexec /usr/sbin/
chmod u+s /usr/sbin/suexec

3. Now restart apache with:

apachectl stop
apachectl start

and check that you see a line like this in your Apache httpd error log, by default /var/log/httpd/error_log

[Tue Nov 22 11:41:03 2005] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)

Done! You now have a working suexec.