SOURCES: lighttpd.init - rewritten - reload differs from restart t...

glen glen at pld-linux.org
Tue Jan 10 21:09:55 CET 2006


Author: glen                         Date: Tue Jan 10 20:09:55 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- rewritten
- reload differs from restart that it will do nothing if service is down,
  otherwise they both use the graceful restart via INT signal.
  now you can be very safe that rpm upgrade will not disrupt your service availability ;)
- added flush-logs that will do just log rotation

---- Files affected:
SOURCES:
   lighttpd.init (1.7 -> 1.8) 

---- Diffs:

================================================================
Index: SOURCES/lighttpd.init
diff -u SOURCES/lighttpd.init:1.7 SOURCES/lighttpd.init:1.8
--- SOURCES/lighttpd.init:1.7	Tue Jan 10 19:57:59 2006
+++ SOURCES/lighttpd.init	Tue Jan 10 21:09:49 2006
@@ -37,6 +37,25 @@
 	fail
 }
 
+start() {
+	daemon env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
+	return $RETVAL
+}
+
+stop() {
+	killproc --pidfile /var/run/lighttpd.pid lighttpd
+	rm -f /var/lock/subsys/lighttpd >/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
+}
+
 RETVAL=0
 # See how we were called.
 case "$1" in
@@ -45,9 +64,7 @@
 	if [ ! -f /var/lock/subsys/lighttpd ]; then
 		msg_starting lighttpd
 		configtest || exit 1
-		daemon env SHELL=/bin/sh lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS
-		RETVAL=$?
-		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
+		start
 	else
 		msg_already_running lighttpd
 	fi
@@ -56,8 +73,7 @@
 	# Stop daemons.
 	if [ -f /var/lock/subsys/lighttpd ]; then
 		msg_stopping lighttpd
-		killproc --pidfile /var/run/lighttpd.pid lighttpd
-		rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1
+		stop
 	else
 		msg_not_running lighttpd
 	fi
@@ -66,21 +82,41 @@
 	status lighttpd
 	RETVAL=$?
 	;;
-  restart|graceful)
+  restart)
 	if [ -f /var/lock/subsys/lighttpd ]; then
-		msg_stopping lighttpd
 		configtest || exit 1
-		# 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
-		rm -f /var/lock/subsys/lighttpd >/dev/null 2>&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
+			reload
+		else
+			msg_stopping lighttpd
+			stop
+			msg_starting lighttpd
+			start
+		fi
+		RETVAL=$?
+	else
+		msg_not_running lighttpd
+		msg_starting lighttpd
+		start
 	fi
-	$0 start
 	;;
-  reload|force-reload)
-	# this is not reload. it will just reopen logs
+  reload|graceful|force-reload)
 	if [ -f /var/lock/subsys/lighttpd ]; then
 		msg_reloading lighttpd
+		reload
+		RETVAL=$?
+	else
+		msg_not_running lighttpd
+		RETVAL=7
+	fi
+	;;
+  flush-logs)
+	if [ -f /var/lock/subsys/lighttpd ]; then
+		nls "Rotating %s logs" lighttpd
 		configtest || exit 1
 		killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP
 		RETVAL=$?
@@ -90,7 +126,7 @@
 	fi
 	;;
   *)
-	msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}"
+	msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|flush-logs|status}"
 	exit 3
 	;;
 esac
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/lighttpd.init?r1=1.7&r2=1.8&f=u



More information about the pld-cvs-commit mailing list