#!/bin/sh
#
# Starts lighttpd.
#

start() {
	echo -n "Starting lighttpd: "

	# protection against cleared .passwd
        HTTPD_PWD=`/sbin/uci -q get httpd.webserver.password_set`
        if [[ ! -f /barix/local/etc/.passwd ]] && [[ "$HTTPD_PWD" == "true" ]]; then /sbin/uci set httpd.webserver.password_set=; /sbin/uci commit; fi

	# generate configuration file
	/lib/config/gen_config.sh httpd

	# start up lighttpd
	start-stop-daemon -S -q -p /var/run/lighttpd.pid --exec /usr/sbin/lighttpd -- -f /etc/lighttpd/lighttpd.conf
	echo "OK"
}
stop() {
	echo -n "Stopping lighttpd: "
	start-stop-daemon -K -q -p /var/run/lighttpd.pid
	echo "OK"
}
restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	restart
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

