severity 316321 serious
tags 316321 patch
thanks

hi,

revisiting this issue, and after having spoken with folks
on -devel and -policy, the consensus is that this is in
fact a policy violation, so i am changing the severity
appropriately.

but, because doing so merely to do so wouldn't be so
constructive, i've also patched the init script to
behave appropriately.  i've attempted to keep the
patch as clean as possible... and have taken
code that would otherwise be duplicated and
placed them in common functions (apache_get_pid and 
apache_kill).  

here's some sample output of the new behavior:

mini-me[~]17:34:55$ sudo /etc/init.d/apache2 start
Starting apache 2.0 web server....
mini-me[~]17:35:00$ sudo /etc/init.d/apache2 reload
Reloading apache 2.0 configuration....
mini-me[~]17:35:05$ sudo /etc/init.d/apache2 stop  
Stopping apache 2.0 web server....
mini-me[~]17:35:12$ sudo /etc/init.d/apache2 reload
Reloading apache 2.0 configuration... no pidfile, not sending signal.  failed!


thanks,
        sean

-- 
--- /etc/init.d/apache2.old     2006-01-26 16:53:24.000000000 +0100
+++ /etc/init.d/apache2 2006-01-26 17:24:54.000000000 +0100
@@ -27,9 +27,8 @@
 APACHE2="$ENV /usr/sbin/apache2"
 APACHE2CTL="$ENV /usr/sbin/apache2ctl"
 
-apache_stop() {
-       PID=""
-       PIDFILE=""
+# find and echo the PID if it exists in the PIDFILE
+apache_get_pid(){
        AP_CONF=/etc/apache2/apache2.conf
 
        # apache2 allows more than PidFile entry in the config but only the
@@ -39,45 +38,26 @@
        for i in $AP_CONF `awk '$1 ~ /^\s*[Ii]nclude$/ && $2 ~ /^\// {print 
$2}' $AP_CONF`; do
                PIDFILE=`grep -i ^PidFile $i | tail -n 1 | awk '{print $2}'`
                if [ -e "$PIDFILE" ]; then
-                       PID=`cat $PIDFILE`
+                       cat $PIDFILE
                fi
        done
-       
-       if `$APACHE2 -t > /dev/null 2>&1`; then
-               # if the config is ok than we just stop normaly
-
-               if [ -n "$PID" ]
-               then
-                       $APACHE2CTL stop
-
-                       CNT=0
-                       while [ 1 ]
-                       do
-                               CNT=$(expr $CNT + 1)
-               
-                               [ ! -d /proc/$PID ] && break
+}
 
-                               if [ $CNT -gt 60 ]
-                               then
-                                       if [ "$VERBOSE" != "no" ]; then
-                                               echo " ... failed!"
-                                               echo "Apache2 failed to honor 
the stop command, please investigate the situation by hand."
-                                       fi
-                                       return 1
-                               fi
+# send a signal (optionally $1) to the apache server if possible
+apache_kill(){
+               PID=`apache_get_pid`
+               if [ "$1" ]; then
+                       SIGNAL="-$1"
+               fi
 
-                               sleep 1
-                       done
-               else
+               # if there's no pid, then stop now
+               if [ ! "$PID" ]; then
                        if [ "$VERBOSE" != "no" ]; then
-                               echo -n " ... no pidfile found! not running?"
+                               echo -n " no pidfile, not sending signal."
                        fi
+                       return 1
                fi
 
-       else
-               # if we are here something is broken and we need to try
-               # to exit as nice and clean as possible
-
                # if pidof is null for some reasons the script exits 
automagically
                # classified as good/unknown feature
                PIDS=`pidof apache2` || true
@@ -97,7 +77,7 @@
                if [ $REALPID = 1 ]; then
                        # in this case everything is nice and dandy
                        # and we kill apache2
-                       kill $PID
+                       kill $SIGNAL $PID
                else
                        # this is the worst situation... just kill all of them
                        #for i in $PIDS; do
@@ -105,17 +85,74 @@
                        #done
                        # Except, we can't do that, because it's very, very bad
                        if [ "$VERBOSE" != "no" ]; then
-                                echo " ... failed!"
+                               echo " ... failed!"
                                echo "You may still have some apache2 processes 
running.  There are"
                                echo "processes named 'apache2' which do not 
match your pid file,"
                                echo "and in the name of safety, we've left 
them alone.  Please review"
                                echo "the situation by hand."
-                        fi
-                        return 1
+                       fi
+                       return 1
+               fi
+}
+
+apache_stop() {
+       PID=""
+       PIDFILE=""
+       AP_CONF=/etc/apache2/apache2.conf
+
+       PID=`apache_get_pid`
+       
+       if `$APACHE2 -t > /dev/null 2>&1`; then
+               # if the config is ok than we just stop normaly
+
+               if [ -n "$PID" ]
+               then
+                       $APACHE2CTL stop
+
+                       CNT=0
+                       while [ 1 ]
+                       do
+                               CNT=$(expr $CNT + 1)
+               
+                               [ ! -d /proc/$PID ] && break
+
+                               if [ $CNT -gt 60 ]
+                               then
+                                       if [ "$VERBOSE" != "no" ]; then
+                                               echo " ... failed!"
+                                               echo "Apache2 failed to honor 
the stop command, please investigate the situation by hand."
+                                       fi
+                                       return 1
+                               fi
+
+                               sleep 1
+                       done
                fi
+
+       else
+               # if we are here something is broken and we need to try
+               # to exit as nice and clean as possible
+               apache_kill
        fi
 }
 
+# this function will reload the apache2 server if running, otherwise nothing
+apache_reload() {
+       PID=`apache_get_pid`
+
+       $APACHE2 $EXTRA -t >/dev/null 2>&1
+       if [ ! $? = 0 ]; then
+               # echo so the error message starts on a new line
+               echo
+               $APACHE2 $EXTRA -t
+               return 1
+       else
+               apache_kill HUP
+               return $?
+       fi
+}
+
+
 # Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
 case $1 in
        start)
@@ -139,7 +176,7 @@
        ;;
        reload)
                log_begin_msg "Reloading apache 2.0 configuration..."
-               if $APACHE2CTL graceful $2 ; then
+               if apache_reload; then
                         log_end_msg 0
                 else
                         log_end_msg 1

Attachment: signature.asc
Description: Digital signature

Reply via email to