[Pkg-apache-commits] [SCM] Debian packaging for apache2 (Apache HTTPD 2.x) branch, next, updated. 5580b12d06e1969115bde674562252417253ec39

Arno Töll debian at toell.net
Mon Apr 9 16:30:01 UTC 2012


The following commit has been merged in the next branch:
commit 5580b12d06e1969115bde674562252417253ec39
Author: Arno Töll <debian at toell.net>
Date:   Mon Apr 9 17:43:36 2012 +0200

    * Enable stateful configuration handling
    * Add -m flag to a2enmod to enable that mode
    * Update apache2-maintscript-helper to make use of that mode
    * Document the -m flag in manpages
    * Remove /var/lib/apache2 on purge
    * Fix matching issues in apache2-maintscript-helper. Make sure it only matches
      exact patterns.

diff --git a/debian/a2enmod b/debian/a2enmod
index 717527b..89923bb 100755
--- a/debian/a2enmod
+++ b/debian/a2enmod
@@ -3,6 +3,9 @@
 # a2enmod by Stefan Fritsch <sf at debian.org>
 # Licensed under Apache License 2.0
 
+#XXX: Implement a "fire & forget" switch
+#dump state database, probably better suited in a2query though
+
 use strict;
 use Cwd 'realpath';
 use File::Spec;
@@ -12,10 +15,13 @@ use Getopt::Long;
 
 my $quiet;
 my $force;
+my $maintmode;
+
 Getopt::Long::Configure('bundling');
 GetOptions(
     'quiet|q' => \$quiet,
-    'force|f' => \$force
+    'force|f' => \$force,
+    'maintmode|m' => \$maintmode
 ) or exit 2;
 
 my $basename = basename($0);
@@ -34,14 +40,6 @@ my $env_file = $ENV{APACHE_ENVVARS}
 $ENV{LANG}='C';
 read_env_file($env_file);
 
