[apache2] 01/01: Defer actions by maintscript-helper if apache2 is unconfigured

Stefan Fritsch sf at moszumanska.debian.org
Sun Sep 28 20:20:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

sf pushed a commit to branch master
in repository apache2.

commit 804b53b7d5901e47c2751cdf78908ccd9c594c5b
Author: Stefan Fritsch <sf at sfritsch.de>
Date:   Tue Sep 2 00:50:20 2014 +0200

    Defer actions by maintscript-helper if apache2 is unconfigured
    
    If apache2 is not yet configured, the configuration files for modules
    etc. are not yet installed. Defer all actions by
    apache2-maintscript-helper in this case and execute them in
    apache2.postinst.
---
 debian/apache2-bin.dirs                     |  1 +
 debian/apache2-bin.postrm                   | 34 ++++++++++++++
 debian/apache2.postinst                     | 72 +++++++++++++++++++++++++++++
 debian/changelog                            |  3 ++
 debian/debhelper/apache2-maintscript-helper | 20 +++++++-
 5 files changed, 128 insertions(+), 2 deletions(-)

diff --git a/debian/apache2-bin.dirs b/debian/apache2-bin.dirs
new file mode 100644
index 0000000..642a5c6
--- /dev/null
+++ b/debian/apache2-bin.dirs
@@ -0,0 +1 @@
+var/lib/apache2
diff --git a/debian/apache2-bin.postrm b/debian/apache2-bin.postrm
new file mode 100644
index 0000000..618cf99
--- /dev/null
+++ b/debian/apache2-bin.postrm
@@ -0,0 +1,34 @@
+#!/bin/sh
+# postrm script for apache2-bin
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postrm> `remove'
+#        * <postrm> `purge'
+#        * <old-postrm> `upgrade' <new-version>
+#        * <new-postrm> `failed-upgrade' <old-version>
+#        * <new-postrm> `abort-install'
+#        * <new-postrm> `abort-install' <old-version>
+#        * <new-postrm> `abort-upgrade' <old-version>
+#        * <disappearer's-postrm> `disappear' <overwriter>
+#          <overwriter-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+case "$1" in
+    purge)
+
+	rm -f /var/lib/apache2/deferred_actions
+    ;;
+
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/apache2.postinst b/debian/apache2.postinst
index 6c156d0..782e5c6 100644
--- a/debian/apache2.postinst
+++ b/debian/apache2.postinst
@@ -392,6 +392,77 @@ warn_itk_users()
 	fi
 }
 
+msg ()
+{
+	local PRIORITY="$1"
+	local MSG="$2"
+	echo "$PRIORITY: $MSG"
+	if [ -x /usr/bin/logger ]; then
+		/usr/bin/logger -p daemon.$PRIORITY -t apache2.postinst "$MSG" || true
+	fi
+}
+
+execute_deferred_actions ()
+{
+	if [ ! -e /var/lib/apache2/deferred_actions ]; then
+		return 0
+	fi
+
+	local error=false
+
+	cat /var/lib/apache2/deferred_actions |
+	while read PACKAGE FUNCTION ARG1 ARG2 ARG3
+	do
+		if ! dpkg-query -f '${Status}' -W "$PACKAGE"|grep -q installed ; then
+			# If the package has been removed again, skip the actions
+			continue
+		fi
+		case "$FUNCTION" in
+		apache2_invoke)
+			case "$ARG1" in
+			enmod|dismod|enconf|disconf|ensite|dissite)
+				# We can ignore reload/restart in ARG3 because apache2 has not
+				# been started, yet.
+				msg "info" "Executing deferred 'a2$ARG1 $ARG2' for package $PACKAGE"
+				a2$ARG1 -m -q "$ARG2"
+				;;
+			*)
+				msg "error" "'apache2_invoke $ARG1' in /var/lib/apache2/deferred_actions invalid"
+				error=true
+			esac
+			;;
+		apache2_switch_mpm)
+			local MPM="mpm_$ARG1"
+			local CUR_MPM="$(ls /etc/apache2/mods-enabled/mpm_*.load)"
+			CUR_MPM="${CUR_MPM##*/}"
+			CUR_MPM="${CUR_MPM%.load}"
+			if [ ! -e /etc/apache2/mods-available/$MPM.load ] ; then
+				msg "error" "$MPM not found in 'apache2_switch_mpm $ARG1' for package $PACKAGE"
+				error=true
+			elif [ ! -e /etc/apache2/mods-enabled/$MPM.load ] ; then
+				msg "info" "$MPM: No action required"
+			else
+				msg "info" "Switch to $MPM for package $PACKAGE"
+				if ! a2dismod -m -q "mpm_$CUR_MPM" ||
+				   ! a2enmod -m -q "mpm_$MPM"
+				then
+					msg "error" "Switching to $MPM failed"
+					error=true
+				fi
+			fi
+			;;
+		*)
+			msg "ERROR: function '$FUNCTION' in /var/lib/apache2/deferred_actions invalid"
+			;;
+		esac
+	done
+
+	if $error ; then
+		msg "error" "Some deferred actions failed. You will need to fix the configuration manually."
+	fi
+	rm /var/lib/apache2/deferred_actions
+}
+
 #XXX: Deal with the sites-available/sites-enabled *.conf transition, e.g. rename
 #     all files which look like site configuration?
 
