[PATCH 4/4] update-rc.d: add disable|reenable runlevel link interface

Kel Modderman kel at otaku42.de
Thu Sep 18 08:52:14 UTC 2008


DISABLING OR REENABLING INIT SCRIPT LINKS

When run with the disable [ S|2|3|4|5 ] options, update-rc.d modifies
existing runlevel links for the script /etc/init.d/name by
renaming start links to stop links with a sequence number equal to the
difference of 100 minus the orignal sequence number.

When run with the reenable [ S|2|3|4|5 ] options, update-rc.d modifies existing
runlevel links for the script /etc/init.d/name by renaming stop links to start
links with a sequence number equal to the positive difference of current
sequence number minus 100, thus returning to the original sequence number that
the script had been installed with before disabling it.

Both of these options only operate on start runlevel links of S, 2, 3, 4 or 5.
If no start runlevel is specified after the disable or enable keywords, the
script will attempt to modify links in all start runlevels.
---
--- a/debian/sysv-rc/sbin/update-rc.d
+++ b/debian/sysv-rc/sbin/update-rc.d
@@ -20,6 +20,7 @@
        update-rc.d [-d <path>] [-n] <basename> defaults [NN | SS KK]
        update-rc.d [-d <path>] [-n] <basename> start|stop NN runlvl [runlvl] [...] .
        update-rc.d [-d <path>] [-n] <basename> from [...] to [...]
+       update-rc.d [-d <path>] [-n] <basename> disable|reenable [S|2|3|4|5]
 		-n: not really
 		-f: force
 		-d: path to alternate /
@@ -75,11 +76,12 @@
 my @stoplinks;
 
 $_ = $ARGV[0];
-if    (/^remove$/)       { &checklinks ("remove"); }
-elsif (/^from$/)         { &fromto (@ARGV); &makelinks; }
-elsif (/^defaults$/)     { &defaults (@ARGV); &makelinks; }
-elsif (/^(start|stop)$/) { &startstop (@ARGV); &makelinks; }
-else                     { &usage; }
+if    (/^remove$/)         { &checklinks ("remove"); }
+elsif (/^from$/)           { &fromto (@ARGV); &makelinks; }
+elsif (/^defaults$/)       { &defaults (@ARGV); &makelinks; }
+elsif (/^(start|stop)$/)   { &startstop (@ARGV); &makelinks; }
+elsif (/^(dis|reen)able$/) { &toggle (@ARGV); &makelinks; }
+else                       { &usage; }
 
 exit (0);
 
@@ -227,6 +229,70 @@
     1;
 }
 
+# Process the arguments after the "reenable" or "disable" keyword.
+
+sub toggle {
+    my @argv = @_;
+    my ($action, %lvls, @start, @stop, @xstartlinks);
+
+    if (!&checklinks) {
+	print " System startup links for $initd/$bn do not exist.\n";
+	exit (0);
+    }
+
+    $action = $argv[0];
+    if ($#argv > 1) {
+	while ($#argv > 0 && shift @argv) {
+	    if ($argv[0] =~ /^[S2-5]$/) {
+		$lvls{$argv[0]}++;
+	    } else {
+		&usage ("expected 'S' '2' '3' '4' or '5'");
+	    }
+	}
+    } else {
+	$lvls{$_}++ for ('S', '2', '3', '4', '5');
+    }
+
+    push(@start, glob($etcd . '[2-5S].d/[KS][0-9][0-9]' . $bn));
+
+    foreach (@start) {
+	my $islink = &is_link (undef, $_, $bn);
+	next if !$islink;
+
+	next unless my ($lvl, $sk, $seq) = m/^$etcd([2-5S])\.d\/([SK])([0-9]{2})$bn$/;
+	$startlinks[$lvl] = $sk . $seq;
+
+	if ($action eq 'disable' and $sk eq 'S' and $lvls{$lvl}) {
+	    $xstartlinks[$lvl] = 'K' . (100 - $seq);
+	} elsif ($action eq 'reenable' and $sk eq 'K' and $lvls{$lvl}) {
+	    $xstartlinks[$lvl] = 'S' . -($seq - 100);
+	} else {
+	    $xstartlinks[$lvl] = $sk . $seq;
+	}
+    }
+
+    push(@stop, glob($etcd . '[016].d/[KS][0-9][0-9]' . $bn));
+
+    foreach (@stop) {
+	my $islink = &is_link (undef, $_, $bn);
+	next if !$islink;
+
+	next unless my ($lvl, $sk, $seq) = m/^$etcd([016])\.d\/([SK])([0-9]{2})$bn$/;
+	$stoplinks[$lvl] = $sk . $seq;
+    }
+
+    if ($action eq 'disable') {
+	print " Disabling system startup links for $initd/$bn ...\n";
+    } elsif ($action eq 'reenable') {
+	print " Re-enabling system startup links for $initd/$bn ...\n";
+    }
+
+    &checklinks ("remove");
+    @startlinks = @xstartlinks;
+
+    1;
+}
+
 # Process the arguments after the "defaults" keyword.
 
 sub defaults {
--- a/debian/sysv-rc/man8/update-rc.d.8
+++ b/debian/sysv-rc/man8/update-rc.d.8
@@ -33,6 +33,12 @@
 .I name
 .BR from " defaults|start|stop ... "
 .BR to " defaults|start|stop ... "
+.HP
+.B update-rc.d
+.RI [ -d " path " ]
+.RI [ -n ]
+.IB name " disable|reenable "
+.RI [ " S|2|3|4|5 " ]
 .SH DESCRIPTION
 .B update-rc.d
 updates the System V style init script links
@@ -58,19 +64,7 @@
 .BR init (8)
 and the
 .IR "Debian Policy Manual" .
-.P
-Please note that this program was designed for use
-in package maintainer scripts and, accordingly,
-has only the very limited functionality required by such scripts.
-System administrators are not encouraged to use
-.BR update-rc.d
-to manage runlevels.
-They should edit the links directly or
-use runlevel editors such as
-.B sysv-rc-conf
-and
-.B bum
-instead.
+
 .SH INSTALLING INIT SCRIPT LINKS
 When run with either the
 .BR defaults ", " start ", or " stop
@@ -233,6 +227,30 @@
 It is intended that this be used only in maintainer scripts of
 packages wishing to change the runlevel link configuration for a
 service script while preserving locally modified link configurations.
+.SH DISABLING OR REENABLING INIT SCRIPT LINKS
+When run with the
+.BR disable " [ " S|2|3|4|5 " ] "
+options,
+.B update-rc.d
+modifies existing runlevel links for the script
+.BR /etc/init.d/ \fIname\fR
+by renaming start links to stop links with a sequence number equal
+to the difference of 100 minus the original sequence number.
+.P
+When run with the
+.BR reenable " [ " S|2|3|4|5 " ] "
+options,
+.B update-rc.d
+modifies existing runlevel links for the script
+.BR /etc/init.d/ \fIname\fR
+by renaming stop links to start links with a sequence number equal
+to the positive difference of current sequence number minus 100, thus
+returning to the original sequence number that the script had been
+installed with before disabling it.
+.P
+Both of these options only operate on start runlevel links of S, 2,
+3, 4 or 5. If no start runlevel is specified after the disable or enable
+keywords, the script will attempt to modify links in all start runlevels.
 
 .SH OPTIONS
 .TP
---



More information about the initscripts-ng-devel mailing list