]> git.pld-linux.org Git - packages/lighttpd.git/blobdiff - lighttpd.init
- load mod_magnet after other path-altering modules (like mod_secdownload), so
[packages/lighttpd.git] / lighttpd.init
index 0505fee683b13ccd8b4365cd8138845ad113a200..957a0321f899e711f3818c46e0e5a6200c34b083 100644 (file)
@@ -27,114 +27,176 @@ else
 fi
 
 configtest() {
-       out=$(env SHELL=/bin/sh lighttpd -t -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS 2>&1)
-       rc=$?
-       if [ "$rc" = 0 ]; then
-               return
+       env SHELL=/bin/sh lighttpd -t -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+}
+
+# wrapper for configtest
+checkconfig() {
+       local details=${1:-0}
+
+       if [ $details = 1 ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "Lighttpd Web Server"; busy
+               local out
+               out=`configtest 2>&1`
+               RETVAL=$?
+               if [ $RETVAL = 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
+       else
+               # run config test and abort with nice message if failed
+               # (for actions checking status before action).
+               configtest >/dev/null 2>&1
+               RETVAL=$?
+               if [ $RETVAL != 0 ]; then
+                       show "Checking %s configuration" "Lighttpd Web Server"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $RETVAL
+               fi
        fi
-       echo >&2 ""
-       echo >&2 "$out"
-       fail
 }
 
 start() {
-       env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+       # Check if the service is already running?
+       if [ -f /var/lock/subsys/lighttpd ]; then
+               msg_already_running "Lighttpd Web Server"
+               return
+       fi
+
+       checkconfig
+       msg_starting "Lighttpd Web Server"; busy
+       if is_yes "${LIGHT_ANGEL}"; then
+               daemon --fork --pidfile /var/run/lighttpd-angel.pid --makepid \
+                       env SHELL=/bin/sh lighttpd-angel -D -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS 1>&2
+
+       else
+               env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+       fi
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                ok
-               touch /var/lock/subsys/lighttpd
+               touch /var/lock/subsys/lighttpd
        else
                fail
        fi
-       return $RETVAL
 }
 
 stop() {
+       # Stop daemons.
+       if [ ! -f /var/lock/subsys/lighttpd ]; then
+               msg_not_running "Lighttpd Web Server"
+               return
+       fi
+
+       msg_stopping "Lighttpd Web Server"
        killproc --pidfile /var/run/lighttpd.pid lighttpd
        rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
+       rm -f /var/run/lighttpd*.pid >/dev/null 2>&1
 }
 
-reload() {
-       # sending INT signal will make lighttpd close all listening sockets and
-       # wait for client connections to terminate.
-       killproc --pidfile /var/run/lighttpd.pid lighttpd -INT
-       env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+restart() {
+       local pid
+
+       # short circuit to safe reload if pid exists and is alive
+       if is_yes "${LIGHT_ANGEL}"; then
+               if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd-angel lighttpd-angel.pid) && checkpid $pid; then
+                       reload
+                       return
+               fi
+       else
+               if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then
+                       reload
+                       return
+               fi
+       fi
+
+       checkconfig
+       stop
+       start
 }
 
-RETVAL=0
-# See how we were called.
-case "$1" in
-  start)
-       # Check if the service is already running?
+reload() {
+       # TODO: check if process is running. Start it in this case.
        if [ ! -f /var/lock/subsys/lighttpd ]; then
-               msg_starting "Lighttpd Web Server"
-               configtest || exit 1
-               start
-       else
-               msg_already_running "Lighttpd Web Server"
+               msg_not_running "Lighttpd Web Server"
+               RETVAL=7
+               return
        fi
-       ;;
-  stop)
-       # Stop daemons.
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               msg_stopping "Lighttpd Web Server"
-               stop
+
+       checkconfig
+       msg_reloading "Lighttpd Web Server"
+
+       if is_yes "${LIGHT_ANGEL}"; then
+               # sending HUP signal to angel will make lighttpd close all listening
+               # sockets and wait for client connections to terminate. After that new
+               # child will be started
+               killproc lighttpd-angel -HUP
        else
-               msg_not_running "Lighttpd Web Server"
+               # sending INT signal will make lighttpd close all listening sockets and
+               # wait for client connections to terminate.
+               killproc --pidfile /var/run/lighttpd.pid lighttpd -INT
+               env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
        fi
-       ;;
-  status)
-       status lighttpd
        RETVAL=$?
-       ;;
-  restart)
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               configtest || exit 1
+}
 
-               # short circuit to safe reload if pid exists and is alive
-               pid=$(pidofproc lighttpd lighttpd.pid)
-               if [ "$pid" ] && checkpid $pid; then
-                       msg_reloading "Lighttpd Web Server"
-                       reload
-               else
-                       msg_stopping "Lighttpd Web Server"
-                       stop
-                       msg_starting "Lighttpd Web Server"
-                       start
-               fi
-               RETVAL=$?
-       else
+condrestart() {
+       if [ ! -f /var/lock/subsys/lighttpd ]; then
                msg_not_running "Lighttpd Web Server"
-               msg_starting "Lighttpd Web Server"
-               start
+               RETVAL=$1
+               return
        fi
-       ;;
-  reload|graceful|force-reload)
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               msg_reloading "Lighttpd Web Server"
-               configtest || exit 1
-               reload
-               RETVAL=$?
-       else
+
+       checkconfig
+       stop
+       start
+}
+
+flush-logs() {
+       if [ ! -f /var/lock/subsys/lighttpd ]; then
                msg_not_running "Lighttpd Web Server"
                RETVAL=7
+               return
        fi
+
+       show "Rotating %s logs" lighttpd
+       # send HUP to main lighttpd (not angel) process to rotate logs:
+       killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
+       RETVAL=$?
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
        ;;
-  configtest)
-               show "Checking lighttpd config syntax"
-               configtest
-               RETVAL=$?
-               [ $RETVAL = 0 ] && ok || fail
+  stop)
+       stop
+       ;;
+  restart)
+       restart
+       ;;
+  try-restart)
+       condrestart 0
+       ;;
+  reload|force-reload|graceful)
+       reload
        ;;
   flush-logs)
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               nls "Rotating %s logs" lighttpd
-               killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
-               RETVAL=$?
-       else
-               msg_not_running "Lighttpd Web Server"
-               RETVAL=7
+       flush-logs
+       ;;
+  checkconfig|configtest)
+       checkconfig 1
+       ;;
+  status)
+       if is_yes "${LIGHT_ANGEL}"; then
+               status lighttpd-angel || RETVAL=$?
        fi
+       status lighttpd || RETVAL=$?
        ;;
   *)
        msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|status}"
This page took 0.057923 seconds and 4 git commands to generate.