-# TODO: those should be moved to envvars ASAP!
-# TODO: follow $suffix policy to allow more instances
-our %STATE_DIRS = ();
-$STATE_DIRS{'apache2'} = "/var/lib/apache2";
-$STATE_DIRS{'module'} = "$STATE_DIRS{'apache2'}/modules";
-$STATE_DIRS{'site'} = "$STATE_DIRS{'apache2'}/sites";
-$STATE_DIRS{'conf'} = "$STATE_DIRS{'apache2'}/conf";
-
 $act .= 'able';
 my ( $name, $dir, $sffx, $reload );
 if ( $obj eq 'mod' ) {
@@ -66,6 +64,9 @@ $name = ucfirst($obj);
 my $confdir  = $ENV{APACHE_CONFDIR}                  || "/etc/apache2$dir_suffix";
 my $availdir = $ENV{ uc("APACHE_${dir}_AVAILABLE") } || "$confdir/$dir-available";
 my $enabldir = $ENV{ uc("APACHE_${dir}_ENABLED") }   || "$confdir/$dir-enabled";
+my $statedir = $ENV{ uc("APACHE_STATE_DIRECTORY") }  || "/var/lib/apache2";
+
+$statedir .= "/$obj";
 
 my $choicedir = $act eq 'enable' ? $availdir : $enabldir;
 my $linkdir = File::Spec->abs2rel( $availdir, $enabldir );
@@ -139,9 +140,9 @@ sub doit {
 
     if ( !-e $tgt ) {
         if ( -l $link && !-e $link ) {
-		if ( $act eq 'disable' ) {
-			info("removing dangling symlink $link\n");
-			unlink($link);
+                if ( $act eq 'disable' ) {
+                        info("removing dangling symlink $link\n");
+                        unlink($link);
 
                         # force a .conf path. It may exist as dangling link, too
                         $conflink = "$enabldir/$acton.conf";
@@ -150,12 +151,12 @@ sub doit {
                                 info("removing dangling symlink $conflink\n");
                                 unlink($conflink)
                         }
-			return 1;
-		}
-		else {
-			error("$link is a dangling symlink!\n");
-		}
-	}
+                        return 1;
+                }
+                else {
+                        error("$link is a dangling symlink!\n");
+                }
+        }
 
         error("$name $acton does not exist!\n");
         return 0;
@@ -198,32 +199,31 @@ sub doit {
             warn_deps( $acton, @depends ) or return 0;
     }
 
-	if ( $act eq 'enable' ) {
-		my $check = check_link( $tgt, $link );
-		if ( $check eq 'ok' ) {
-			if ($conflink) {
-
-				# handle .conf file
-				my $confcheck = check_link( $conftgt, $conflink );
-				if ( $confcheck eq 'ok' ) {
-					info("$name $acton already enabled\n");
-					return 1;
-				}
-				elsif ( $confcheck eq 'missing' ) {
-				print "Enabling config file $acton.conf.\n";
-				add_link( $conftgt, $conflink ) or return 0;
-		
-				}
-				else {
-					error("Config file $acton.conf not properly enabled: $confcheck\n");
-					return 0;
-				}
-			}
-			else {
-				info("$name $acton already enabled\n");
-				return 1;
-			}
-		}
+        if ( $act eq 'enable' ) {
+                my $check = check_link( $tgt, $link );
+                if ( $check eq 'ok' ) {
+                        if ($conflink) {
+
+                                # handle .conf file
+                                my $confcheck = check_link( $conftgt, $conflink );
+                                if ( $confcheck eq 'ok' ) {
+                                        info("$name $acton already enabled\n");
+                                        return 1;
+                                }
+                                        elsif ( $confcheck eq 'missing' ) {
+                                        print "Enabling config file $acton.conf.\n";
+                                        add_link( $conftgt, $conflink ) or return 0;
+                                }
+                                else {
+                                        error("Config file $acton.conf not properly enabled: $confcheck\n");
+                                        return 0;
+                                }
+                        }
+                        else {
+                                info("$name $acton already enabled\n");
+                                return 1;
+                        }
+                }
         elsif ( $check eq 'missing' ) {
             if ($conflink) {
 
@@ -242,8 +242,8 @@ sub doit {
             if ( $acton eq 'ssl' ) {
                 info("See /usr/share/doc/apache2/README.Debian.gz on " .
                      "how to configure SSL and create self-signed certificates.\n");
-	    }
-		return add_link( $tgt, $link ) && switch_marker($obj, $act, $acton);
+            }
+                return add_link( $tgt, $link ) && switch_marker($obj, $act, $acton);
         }
         else {
             error("$name $acton not properly enabled: $check\n");
@@ -252,12 +252,12 @@ sub doit {
     }
     else {
         if ( -e $link || -l $link ) {
-            	remove_link($link);
+                remove_link($link);
             if ( $conflink && -e $conflink ) {
                 remove_link($conflink);
             } 
-		switch_marker($obj, $act, $acton);
-		print "$name $acton disabled.\n";
+                switch_marker($obj, $act, $acton);
+                print "$name $acton disabled.\n";
         }
         elsif ( $conflink && -e $conflink ) {
             print "Disabling stale config file $acton.conf.\n";
@@ -455,31 +455,32 @@ sub read_env_file {
 }
 
 sub switch_marker {
-	die('usage: switch_marker([module|site|conf], [enable|disable], $name)') if @_ != 3;
-	my $which = shift;
-	my $what = shift;
-	my $name = shift;
-	# TODO: get rid of the magic string(s)
-	my $state_marker_dir = "$STATE_DIRS{$which}/$what" . "d" . "_by_maint";
-	my $state_marker = "$state_marker_dir/$name";
-	if ( !-d $state_marker_dir ) {
-		File::Path::mkpath("$state_marker_dir") || error("Failed to create marker directory: '$state_marker_dir'\n");
-	}
-	# XXX: swap find with perl alternative
-	my @markers = qx{find "$STATE_DIRS{$which}" -type f -a -name "$name"};
-	chomp(@markers);
-	foreach (@markers) {
-		if(unlink $_) {
-			info("Old marker '$_' removed\n");
-		}
-		else {
-			error("Failed to remove old marker '$_'!\n") && return 0;
+        die('usage: switch_marker([module|site|conf], [enable|disable], $name)') if @_ != 3;
+        my $which = shift;
+        my $what = shift;
+        my $name = shift;
+
+	my $mode = "admin";
+	$mode = "maint" if $maintmode;
+
+        #print("switch_marker $which $what $name\n");
+        # TODO: get rid of the magic string(s)
+        my $state_marker_dir = "$statedir/$what" . "d" . "_by_$mode";
+        my $state_marker = "$state_marker_dir/$name";
+        if ( !-d $state_marker_dir ) {
+                File::Path::mkpath("$state_marker_dir") || error("Failed to create marker directory: '$state_marker_dir'\n");
+        }
+        # XXX: swap find with perl alternative
+        my @markers = qx{find "$statedir" -type f -a -name "$name"};
+        chomp(@markers);
+        foreach (@markers) {
+                unless(unlink $_) {
+                       error("Failed to remove old marker '$_'!\n") && return 0;
 		}
-	}
-	info("Creating '$state_marker'\n");
-	qx{touch "$state_marker"};
-	if ($? != 0) {
-		error("Failed to create marker '$state_marker'!\n") && return 0;
-	}
-	return 1;
+        }
+        qx{touch "$state_marker"};
+        if ($? != 0) {
+                error("Failed to create marker '$state_marker'!\n") && return 0;
+        }
+        return 1;
 }
diff --git a/debian/a2query.in b/debian/a2query.in
index ed331bd..08d7af8 100755
--- a/debian/a2query.in
+++ b/debian/a2query.in
@@ -53,13 +53,12 @@ our $API = "__API__";
 our $MODULE_DIR = "__MODULE_DIR__";
 our $SERVER_VERSION = "__SERVER_VERSION__";
 our $MODULE_DIR = "/usr/lib/apache2/modules/";
-our %STATE_DIRS = ();
-$STATE_DIRS{'apache2'} = "/var/lib/apache2";
-$STATE_DIRS{'module'} = "$STATE_DIRS{'apache2'}/modules";
-$STATE_DIRS{'site'} = "$STATE_DIRS{'apache2'}/sites";
-$STATE_DIRS{'conf'} = "$STATE_DIRS{'apache2'}/conf";
+our $STATE_DIR = "/var/lib/apache2";
+our @STATES = ("maint", "admin");
+
 our $MPM = "invalid";
 our $CONFIG_DIR = "/etc/apache2";
+
 # time to introduce more _exit_ values
 our $E_OK = '0';
 our $E_FOUND = '0';
@@ -67,6 +66,7 @@ our $E_ONBYMAINT = '1';
 our $E_NOTFOUND = '32';
 our $E_OFFBYMAINT = '33';
 our @RETVALS = ( $E_OK, $E_FOUND, $E_ONBYMAINT, $E_NOTFOUND, $E_OFFBYMAINT );
+
 our @MODULES = ();
 our @CONFS = ();
 our @SITES =();
@@ -237,11 +237,13 @@ sub switch_history
 	my $which = shift;
 	my $what = shift;
 	my $name = shift;
-	# TODO: get rid of the magic string
-	my $state_token = "$STATE_DIRS{$which}/$what" . "_by_maint/" . $name;
-	if (-e $state_token)
+	foreach my $state (@STATES)
 	{
-		return 1;
+		my $state_token = "$STATE_DIR/$which/$what" . "_by_$state/" . $name;
+		if (-e $state_token)
+		{
+			return $state;
+		}
 	}
 	return 0;
 }
@@ -254,7 +256,7 @@ my $help = 1;
 getopt('m:s:c:havMd', \%opts);
 
 
-push @HELP, ["m [MODULE]", "checks whether the module MODULE is enabled, lists all modules if no argument was given"];
+push @HELP, ["m [MODULE]", "checks whether the module MODULE is enabled, lists all enabled modules if no argument was given"];
 if (exists $opts{'m'})
 {
 	--$help;
@@ -265,18 +267,20 @@ if (exists $opts{'m'})
 	}
 	foreach my $module (grep { $_ =~ m/$opts{'m'}/ } @MODULES)
 	{
-		print("$module\n");
+		my $state = switch_history("module", "enabled", $module);
+		if (!$state)
+		{
+			$state = "unknown";
+		}
+		print("$module (by $state)\n");
 		$matches++;
 	}
 	if (!$matches)
 	{
 		my $reason = "No module matches $opts{'m'}";
 		my $retval = $E_NOTFOUND;
-		if (switch_history("module", "disabled", $opts{'m'}))
-		{
-			$reason .= " (disabled by maint)";
-			$retval = $E_OFFBYMAINT;
-		}
+		#Figure out something for disabled modules
+		#$retval = $E_OFFBYMAINT;
 		fail($reason, $retval);
 	}
 }
@@ -293,18 +297,21 @@ if (exists $opts{'s'})
 	}
 	foreach my $site (grep { $_ =~ m/$opts{'s'}/ } @SITES)
 	{
-		print("$site\n");
+		$site =~ s/\.conf$//;
+		my $state = switch_history("site", "enabled", $site);
+		if (!$state)
+		{
+			$state = "unknown";
+		}
+		print("$site (by $state)\n");
 		$matches++;
 	}
 	if (!$matches)
 	{
 		my $reason = "No site matches $opts{'s'}";
 		my $retval = $E_NOTFOUND;
-		if (switch_history("site", "disabled", $opts{'s'}))
-		{
-			$reason .= " (disabled by maint)";
-			$retval = $E_OFFBYMAINT;
-		}
+		#ditto
+		#$retval = $E_OFFBYMAINT;
 		fail($reason, $retval);
 	}
 }
@@ -322,18 +329,21 @@ if (exists $opts{'c'})
 	}
 	foreach my $conf (grep { $_ =~ m/$opts{'c'}/ } @CONFS)
 	{
-		print("$conf\n");
+		$conf =~ s/\.conf$//;
+		my $state = switch_history("conf", "enabled", $conf);
+		if (!$state)
+		{
+			$state = "unknown";
+		}
+		print("$conf (by $state)\n");
 		$matches++;
 	}
 	if (!$matches)
 	{
 		my $reason = "No conf matches $opts{'c'}";
 		my $retval = $E_NOTFOUND;
-		if (switch_history("conf", "disabled", $opts{'c'}))
-		{
-			$reason .= " (disabled by maint)";
-			$retval = $E_OFFBYMAINT;
-		}
+		#ditto
+		#$retval = $E_OFFBYMAINT;
 		fail($reason, $retval);
 	}
 }
diff --git a/debian/apache2.dirs b/debian/apache2.dirs
index b5219b3..9ef4c24 100644
--- a/debian/apache2.dirs
+++ b/debian/apache2.dirs
@@ -3,6 +3,7 @@ etc/apache2/conf-enabled
 etc/apache2/sites-enabled
 etc/logrotate.d
 usr/lib/cgi-bin
+var/lib/apache2
 usr/share/lintian/overrides
 var/cache/apache2
 var/cache/apache2/mod_cache_disk
diff --git a/debian/apache2.postinst b/debian/apache2.postinst
index a61bc78..ec7b8ce 100644
--- a/debian/apache2.postinst
+++ b/debian/apache2.postinst
@@ -185,12 +185,14 @@ enable_default_mpm()
 			;;
 		esac
 
+		# No -m here, we pretend the user picked the MPM as this choice comes
+		# from a 2.2 package relation
 		a2enmod -q $mpm
 		return 0
 	fi
 
 	if is_fresh_install $@ ; then
-		a2enmod -q $mpm
+		a2enmod -m -q $mpm
 	fi
 
 }
@@ -203,11 +205,11 @@ enable_default_modules()
 				env mime negotiation setenvif \
 				filter deflate \
 				status ; do
-			a2enmod -q $module
+			a2enmod -m -q $module
 		done
 	elif we_are_upgrading_from_squeeze $@; then
 		for module in filter access_compat ; do
-			a2enmod -q $module
+			a2enmod -m -q $module
 		done
 	fi
 }
@@ -216,7 +218,7 @@ enable_default_conf()
 {
 	if is_fresh_install $@ || we_are_upgrading_from_squeeze $@ ; then
 		for conf in charset localized-error-pages other-vhosts-access-log security ; do
-			a2enconf -q $conf
+			a2enconf -m -q $conf
 		done
 	fi
 }
@@ -284,10 +286,12 @@ refresh_modules()
 
 			if [ ! -e "/etc/apache2/mods-enabled/$target" ] ; then
 				echo "disable obsolete module $module"
-				a2dismod -q "$module"
+				a2dismod -m -q "$module"
 
 				if [ "$module" = "disk_cache" ] ; then
 					echo "Enable cache_disk as disk_cache was enabled in Apache 2.2"
+					# ditto, we pretend it was the user's
+					# choice not to use -m here
 					a2enmod -q cache_disk
 				fi
 			fi
@@ -297,7 +301,7 @@ refresh_modules()
 			# Example: the deflate module when upgraded from
 			# Squeeze
 			if [ -e "/etc/apache2/mods-enabled/$target" ] ; then
-				a2enmod -q "$module"
+				a2enmod -m -q "$module"
 			fi
 		done
 	fi
diff --git a/debian/apache2.postrm b/debian/apache2.postrm
index 03d94f0..72de74c 100644
--- a/debian/apache2.postrm
+++ b/debian/apache2.postrm
@@ -48,7 +48,8 @@ case "$1" in
 
 	for d in var/cache/apache2 \
 		 var/cache/apache2/mod_cache_disk \
-		 var/log/apache2 ; do
+		 var/log/apache2 \
+		 var/lib/apache2 ; do
 		[ -d $d ] && rm -rf $d
 	done
 
diff --git a/debian/changelog b/debian/changelog
index a27582a..d7af688 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-apache2 (2.4.1-4) experimental; urgency=low
+apache2 (2.4.1-5) experimental; urgency=low
 
   * NOT RELEASED YET
   * Drop update-alternative call in postrm. Our prerm script catches them
@@ -9,8 +9,12 @@ apache2 (2.4.1-4) experimental; urgency=low
     Beckert for the hint.
   * Add /usr/share/doc/apache2/migrate-sites.pl, a script to assist users to
     give sites a .conf suffix, add a hint to the NEWS file.
+  * Do stateful configuration handling by remembering who enabled when a
+    particular piece of configuration. That way in can be told under which
+    circumstances for example modules should be re-enabled. Thanks to Filip M.
+    Nowak who was providing a patch where my changes are built upon.
 
- -- Arno Töll <arno at debian.org>  Tue, 03 Apr 2012 22:47:47 +0200
+ -- Arno Töll <arno at debian.org>  Mon, 09 Apr 2012 17:41:05 +0200
 
 apache2 (2.4.1-3) experimental; urgency=low
 
diff --git a/debian/debhelper/apache2-maintscript-helper b/debian/debhelper/apache2-maintscript-helper
index 6e6cd6b..eb8385d 100644
--- a/debian/debhelper/apache2-maintscript-helper
+++ b/debian/debhelper/apache2-maintscript-helper
@@ -173,7 +173,7 @@ apache2_has_module()
 {
 	[ -x /usr/sbin/a2query ] || return 1
 	local MODULE="$1"
-	if a2query -m $MODULE > /dev/null ; then
+	if a2query -m "^$MODULE\$" > /dev/null ; then
 		return 0
 	fi
 
@@ -217,14 +217,14 @@ apache2_switch_mpm()
 	local CUR_MPM=$(a2query -M) || return 1
 
 	if [ $CUR_MPM != $MPM ] ; then
-		a2dismod -q "mpm_$CUR_MPM";
-		a2enmod -q "mpm_$MPM";
+		a2dismod -m -q "mpm_$CUR_MPM";
+		a2enmod -m -q "mpm_$MPM";
 		apache2_msg "info" "apache2_switch_mpm Switch to $MPM"
 	fi
 
 	if ! apache2_has_module "mpm_$MPM" ; then
 		# rollback
-		a2enmod -q "mpm_$CUR_MPM"
+		a2enmod -m -q "mpm_$CUR_MPM"
 		apache2_msg "warning" "apache2_switch_mpm Switch to $MPM failed. Rolling back to $CUR_MPM"
 		return 1
 	fi
@@ -288,11 +288,11 @@ apache2_invoke()
 
 	case "$CMD" in
 		enconf|enmod|ensite)
-			if a2query $check_switch $CONF > /dev/null 2>&1 ; then
+			if a2query $check_switch "^$CONF\$" > /dev/null 2>&1 ; then
 				continue
 			fi
 			invoke_rcd=1
-			a2$CMD -q "$CONF" > /dev/null 2>&1 || return 1
+			a2$CMD -m -q "$CONF" > /dev/null 2>&1 || return 1
 			apache2_msg "info" "apache2_invoke: Enable $invoke_string $CONF"
 			;;
 		disconf|dismod|dissite)
