Robert Eisele
Systems Engineer, Architect and DBA

Debian lighttpd startup script

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 possebility 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 download the script or copy it directly from here:

#! /bin/sh
# Debian startup script for lighttpd webserver
#
# Author: Robert Eisele <robert@xarg.org>
# Source: http://www.xarg.org/dowload/rc.lighttpd.debian
#

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.

You might also be interested in the following

 

Sorry, comments are closed for this article. Contact me if you have an inventive contribution.