[Pkg-sysvinit-commits] r1635 - in sysvinit/trunk/debian: . sysv-rc/sbin

Petter Reinholdtsen pere at alioth.debian.org
Wed Aug 26 06:31:33 UTC 2009


Author: pere
Date: 2009-08-26 06:31:33 +0000 (Wed, 26 Aug 2009)
New Revision: 1635

Added:
   sysvinit/trunk/debian/sysv-rc.prerm
Modified:
   sysvinit/trunk/debian/rules
   sysvinit/trunk/debian/sysv-rc.postinst
   sysvinit/trunk/debian/sysv-rc.postrm
   sysvinit/trunk/debian/sysv-rc.preinst
   sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d
Log:
Different approach to migration, saving the update-rc.d calls for each script, to be able to replay when file-rc is installed.

Modified: sysvinit/trunk/debian/rules
===================================================================
--- sysvinit/trunk/debian/rules	2009-08-25 20:28:34 UTC (rev 1634)
+++ sysvinit/trunk/debian/rules	2009-08-26 06:31:33 UTC (rev 1635)
@@ -285,8 +285,9 @@
 	install -d -o root -g root -m 755 $(tmp)/etc
 	install -d -o root -g root -m 755 $(tmp)/usr/share
 	install -d -o root -g root -m 755 $(tmp)$(doc)/sysv-rc
+	install -d -o root -g root -m 755 $(tmp)/usr/share/sysv-rc
 	install -d -o root -g root -m 755 $(tmp)/var/lib/insserv
