#!/bin/sh
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/var/lib/moin/bin/moin.fcg #Where the moin.fcg file is
PIDFILE=/var/run/moin.pid
LOGFILE=/var/log/moin.log

test -x $DAEMON || exit 0

case "$1" in
  start)
    echo -n "Starting MoinMoin FastCGI external server: moin"
    ps ax | grep "python2.4 $DAEMON" | grep -v grep > /dev/null
    if [ $? -ne 0 ];
    then
        echo " - Launch"
        $DAEMON >> $LOGFILE 2>&1  &
        ps ax | grep "python2.4 $DAEMON" | grep -v grep
    else
        echo " - Processes already running:"
        ps ax | grep "python2.4 $DAEMON" | grep -v grep
    fi
    ;;
  stop)
    echo "Stopping MoinMoin FastCGI: moin"
    for I in `ps ax | grep "python2.4 $DAEMON" | grep -v grep | cut -c 1-5`;
    do
        echo "  Stopping process $I";
        kill -15 "$I"
    done
    echo "."
    ;;
  status)
    echo "MoinMin FastCGI processes running:"
    ps ax | grep "python2.4 $DAEMON" | grep -v grep
    ;;
  reload)
    echo "Not implemented."
    ;;
  force-reload|restart)
    sh $0 stop
    sleep 2
    sh $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/moin {start|stop|restart|force-reload|reload|status}"
    exit 1
    ;;
esac

exit 0
