#! /bin/sh
#
# Dave Cinegified GLP2

RCDLINKS="0,K50 1,K50 2,S50 3,S50 4,S50 5,S50 6,K50"

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/thttpd

test -f $DAEMON || exit 0

#thttpd  [-p port] [-d dir] [-r|-nor] [-u user] [-c cgipat]
#        [-t throttles] [-h host] [-l logfile]

[ -e /etc/thttpd/thttpd.conf ] && . /etc/thttpd/thttpd.conf

[ "$PORT" != "" ]	&& PORT="-p $PORT"
[ "$DIR" != "" ]	&& DIR="-d $DIR"
[ "$CHROOT" = "YES" ]	&& CHROOT="-r"	|| CHROOT="-nor"
[ "$USR" != "" ]	&& USR="-u $USR"
[ "$CGI" != "" ]	&& CGI="-c $CGI"
[ "$THRTS" != "" ]	&& THRTS="-t $THRTS"
[ "$HOST" != "" ]	&& HOST="-h $HOST"
[ "$LOG" != "" ]	&& LOG="-l $LOG"

OPTIONS="$PORT $DIR $CHROOT $USR $CGI $THRTS $HOST $LOG"

case "$1" in
  start)
    echo "Starting thttpd..."
    start-stop-daemon --start --verbose --exec $DAEMON -- $OPTIONS
    ;;
  stop)
    start-stop-daemon --stop --verbose --exec $DAEMON
    ;;
  restart|force-reload)
    echo "Restarting $DAEMON..."
    start-stop-daemon --stop --verbose --exec $DAEMON
    sleep 1
    start-stop-daemon --start --verbose --exec $DAEMON -- $OPTIONS
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
