[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Some proposed changes to apache.init



[ I will make analagous changes to apache-perl.init and apache-ssl.init
  too; I think it's clearer to only discuss in terms of apache.init ]

 - Convert to use /bin/sh (not *many* bashisms present and they're painless
   to remove)
 - Delete the SUEXEC variable because it wasn't used.
 - Move the inetd check up earlier to avoid confusion with the functions.
   Put a comment by it at the same time since I couldn't remember why we
   were grepping for inet.
 - Check that apache & apachectl are executable, not just present.
 - Pass LANG=C *only* to apachectl, not to apache.
 - Ditto PATH setting.
 - New function common_restart() to make the messages nicer ("I asked it
   to restart.  Why's it reloading the modules?").
 - Don't use --exec to stop the daemon, rely on the --pidfile.  For
   some reason it wasn't working on my ia64 box.

Feedback welcome.  It successfully installed on my machine.

Index: debian/apache.init
===================================================================
RCS file: /var/lib/cvs/debian-apache/debian/apache.init,v
retrieving revision 1.6
diff -u -p -r1.6 apache.init
--- debian/apache.init	3 Oct 2003 07:50:03 -0000	1.6
+++ debian/apache.init	20 Oct 2003 19:22:18 -0000
@@ -1,27 +1,31 @@
-#! /bin/bash
+#!/bin/sh
 #
 # apache	Start the apache HTTP server.
 #
 
 NAME=apache
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
 DAEMON=/usr/sbin/apache
-SUEXEC=/usr/lib/apache/suexec
 PIDFILE=/var/run/$NAME.pid
 CONF=/etc/apache/httpd.conf
 APACHECTL=/usr/sbin/apachectl 
 
 trap "" 1
-export LANG=C
-export PATH
 
-test -f $DAEMON || exit 0
-test -f $APACHECTL || exit 0
-
-# ensure we don't leak environment vars into apachectl
-APACHECTL="env -i LANG=${LANG} PATH=${PATH} $APACHECTL"
+# Check that we're not being started by inetd
+if egrep -q -i "^[[:space:]]*ServerType[[:space:]]+inet" $CONF
+then
+    exit 0
+fi
 
 test_config() {
+    if [ ! -x $APACHECTL ]; then
+	echo "$APACHECTL is not executable, exiting"
+	exit 0
+    fi
+
+    # ensure we don't leak environment vars into apachectl
+    APACHECTL="env -i LANG=C PATH=/bin:/usr/bin:/sbin:/usr/sbin $APACHECTL"
+
     if ! $APACHECTL configtest 2> /dev/null
     then
         echo -ne "Configuration syntax error detected. Not reloading.\n\n"
@@ -30,19 +34,24 @@ test_config() {
     fi
 }
 
-if egrep -q -i "^[[:space:]]*ServerType[[:space:]]+inet" $CONF
-then
-    exit 0
-fi
-
 should_start() {
     if [ -e /etc/default/apache ]; then
     	. /etc/default/apache
 	if [ "$start_at_boot" != "true" ]; then
-	   echo "Apache Webserver not started as requested"
-	   exit 0
+	    echo "Apache Webserver not started as requested"
+	    exit 0
 	fi
     fi
+    if [ ! -x $DAEMON ]; then
+	echo "Apache is not executable, not starting"
+	exit 0
+    fi
+}
+
+common_restart() {
+    start-stop-daemon --stop --pidfile $PIDFILE --oknodo --retry 30
+    should_start
+    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON
 }
 
 case "$1" in
@@ -55,31 +64,25 @@ case "$1" in
 
   stop)
     echo -n "Stopping web server: $NAME"
-    start-stop-daemon --stop --pidfile $PIDFILE --oknodo --exec $DAEMON
+    start-stop-daemon --stop --pidfile $PIDFILE --oknodo
     ;;
 
   reload)
     test_config
     echo -n "Reloading $NAME configuration"
-    start-stop-daemon --stop --pidfile $PIDFILE --signal USR1 --exec $DAEMON
+    start-stop-daemon --stop --pidfile $PIDFILE --signal USR1
     ;;
 
   reload-modules)
     test_config
     echo -n "Reloading $NAME modules"
-    start-stop-daemon --stop --pidfile $PIDFILE --oknodo --retry 30
-    should_start
-    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON
+    common_restart
     ;;
 
-  restart)
-    $0 reload-modules
-    exit $?
-    ;;
-
-  force-reload)
-    $0 reload-modules
-    exit $?
+  restart | force-reload)
+    test_config
+    echo -n "Restarting $NAME"
+    common_restart
     ;;
 
   *)
@@ -88,7 +91,7 @@ case "$1" in
     ;;
 esac
 
-if [ $? == 0 ]; then
+if [ $? -eq 0 ]; then
 	echo .
 	exit 0
 else

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk



Reply to: