#!/bin/sh
#
# tclhttpd: Starts the Tcl Web server
#
# chkconfig: 345 80 15
# description: Tcl Web server
#
# processname: tclhttpd
# config: /etc/tclhttpd/tclhttpd.rc

WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

DAEMON=/usr/sbin/tclhttpd
PIDFILE=/var/run/tclhttpd/tclhttpd.pid
LOCKFILE=/var/lock/subsys/tclhttpd
RETVAL=0

start()
{
    action "Starting ${DAEMON##*/} service: " \
    start-stop-daemon --start --quiet --background --chuid tclhttpd \
		--pidfile "$PIDFILE" --make-pidfile --exec "$DAEMON"
    RETVAL=$?
    [ "$RETVAL" -ne 0 ] || touch "$LOCKFILE"
    return $RETVAL
}

stop()
{
    stop_daemon --name tclhttpd --pidfile "$PIDFILE" \
	--lockfile "$LOCKFILE" --expect-user tclhttpd -- tclhttpd
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}


# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		restart
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
                if [ -e "$LOCKFILE" ]; then
                        reload
                fi
                ;;
	status)
                status --name tclhttpd --pidfile "$PIDFILE" --expect-user tclhttpd -- tclhttpd
                RETVAL=$?
                ;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
