]> git.pld-linux.org Git - packages/lighttpd.git/blobdiff - lighttpd.init
- up to Revision 2692 (1.4.25-rc1); rel 6
[packages/lighttpd.git] / lighttpd.init
index 9409446fb9ad1e44691c4051c2076dc16f0be180..f855d78c61ff6d9c7053fb1075466cf2f97fa79d 100644 (file)
 # Check that networking is up.
 if is_yes "${NETWORKING}"; then
        if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
-               # nls "ERROR: Networking is down. %s can't be run." <service>
-               msg_network_down lighttpd
+               msg_network_down "Lighttpd Web Server"
                exit 1
        fi
 else
        exit 0
 fi
 
-RETVAL=0
-# See how we were called.
-case "$1" in
-  start)
-       # Check if the service is already running?
-       if [ ! -f /var/lock/subsys/lighttpd ]; then
-               msg_starting lighttpd
-               daemon lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+configtest() {
+       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=$?
-               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
+               if [ $RETVAL = 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
        else
-               msg_already_running lighttpd
+               # 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
-       ;;
-  stop)
-       # Stop daemons.
+}
+
+start() {
+       # Check if the service is already running?
        if [ -f /var/lock/subsys/lighttpd ]; then
-               msg_stopping lighttpd
-               kill `cat /var/run/lighttpd.pid`
-               rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
+               msg_already_running "Lighttpd Web Server"
+               return
+       fi
+
+       checkconfig
+       msg_starting "Lighttpd Web Server"; busy
+       env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+       RETVAL=$?
+       if [ $RETVAL -eq 0 ]; then
+               ok
+               touch /var/lock/subsys/lighttpd
        else
-               msg_not_running lighttpd
+               fail
        fi
-       ;;
-  status)
-       status lighttpd
+}
+
+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
+}
+
+restart() {
+       local pid
+
+       # short circuit to safe reload if pid exists and is alive
+       if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then
+               reload
+               return
+       fi
+
+       checkconfig
+       stop
+       start
+}
+
+reload() {
+       if [ ! -f /var/lock/subsys/lighttpd ]; then
+               msg_not_running "Lighttpd Web Server"
+               RETVAL=7
+               return
+       fi
+
+       checkconfig
+       msg_reloading "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
        RETVAL=$?
+}
+
+condrestart() {
+       if [ ! -f /var/lock/subsys/lighttpd ]; then
+               msg_not_running "Lighttpd Web Server"
+               RETVAL=$1
+               return
+       fi
+
+       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
+       killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
+       RETVAL=$?
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
        ;;
   restart)
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               msg_stopping lighttpd
-               # sending INT signal will make lighttpd close all listening sockets and
-               # wait for client connections to terminate.
-               kill -INT `cat /var/run/lighttpd.pid` 
-               rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
-       fi
-       $0 start
+       restart
+       ;;
+  try-restart)
+       condrestart 0
        ;;
   reload|force-reload|graceful)
-       if [ -f /var/lock/subsys/lighttpd ]; then
-               msg_reloading lighttpd
-               kill -HUP `cat /var/run/lighttpd.pid`
-               RETVAL=$?
-       else
-               msg_not_running lighttpd
-               RETVAL=7
-       fi
+       reload
+       ;;
+  flush-logs)
+       flush-logs
+       ;;
+  checkconfig|configtest)
+       checkconfig 1
+       ;;
+  status)
+       status lighttpd
+       RETVAL=$?
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}"
+       msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|status}"
        exit 3
        ;;
 esac
This page took 0.074355 seconds and 4 git commands to generate.