[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 d044417e61d0cdb7d91433cffca7448d78402888
Author: Filip M. Nowak <debian-apache at oneiroi.net>
Date:   Tue Mar 27 21:36:42 2012 +0000

    * Added module/configuration/site on|off "memory"

diff --git a/debian/a2enmod b/debian/a2enmod
index fee796d..717527b 100755
--- a/debian/a2enmod
+++ b/debian/a2enmod
@@ -7,6 +7,7 @@ use strict;
 use Cwd 'realpath';
 use File::Spec;
 use File::Basename;
+use File::Path;
 use Getopt::Long;
 
 my $quiet;
@@ -33,6 +34,14 @@ 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' ) {
@@ -141,7 +150,6 @@ sub doit {
                                 info("removing dangling symlink $conflink\n");
                                 unlink($conflink)
                         }
-
 			return 1;
 		}
 		else {
@@ -190,31 +198,32 @@ 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) {
 
@@ -234,7 +243,7 @@ sub doit {
                 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 );
+		return add_link( $tgt, $link ) && switch_marker($obj, $act, $acton);
         }
         else {
             error("$name $acton not properly enabled: $check\n");
@@ -243,11 +252,12 @@ sub doit {
     }
     else {
         if ( -e $link || -l $link ) {
-            remove_link($link);
+            	remove_link($link);
             if ( $conflink && -e $conflink ) {
                 remove_link($conflink);
-            }
-            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";
@@ -443,3 +453,33 @@ sub read_env_file {
         $ENV{$1} = $2;
     }
 }
+
+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;
+		}
+	}
+	info("Creating '$state_marker'\n");
+	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 ed970a1..ed331bd 100755
--- a/debian/a2query.in
+++ b/debian/a2query.in
@@ -52,8 +52,21 @@ our $APACHE2 = "apache2ctl";
 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 $MPM = "invalid";
 our $CONFIG_DIR = "/etc/apache2";
+# time to introduce more _exit_ values
+our $E_OK = '0';
+our $E_FOUND = '0';
+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 =();
@@ -125,9 +138,11 @@ This manual and L<a2query> was written by Arno Toell <debian at toell.net>.
 
 sub fail
 {
+	die('usage: fail($reason, $retval)') if @_ != 2;
 	my $reason = shift;
+	my $retval = shift;
 	print STDERR "$reason\n";
-	exit 1;
+	exit $retval;
 }
 
 sub load_defaults
@@ -216,6 +231,20 @@ sub load_sites
 	closedir(DIR);
 }
 
+sub switch_history
+{
+	die('usage: switch_history([module|site|conf], [enabled|disabled], $name)') if @_ != 3;
+	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)
+	{
+		return 1;
+	}
+	return 0;
+}
 
 load_defaults();
 load_modules();
@@ -241,11 +270,17 @@ if (exists $opts{'m'})
 	}
 	if (!$matches)
 	{
-		fail("No module matches $opts{'m'}");
+		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;
+		}
+		fail($reason, $retval);
 	}
 }
 
-
 push @HELP, ["s [SITE]", "checks whether the site SITE is enabled, lists all sites if no argument was given"];
 if (exists $opts{'s'})
 {
@@ -263,7 +298,14 @@ if (exists $opts{'s'})
 	}
 	if (!$matches)
 	{
-		fail("No site matches $opts{'s'}");
+		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;
+		}
+		fail($reason, $retval);
 	}
 }
 
@@ -285,7 +327,14 @@ if (exists $opts{'c'})
 	}
 	if (!$matches)
 	{
-		fail("No conf matches $opts{'c'}");
+		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;
+		}
+		fail($reason, $retval);
 	}
 }
 
@@ -330,7 +379,7 @@ if (exists $opts{'h'} or $help == 1)
 		my ($switch, $description) = ($switch->[0], $switch->[1]);
 		print("-$switch\t\t$description\n");
 	}
-	exit 0;
+	exit $E_OK;
 }
 
 

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



More information about the Pkg-apache-commits mailing list