#!/bin/sh
#
# lighttpd     Startup script for the lighttpd server
#
# chkconfig: - 85 15
# description: Lightning fast webserver with light system requirements
#
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
#

WITHOUT_RC_COMPAT=1

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

if [ -f /etc/sysconfig/lighttpd ]; then
	. /etc/sysconfig/lighttpd
fi

if [ -z "$LIGHTTPD_CONF_PATH" ]; then
	LIGHTTPD_CONF_PATH="/etc/lighttpd/lighttpd.conf"
fi

PIDFILE=/var/run/lighttpd.pid
LOCKFILE=/var/lock/lighttpd
RETVAL=0

start() {
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" \
	--expect-user lighttpd --name lighttpd -- lighttpd -f $LIGHTTPD_CONF_PATH
	RETVAL=$?
	return $RETVAL
}

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

reload() {
	msg_reloading $prog
	stop_daemon --pidfile "$PIDFILE" \
		--expect-user lighttpd --name lighttpd -INT -- lighttpd
	RETVAL=$?
	return $RETVAL
}

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

exit $RETVAL
