Attached is our attempt for fixing this for ubuntu, I think this or
something like it should fix for Debian too.

Bryce
diff -Nru apache2-2.4.46/debian/apache2ctl apache2-2.4.46/debian/apache2ctl
--- apache2-2.4.46/debian/apache2ctl    2020-08-05 11:40:13.000000000 -0700
+++ apache2-2.4.46/debian/apache2ctl    2020-10-05 16:06:32.000000000 -0700
@@ -143,6 +143,18 @@
     fi
 }
 
+need_systemd () {
+    # Detect if systemd is in use and should be used for managing
+    # the Apache2 httpd service.  Returns 0 if so, 1 otherwise.
+    if [ -z "${APACHE_STARTED_BY_SYSTEMD}" ]; then
+       case "$(readlink -f /proc/1/exe)" in
+           *systemd*)
+               return 0
+               ;;
+       esac
+    fi
+    return 1
+}
 
 [ ! -d ${APACHE_RUN_DIR:-/var/run/apache2} ] && mkdir -p 
${APACHE_RUN_DIR:-/var/run/apache2}
 [ ! -d ${APACHE_LOCK_DIR:-/var/lock/apache2} ] && mkdir_chown 
${APACHE_RUN_USER:-www-data} ${APACHE_LOCK_DIR:-/var/lock/apache2}
@@ -153,38 +165,38 @@
     # (this is bad if there are several apache2 instances running)
     rm -f ${APACHE_RUN_DIR:-/var/run/apache2}/*ssl_scache*
 
-    need_systemd=false
-    if [ -z "$APACHE_STARTED_BY_SYSTEMD" ] ; then
-        case "$(readlink -f /proc/1/exe)" in
-        *systemd*)
-            need_systemd=true
-            ;;
-        *)
-            ;;
-        esac
-    fi
-    if $need_systemd ; then
+    if need_systemd; then
         # If running on systemd we should not start httpd without systemd
         # or systemd will get confused about the status of httpd.
-        echo "Invoking 'systemctl start $APACHE_SYSTEMD_SERVICE'."
-        echo "Use 'systemctl status $APACHE_SYSTEMD_SERVICE' for more info."
-        systemctl start "$APACHE_SYSTEMD_SERVICE"
+        echo "Invoking 'systemctl start ${APACHE_SYSTEMD_SERVICE}'."
+        echo "Use 'systemctl status ${APACHE_SYSTEMD_SERVICE}' for more info."
+        systemctl start "${APACHE_SYSTEMD_SERVICE}"
     else
         unset APACHE_STARTED_BY_SYSTEMD
-        $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV"
+        ${HTTPD} ${APACHE_ARGUMENTS} -k "${ARGV}"
     fi
 
     ERROR=$?
     ;;
 stop|graceful-stop)
-    $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV"
+    ${HTTPD} ${APACHE_ARGUMENTS} -k "$ARGV"
     ERROR=$?
     ;;
 restart|graceful)
     if $HTTPD ${APACHE_ARGUMENTS} -t 2> /dev/null ; then
-        $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV"
+        if need_systemd; then
+            # If running on systemd we should not directly restart httpd since
+            # systemd would be confused about httpd's status.
+            # (See LP: #1832182)
+            echo "Invoking 'systemctl restart ${APACHE_SYSTEMD_SERVICE}'."
+            echo "Use 'systemctl status ${APACHE_SYSTEMD_SERVICE}' for more 
info."
+            systemctl restart "${APACHE_SYSTEMD_SERVICE}"
+        else
+            unset APACHE_STARTED_BY_SYSTEMD
+            ${HTTPD} ${APACHE_ARGUMENTS} -k "${ARGV}"
+        fi
     else
-        $HTTPD ${APACHE_ARGUMENTS} -t
+        ${HTTPD} ${APACHE_ARGUMENTS} -t
     fi
     ERROR=$?
     ;;
diff -Nru apache2-2.4.46/debian/changelog apache2-2.4.46/debian/changelog
--- apache2-2.4.46/debian/changelog     2020-08-25 05:13:38.000000000 -0700
+++ apache2-2.4.46/debian/changelog     2020-10-05 16:06:32.000000000 -0700
@@ -1,3 +1,12 @@
+apache2 (2.4.46-1ubuntu2) groovy; urgency=medium
+
+  * d/apache2ctl: Also use systemd for graceful if it is in use.  This
+    extends an earlier fix for the start command to behave similarly for
+    restart / graceful.  Fixes service failures on unattended upgrade.
+    (LP: #1832182)
+
+ -- Bryce Harrington <br...@canonical.com>  Mon, 05 Oct 2020 16:06:32 -0700
+
 apache2 (2.4.46-1ubuntu1) groovy; urgency=medium
 
   * Merge with Debian unstable. Remaining changes:

Reply via email to