config-files/lighttpd-config/files/lighttpd.init

129 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
### BEGIN INIT INFO
# Provides: Web Server
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Lighttpd Web Server
# Description: Web service to serve static files and proxy
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/lighttpd
NAME=lighttpd
DESC="Lighttpd Web Server"
OPTS="-f /etc/lighttpd/lighttpd.conf"
PIDFILE="/var/run/$NAME.pid"
start()
{
port=$(cat /etc/lighttpd/lighttpd.conf | awk '{if ($1 == "server.port")
{ print $3; }}')
if [ ! -z "$port" ]; then
pid=$(lsof -t -i:${port} 2> /dev/null)
if [ ! -z "$pid" ]; then
kill ${pid} > /dev/null 2>&1
fi
fi
if [ -e $PIDFILE ]; then
pid=$(pidof $NAME 2> /dev/null)
if [ -n "$pid" ]; then
echo "$DESC already running."
return
else
echo "Removing stale PID file $PIDFILE"
rm -f $PIDFILE
fi
fi
echo -n "Checking scratch filesystem..."
let -i COUNT=0
while [ ! -e /scratch ]
do
if [ $COUNT -ge 15 ]
then
echo "failed to find /scratch."
exit -1
fi
let COUNT=COUNT+1
sleep 1
done
echo -n "Mounting scratch filesystem to chroot tmp..."
umount /www/tmp >& /dev/null
rm -r /scratch/lighttpd >& /dev/null
mkdir -p /scratch/lighttpd
mount --bind /scratch/lighttpd /www/tmp/
chown www /www/tmp/
echo -n "Starting $DESC..."
start-stop-daemon --start --pidfile ${PIDFILE} -x "$DAEMON" -- $OPTS
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "done."
else
echo "failed."
fi
}
stop()
{
if [ ! -e $PIDFILE ]; then return; fi
echo -n "Stopping $DESC..."
start-stop-daemon --stop --quiet --pidfile ${PIDFILE} -x "$DAEMON"
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "done."
else
echo "failed."
fi
rm -f $PIDFILE
echo -n "Unmounting scratch filesystem from chroot tmp..."
umount /www/tmp
}
status()
{
pid=`cat $PIDFILE 2>/dev/null`
if [ -n "$pid" ]; then
if ps -p $pid &>/dev/null ; then
echo "$DESC is running"
RETVAL=0
return
else
RETVAL=1
fi
fi
echo "$DESC is not running"
RETVAL=3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|force-reload|restart|reload|status}"
RETVAL=1
;;
esac
exit $RETVAL