Project

General

Profile

Startup script for Ubuntu


#!/bin/sh

USER=lighttpd
GROUP=lighttpd
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LIGHTY_DAEMON=/usr/sbin/lighttpd
LIGHTY_OPTS="-f /etc/lighttpd/lighttpd.conf" 
LIGHTY_NAME=lighttpd
LIGHTY_PIDFILE=/var/run/$LIGHTY_NAME.pid
SCRIPTNAME=/etc/init.d/$LIGHTY_NAME
SSD="/sbin/start-stop-daemon" 
PHP_FCGI_CHILDREN=10
PHP_FCGI_MAX_REQUESTS=1000
RETVAL=0

FCGI_DAEMON="/usr/bin/spawn-fcgi" 
FCGI_PROGRAM="/usr/bin/php-cgi" 
FCGI_PORT="4050" 
FCGI_SOCKET="/tmp/php-fastcgi.sock" 
FCGI_PIDFILE="/var/run/spawn-fcgi.pid" 

test -x $LIGHTY_DAEMON || exit 0

set -e

export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS

. /lib/lsb/init-functions

case "$1" in
  start)
        log_daemon_msg "Starting $LIGHTY_NAME" 
        if ! $SSD --quiet --start --pidfile $LIGHTY_PIDFILE --exec $LIGHTY_DAEMON -- $LIGHTY_OPTS 2> /dev/null; then
            log_end_msg 1
        else
            log_end_msg 0
        fi
        log_daemon_msg "Starting spawn-fcgi" 
        if ! $FCGI_DAEMON -s $FCGI_SOCKET -f $FCGI_PROGRAM -u $USER -g $GROUP -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE; then
            log_end_msg 1
        else
            log_end_msg 0
        fi
        RETVAL=$?
  ;;
  stop)
        log_daemon_msg "Stopping $LIGHTY_NAME" 
        if $SSD --quiet --stop --oknodo --retry=0/30/KILL/5 --exec $LIGHTY_DAEMON; then
            rm -f $LIGHTY_PIDFILE $FCGI_PIDFILE $FCGI_SOCKET
            log_end_msg 0
        else
            log_end_msg 1
        fi
        log_daemon_msg "Killing all spawn-fcgi processes" 
        if killall --signal 2 php-cgi > /dev/null 2> /dev/null; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        RETVAL=$?
  ;;
reload)
        log_daemon_msg "Reloading $LIGHTY_NAME configuration" 
        if $SSD --stop --signal 2 --oknodo --quiet --pidfile $LIGHTY_PIDFILE --exec $LIGHTY_DAEMON; then
            if $SSD --start --quiet --pidfile $LIGHTY_PIDFILE --exec $LIGHTY_DAEMON -- $LIGHTY_OPTS ; then
                log_end_msg 0
            else
                log_end_msg 1
            fi
        else
            log_end_msg 1
        fi
        RETVAL=$?
  ;;
  restart|force-reload)
        $0 stop
        [ -r  $LIGHTY_PIDFILE ] && while pidof lighttpd |\
                 grep -q `cat $LIGHTY_PIDFILE 2>/dev/null` 2>/dev/null ; do sleep 1; done
        $0 start
  ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        exit 1
  ;;
esac

exit $RETVAL