-	install -d -o root -g root -m 755 $(tmp)/var/lib/sysv-rc
+	install -d -o root -g root -m 755 $(tmp)/var/lib/sysv-rc/lastactions
 	install -o root -g root -m 644 debian/sysv-rc/doc/* $(tmp)$(doc)/sysv-rc
 	sed -ne '/sysvinit (2.84-3)/q' -e p < debian/changelog \
 		> $(tmp)$(doc)/sysv-rc/changelog.Debian
@@ -327,11 +328,11 @@
 	install -o root -g root -m 644 debian/sysv-rc.copyright \
 	  $(tmp)$(doc)/sysv-rc/copyright
 	po2debconf debian/sysv-rc.templates > $(tmp)/DEBIAN/templates
-	for f in preinst postinst postrm ; do \
+	for f in preinst postinst prerm postrm ; do \
 		install -o root -g root -m 755 debian/sysv-rc.$$f $(tmp)/DEBIAN/$$f ; \
 	done
 	install -o root -g root -m 755 debian/sysv-rc/saveconfig \
-		$(tmp)/usr/share/doc/sysv-rc/saveconfig
+		$(tmp)/usr/share/sysv-rc/saveconfig
 	dpkg-gencontrol -psysv-rc -P$(tmp) -isp
 	dh_md5sums -Ninitscripts -Nsysv-rc
 	dpkg --build $(tmp) ..

Modified: sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d
===================================================================
--- sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d	2009-08-25 20:28:34 UTC (rev 1634)
+++ sysvinit/trunk/debian/sysv-rc/sbin/update-rc.d	2009-08-26 06:31:33 UTC (rev 1635)
@@ -30,7 +30,7 @@
 # Dependency based boot sequencing is the default, but upgraded
 # systems might keep the legacy ordering until the sysadm choose to
 # migrate to the new ordering method.
-if ( ! -f "/var/lib/sysv-rc/legacy-bootsequence" ) {
+if ( ! -f "/etc/init.d/.legacy-bootordering" ) {
     info("using dependency based boot sequencing");
     exit insserv_updatercd(@ARGV);
 }
@@ -38,6 +38,8 @@
 # Check out options.
 my $force;
 
+my @orig_argv = @ARGV;
+
 while($#ARGV >= 0 && ($_ = $ARGV[0]) =~ /^-/) {
 	shift @ARGV;
 	if (/^-n$/) { $notreally++; next }
@@ -46,6 +48,15 @@
 	&usage("unknown option");
 }
 
+sub save_last_action {
+    my ($script, @arguments) = @_;
+    my $archive = "/var/lib/sysv-rc/lastactions";
+    open(FILE, ">", "$archive/${script}.new") || die;
+    print FILE join(" ","update-rc.d", at arguments), "\n";
+    close(FILE);
+    rename "$archive/${script}.new", "$archive/${script}";
+}
+
 # Action.
 
 &usage() if ($#ARGV < 1);
@@ -73,10 +84,10 @@
 my @stoplinks;
 
 $_ = $ARGV[0];
-if    (/^remove$/)       { &checklinks ("remove"); }
-elsif (/^defaults$/)     { &defaults (@ARGV); &makelinks; }
-elsif (/^(start|stop)$/) { &startstop (@ARGV); &makelinks; }
-elsif (/^(dis|en)able$/) { &toggle (@ARGV); &makelinks; }
+if    (/^remove$/)       { &checklinks ("remove"); save_last_action($bn, @orig_argv); }
+elsif (/^defaults$/)     { &defaults (@ARGV); &makelinks; save_last_action($bn, @orig_argv); }
+elsif (/^(start|stop)$/) { &startstop (@ARGV); &makelinks; save_last_action($bn, @orig_argv); }
+elsif (/^(dis|en)able$/) { &toggle (@ARGV); &makelinks; save_last_action($bn, @orig_argv); }
 else                     { &usage; }
 
 exit (0);
@@ -316,7 +327,7 @@
 
     if (&checklinks) {
 	print " System start/stop links for $initd/$bn already exist.\n";
-	exit (0);
+	return 0;
     }
     print " Adding system startup for $initd/$bn ...\n";
 
@@ -346,6 +357,8 @@
     my $action;
     my $notreally = 0;
 
+    my @orig_argv = @args;
+
     while($#args >= 0 && ($_ = $args[0]) =~ /^-/) {
         shift @args;
         if (/^-n$/) { push(@opts, $_); $notreally++; next }
@@ -360,11 +373,19 @@
     $action = shift @args;
     if ("remove" eq $action) {
         if ( -f "/etc/init.d/$scriptname" ) {
-            exec "insserv", @opts, "-r", $scriptname;
+            my $rc = system "insserv", @opts, "-r", $scriptname;
+            if (0 == $rc && !$notreally) {
+                save_last_action($scriptname, @orig_argv);
+            }
+            exit $rc;
         } else {
             # insserv removes all dangling symlinks, no need to tell it
             # what to look for.
-            exec "insserv", @opts;
+            my $rc = system "insserv", @opts;
+            if (0 == $rc && !$notreally) {
+                save_last_action($scriptname, @orig_argv);
+            }
+            exit $rc;
         }
     } elsif ("defaults" eq $action || "start" eq $action ||
              "stop" eq $action) {
@@ -377,14 +398,22 @@
             info("\`$action @args' overridden by LSB info of $scriptname");
         }
         if ( -f "/etc/init.d/$scriptname" ) {
-            exec "insserv", @opts, $scriptname;
+            my $rc = system "insserv", @opts, $scriptname;
+            if (0 == $rc && !$notreally) {
+                save_last_action($scriptname, @orig_argv);
+            }
+            exit $rc;
         } else {
             error("initscript does not exist: /etc/init.d/$scriptname");
         }
     } elsif ("disable" eq $action || "enable" eq $action) {
         insserv_toggle($action, $scriptname, @args);
         # Call insserv to resequence modified links
-        exec "insserv", @opts, $scriptname;
+        my $rc = system "insserv", @opts, $scriptname;
+        if (0 == $rc && !$notreally) {
+            save_last_action($scriptname, @orig_argv);
+        }
+        exit $rc;
     } else {
         usage();
     }

Modified: sysvinit/trunk/debian/sysv-rc.postinst
===================================================================
--- sysvinit/trunk/debian/sysv-rc.postinst	2009-08-25 20:28:34 UTC (rev 1634)
+++ sysvinit/trunk/debian/sysv-rc.postinst	2009-08-26 06:31:33 UTC (rev 1635)
@@ -7,8 +7,6 @@
 
 now=`date +%Y%m%dT%H%M`
 logdir=/var/lib/insserv
-backupfile="$logdir/bootscripts-$now.tar.gz"
-listfile="$logdir/bootscripts-$now-after.list"
 logfile="$logdir/run-$now.log"
 flagfile=/etc/init.d/.legacy-bootordering
 
@@ -69,7 +67,7 @@
     # with init.d scripts, as their dependency information is probably
     # outdated or missing, leading to incorrect ordering.
     for package in $(dpkg -l $(dpkg -S /etc/init.d/* 2>/dev/null |
-	    cut -d: -f1)|grep ^rc|awk '{print $2}') ; do
+	    cut -d: -f1 |sort -u)|grep ^rc|awk '{print $2}') ; do
         echo "error: Removed but not purged package $package with init.d script"
 	return 0
     done
@@ -85,8 +83,14 @@
 }
 
 activate_insserv() {
-    echo "info: Backing up existing boot scripts in $backupfile"
-    (cd /etc; tar zcf $backupfile init.d rc*.d)
+    # Save the current sequence numbers in
+    # /var/lib/sysv-rc/lastactions/.  This directory will be updated
+    # when update-rc.d is called, to make it possible to migrate away
+    # from dependency based boot sequencing.  If some script is
+    # missing in /var/lib/sysv-rc/lastactions/, one will have to
+    # reconfigure the package it belong to for update-rc.d to update
+    # the content in /var/lib/sysv-rc/lastactions/.
+    /usr/share/sysv-rc/saveconfig -s /var/lib/sysv-rc/lastactions
 
     echo "info: Reordering boot system, log to $logfile"
     (
@@ -97,9 +101,6 @@
 	insserv -v
     ) > $logfile 2>&1
 
-    echo "info: Recording new boot sequence in $listfile"
-    ls /etc/init.d /etc/rc*.d > $listfile
-
     # Indicate that system is no longer using the legacy ordering
     rm $flagfile
 
@@ -120,9 +121,12 @@
 	return 1
     else
 	# Ask if the legacy boot sequence should be converted to
-	# dependency based, making 'yes' the default.
-	db_set sysv-rc/convert-legacy true
+	# dependency based, making 'no' the default.
+	db_set sysv-rc/convert-legacy false
 
+	# Make sure the question is seen every time
+	db_fset sysv-rc/convert-legacy seen false
+
 	# Priority is critical during upgrades, to give those with
 	# existing installations a good  chance of seeing and rejecting
 	# the migration.
@@ -145,17 +149,20 @@
 
 case "$1" in
     configure)
-        # Remove insserv created divert during upgrades if it exist.
-        # It was dropped in insserv 1.12.0-11 converted since sysvinit
-        # 2.87dsf-3, 2009-08-19.
-        if [ ! -f /var/run/sysv-rc.upgrade ]; then
-	    if check_divert status /usr/sbin/update-rc.d \
-		/usr/sbin/update-rc.d-insserv ; then
-		check_divert false /usr/sbin/update-rc.d \
-		    /usr/sbin/update-rc.d-insserv
-		rm /var/lib/insserv/using-insserv
-	    else
-		touch $flagfile
+        # Remove divert created by insserv during upgrades if it
+        # exist.  It was dropped in insserv 1.12.0-11 converted since
+        # sysvinit 2.87dsf-3, 2009-08-19.
+        if [ -f /var/run/sysv-rc.upgrade ]; then
+	    lastver=$(cat /var/run/sysv-rc.upgrade)
+	    if dpkg --compare-versions "$2" lt 2.87dsf-3 ; then
+		if check_divert status /usr/sbin/update-rc.d \
+		    /usr/sbin/update-rc.d-insserv ; then
+		    check_divert false /usr/sbin/update-rc.d \
+			/usr/sbin/update-rc.d-insserv
+		    rm /var/lib/insserv/using-insserv
+		else
+		    touch $flagfile
+		fi
 	    fi
 	fi
 	if [ -f $flagfile ] ; then

Modified: sysvinit/trunk/debian/sysv-rc.postrm
===================================================================
--- sysvinit/trunk/debian/sysv-rc.postrm	2009-08-25 20:28:34 UTC (rev 1634)
+++ sysvinit/trunk/debian/sysv-rc.postrm	2009-08-26 06:31:33 UTC (rev 1635)
@@ -29,6 +29,9 @@
 
 # Remove the flag file indicating dependency based boot sequencing, to
 # make sure we convert / update if migrating back from file-rc.
-rm /var/lib/insserv/using-insserv
+rm -f /var/lib/insserv/using-insserv
 
+# Remove the recorded update-rc.d calls
+rm /var/lib/sysv-rc/lastactions/*
+
 exit 0

Modified: sysvinit/trunk/debian/sysv-rc.preinst
===================================================================
--- sysvinit/trunk/debian/sysv-rc.preinst	2009-08-25 20:28:34 UTC (rev 1634)
+++ sysvinit/trunk/debian/sysv-rc.preinst	2009-08-26 06:31:33 UTC (rev 1635)
@@ -11,6 +11,12 @@
 
 case "$1" in
     upgrade)
+	# Remain in legacy mode during upgrades, unless insserv is
+	# already activated.
+	if [ ! -f /var/lib/insserv/using-insserv ] &&
+	    dpkg --compare-versions "$2" lt 2.87dsf-3 ; then
+	    touch /etc/init.d/.legacy-bootordering
+	fi
         echo "$2" > /var/run/sysv-rc.upgrade
     	;;
     install)

Added: sysvinit/trunk/debian/sysv-rc.prerm
===================================================================
--- sysvinit/trunk/debian/sysv-rc.prerm	                        (rev 0)
+++ sysvinit/trunk/debian/sysv-rc.prerm	2009-08-26 06:31:33 UTC (rev 1635)
@@ -0,0 +1,86 @@
+#! /bin/sh
+#
+# sysv-rc prerm
+#
+
+set -e
+
+revert_to_legacy_ordering() {
+    # First, check that we have all the needed actions recorded
+    present=""
+    missing=""
+    for script in /etc/init.d/* ; do
+	name=$(basename $script)
+	case $name in
+	    *.dpkg*)
+		continue;
+		;;
+	esac
+	enabled=""
+	for f in $(ls /etc/rc?.d/[KS][0-9][0-9]$name 2> /dev/null) ; do
+	    if [ -e $f ] ; then
+		if [ ! -f /var/lib/sysv-rc/lastactions/$name ] ; then
+		    missing="$missing $script"
+		else
+		    present="$present $name"
+		fi
+		break;
+	    fi
+	done
+    done
+
+    if [ "$missing" ] ; then
+	cat <<EOF
+Unable to revert to legacy boot ordering to remove sysv-rc.  Missing
+update-rc.d information for the following packages:
+
+EOF
+	# Map from script to packages
+	for pkg in $(dpkg -S $missing | cut -d: -f1 | sort -u) ; do
+	    if dpkg -l $pkg | grep -q ^ii ; then
+		echo "  $pkg"
+	    else
+		echo "  $pkg (removed but not purged)"
+	    fi
+	done
+	cat <<EOF
+
+This is due to a earlier issues with sysv-rc and insserv.  To work
+around this bug, the packages listed need to be reconfigured to
+register the update-rc.d call again, for example using
+
+  dpkg-reconfigure packagename
+
+before trying again to migrate to legacy boot ordering.  For some
+packages, purging and reinstalling might be needed to record the
+update-rc.d call.
+
+Aborting package removal until this is done, to avoid leaving the boot
+system in a non-functioning state.
+
+EOF
+	return 1
+    fi
+
+    # Enable legacy boot ordering, remove all start and stop symlinks,
+    # and register all scripts again.
+    touch /etc/init.d/.legacy-bootordering
+    for script in $present ; do
+	rm /etc/rc?.d/[KS][0-9][0-9]$script
+	sh -x /var/lib/sysv-rc/lastactions/$script
+    done
+    return 0
+}
+ 
+case "$1" in
+	remove)
+            # Refuse to be uninstalled unless all the needed
+            # update-rc.d calls are recorded already.
+	    if [ ! -f /etc/init.d/.legacy-bootordering ] ; then
+		revert_to_legacy_ordering
+	    fi
+	    ;;
+	*) : ;;
+esac
+
+exit 0


Property changes on: sysvinit/trunk/debian/sysv-rc.prerm
___________________________________________________________________
Added: svn:executable
   + *




More information about the Pkg-sysvinit-commits mailing list