lighttpd.sh 1.95 KB
Newer Older
1 2 3 4
#!/bin/ash
#
# Starts lighttpd daemon.
#
5 6 7
MONIT=/usr/bin/monit

dotconfig=/wr/etc/dot-config
8 9 10 11 12 13 14 15 16 17 18 19 20

start_counter() {
	# increase boot counter
	COUNTER_FILE="/tmp/start_cnt_httpd"
	START_COUNTER=1
	if [ -f "$COUNTER_FILE" ];
	then
	    read -r START_COUNTER < $COUNTER_FILE
	    START_COUNTER=$((START_COUNTER+1))
	fi
	echo "$START_COUNTER" > $COUNTER_FILE
}

21
start() {
22
	echo -n "Starting lighttpd daemon: "
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

	if [ -f $dotconfig ]; then
		. $dotconfig
	else
		echo "$0 unable to source dot-config ($dotconfig)!"
	fi

	if [ "$CONFIG_HTTPD_DISABLE" = "y" ]; then
		echo "web interface disabled in dot-config!"
		if [ "$1" != "force" ]; then
			# Unmonitor web server (lighttpd), ignore all printouts
			# from monit.
			# Run in background since monit may wait for a timeout.
			$MONIT unmonitor lighttpd &>/dev/null &
			exit 0
		fi
		echo -n "Force start of lighttpd: "
	fi

42 43 44
	# note start-stop-daemon does not create pidfile, only check if pid is
	# running
	start-stop-daemon -q -p /var/run/lighttpd.pid -S \
45
		--exec /usr/sbin/lighttpd -- -f /etc/lighttpd/lighttpd.conf
46 47
	ret=$?
	if [ $ret -eq 0 ]; then
48 49
		start_counter
		echo "OK"
50
	elif [ $ret -eq 1 ]; then
51
		echo "Failed (already running?)"
52 53
	else
		echo "Failed"
54
	fi
55 56 57 58 59 60 61 62 63

	# check whether the process was monitored
	$MONIT summary 2>&1 | grep lighttpd | grep "Not monitored" &> /dev/null
	if [ $? -eq 0 ]; then
		echo "web interface was not monitored, enabling monitoring"
		# the process was not monitored, enable monitoring
		# this will generate extra log entries from monit
		$MONIT monitor lighttpd
	fi
64
}
65

66 67
stop() {
	echo -n "Stopping lighttpd daemon: "
68 69 70 71 72 73
	start-stop-daemon -K -q -p /var/run/lighttpd.pid
	if [ $? -eq 0 ]; then
		echo "OK"
	else
		echo "Failed"
	fi
74
}
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
restart() {
	stop
	start
}



case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
94 95
	echo "Usage: $0 {start <force>|stop|restart}"
	echo "    start force -- enable web interface even it is disabled in the dot-config"
96 97 98 99
	exit 1
esac

exit $?