@@ -409,6 +480,7 @@ case "$1" in
 		move_httpd_conf $@
 		migrate_data $@
 		warn_itk_users $@
+		execute_deferred_actions
 
 		# post installation cleanup
 		if [ -e /etc/apache2/.apache2_mpm_selected ] ; then
diff --git a/debian/changelog b/debian/changelog
index c2d288d..fbc1bd6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,8 @@
 apache2 (2.4.10-3) UNRELEASED; urgency=medium
 
+  * If apache2 is not configured yet, defer actions executed via
+    apache2-maintscript-helper. This fixes installation failures if a
+    module package is configured first. Closes: #745834
   * Include mod_authnz_fcgi. Closes: #762908
   * Add some comments about SSLHonorCipherOrder in ssl.conf. Closes: #746359
   * Remove misleading sentence in apache2-bin's description. Closes: #762645
diff --git a/debian/debhelper/apache2-maintscript-helper b/debian/debhelper/apache2-maintscript-helper
index 1c2ea7b..3726365 100644
--- a/debian/debhelper/apache2-maintscript-helper
+++ b/debian/debhelper/apache2-maintscript-helper
@@ -75,6 +75,11 @@ else
 		fi
 	fi
 
+	APACHE2_MAINTSCRIPT_DEFER=
+	if ! dpkg-query -f '${Status}' -W apache2|grep -q installed; then
+		echo "Package apache2 is not configured yet. Will defer actions by package $DPKG_MAINTSCRIPT_PACKAGE."
+		APACHE2_MAINTSCRIPT_DEFER=/var/lib/apache2/deferred_actions
+	fi
 
 	if [ -z "$1" ] ; then
 		echo "You must invoke apache2-maintscript-helper with an unmodified environment when sourcing it" >&2
@@ -129,8 +134,6 @@ fi
 #
 
 
-
-
 #
 # Function apache2_msg
 #	print out a warning to both, the syslog and a local standard output.
@@ -273,6 +276,10 @@ apache2_switch_mpm()
 	local MPM="$1"
 	MPM="${MPM#mpm_}"
 
+	if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+		echo "$APACHE2_MAINTSCRIPT_PACKAGE apache2_switch_mpm $*" >> $APACHE2_MAINTSCRIPT_DEFER
+		return 0
+	fi
 
 	if [ ! -e "/etc/apache2/mods-available/mpm_$MPM.load" ] ; then
 		apache2_msg "err" "apache2_switch_mpm: MPM $MPM not found"
@@ -341,6 +348,11 @@ apache2_invoke()
 	[ -x "/usr/sbin/a2$CMD" ] || return 1
 	[ -x "/usr/sbin/a2query" ] || return 1
 
+	if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+		echo "$APACHE2_MAINTSCRIPT_PACKAGE apache2_invoke $*" >> $APACHE2_MAINTSCRIPT_DEFER
+		return 0
+	fi
+
 	case "${RCD_ACTION:-}" in
 		""|reload|restart)
 			;;
@@ -449,6 +461,10 @@ apache2_reload()
 	if ! apache2_needs_action ; then
 		return 0
 	fi
+	if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+		return 0
+	fi
+
 	local action
 	case "${1:-}" in
 	""|reload)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-apache/apache2.git



More information about the Pkg-apache-commits mailing list