raw code

Debian lighttpd startup script

Robert Eisele

There is at the meanwhile a lighttpd debian package available, which includes a rc-script for a handy use. Who want to install the server from source have to take the Suse or RedHat rc-script as skeleton to write a own Debian startup script. I've done this and want to share the little script with you. There is a little difference to the other startup scripts. The debian one offers the possibility to "rotate" the access-log. Rotate is maybe the wrong word, let's say "free", because it only moves the old log to a different place and reopens the logfile by sending SIGHUP to the server.

You can easily copy the directly from here and save it as rc.lighttpd.debian:

#! /bin/sh
# Debian startup script for lighttpd webserver
#
# Author: Robert Eisele ( https://raw.org/ )
# Source: https://raw.org/article/debian-lighttpd-startup-script/
#

LIGHTTPD_BIN=/usr/local/sbin/lighttpd
test -x $LIGHTTPD_BIN || exit 5

LIGHTTPD_CONFIG=/etc/lighttpd/lighttpd.conf
test -r $LIGHTTPD_CONFIG || exit 6

LIGHTTPD_PIDFILE=/var/run/lighttpd.pid
LIGHTTPD_LOGFILE=/var/log/lighttpd/access.log

case "$1" in
	start)
		echo "Starting lighttpd"
		$LIGHTTPD_BIN -f $LIGHTTPD_CONFIG
		;;

	stop)
		echo "Shutting down lighttpd"
		kill `cat $LIGHTTPD_PIDFILE`
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	force-reload|reload)
		echo "Reload service lighttpd"
		kill -INT `cat $LIGHTTPD_PIDFILE`
		$0 start
		touch $LIGHTTPD_PIDFILE
		;;

	rotate)
		echo "Rotate logfile of lighttpd"
		mv $LIGHTTPD_LOGFILE /tmp/`date +%D`.log
		kill -HUP `cat $LIGHTTPD_PIDFILE`
		;;

	*)
		echo "Usage: $0 {start|stop|restart|force-reload|reload|rotate}"
		exit 1
		;;
esac

If you have a copy of the script on your hard drive, move it to /etc/init.d and add the execute right with chmod +x /etc/init.d/lighttpd.