integ/extended/lighttpd/lighttpd-1.4.35/lighttpd.init
Dean Troyer 3cd12006bb StarlingX open source release updates
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2018-05-31 07:36:35 -07:00

125 lines
2.5 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"
PORT="80"
start()
{
if lsof -t -i:${PORT} 1> /dev/null 2>&1; then
kill $(lsof -t -i:${PORT}) > /dev/null 2>&1
fi
if [ -e $PIDFILE ]; then
PIDDIR=/proc/$(cat $PIDFILE)
if [ -d ${PIDDIR} ]; 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