@@ -302,7 +302,7 @@ apache2_invoke()
 					#XXX: Replace me by the "forget-state-switch" call
 					a2$CMD -f -q "$CONF" || return 1
 				else
-					a2$CMD -f -q "$CONF" || return 1
+					a2$CMD -m -f -q "$CONF" || return 1
 				fi
 				apache2_msg "info" "apache2_invoke: Disable $invoke_string $CONF"
 			else
diff --git a/debian/manpages/a2enconf.8 b/debian/manpages/a2enconf.8
index d3ff413..978120d 100644
--- a/debian/manpages/a2enconf.8
+++ b/debian/manpages/a2enconf.8
@@ -51,6 +51,11 @@ being installed and manged by reverse dependencies (e.g. web scripts).
 .TP
 .B \-q, \-\-quiet
 Don't show informative messages.
+.TP
+.B \-m, \-\-maintmode
+Enables the maintainer mode, that is the program invokation is effectuated
+automatically by a maintainer script. This switch should not be used by end
+users.
 .SH "EXIT STATUS"
 .B a2enconf
 and
diff --git a/debian/manpages/a2enmod.8 b/debian/manpages/a2enmod.8
index 18148ca..4bc8b12 100644
--- a/debian/manpages/a2enmod.8
+++ b/debian/manpages/a2enmod.8
@@ -51,6 +51,11 @@ directives in the .conf file as directives into the main server context of
 .TP
 .B \-q, \-\-quiet
 Don't show informative messages.
+.TP
+.B \-m, \-\-maintmode
+Enables the maintainer mode, that is the program invokation is effectuated
+automatically by a maintainer script. This switch should not be used by end
+users.
 .SH "EXIT STATUS"
 .B a2enmod
 and
diff --git a/debian/manpages/a2ensite.8 b/debian/manpages/a2ensite.8
index 4e589ed..17291a7 100644
--- a/debian/manpages/a2ensite.8
+++ b/debian/manpages/a2ensite.8
@@ -51,6 +51,11 @@ in order to sort before the remaining hosts to be loaded first.
 .TP
 .B \-q, \-\-quiet
 Don't show informative messages.
+.TP
+.B \-m, \-\-maintmode
+Enables the maintainer mode, that is the program invokation is effectuated
+automatically by a maintainer script. This switch should not be used by end
+users.
 .SH "EXIT STATUS"
 .B a2ensite
 and

-- 
Debian packaging for apache2 (Apache HTTPD 2.x)



More information about the Pkg-apache-commits mailing list