[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RFC: update-rc.d <script> disable|reenable



Hi all,

This email describes an extension of update-rc.d to provide an interface
for disabling and reenabling initscript sysvinit runlevel start links.

It contains a patch that is the last in a series[0] of patches submitted to
the sysvinit team. After speaking with Petter Reinholdtsen on irc he suggested
sending the idea to a wider audience for review and discusion.

Another proposed update-rc.d extension[1] is worth a mention too, though it is
not described in detail by this communication. It is a proposal for a method
providing an interface for maintainer scripts to facilitate change of runlevel
scheme on package upgrades.

Please have a comment and identify what you think is good and crap.

[0] http://lists.alioth.debian.org/pipermail/pkg-sysvinit-devel/2008-September/002861.html
[1] http://lists.alioth.debian.org/pipermail/pkg-sysvinit-devel/2008-September/002865.html
---

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.

Below is an excerpt from a test suite script which shows the intended interface
in action. At the very bottom of this email exists the patch (it depends on the
other patches in the aforementioned series).

--- update-rc.d hotkey-setup start 85 2 3 4 5 . stop 20 1 .
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/S85hotkey-setup -> ../init.d/hotkey-setup


---
/
`-- etc/
    |-- init.d/
    |   `-- hotkey-setup
    |-- rc0.d/
    |-- rc1.d/
    |   `-- K20hotkey-setup -> ../init.d/hotkey-setup
    |-- rc2.d/
    |   `-- S85hotkey-setup -> ../init.d/hotkey-setup
    |-- rc3.d/
    |   `-- S85hotkey-setup -> ../init.d/hotkey-setup
    |-- rc4.d/
    |   `-- S85hotkey-setup -> ../init.d/hotkey-setup
    |-- rc5.d/
    |   `-- S85hotkey-setup -> ../init.d/hotkey-setup
    |-- rc6.d/
    `-- rcS.d/


--- update-rc.d hotkey-setup disable
 Disabling system startup links for /etc/init.d/hotkey-setup ...
 Removing any system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup
   /etc/rc2.d/S85hotkey-setup
   /etc/rc3.d/S85hotkey-setup
   /etc/rc4.d/S85hotkey-setup
   /etc/rc5.d/S85hotkey-setup
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/K15hotkey-setup -> ../init.d/hotkey-setup


--- update-rc.d hotkey-setup reenable
 Re-enabling system startup links for /etc/init.d/hotkey-setup ...
 Removing any system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup
   /etc/rc2.d/K15hotkey-setup
   /etc/rc3.d/K15hotkey-setup
   /etc/rc4.d/K15hotkey-setup
   /etc/rc5.d/K15hotkey-setup
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/S85hotkey-setup -> ../init.d/hotkey-setup


--- update-rc.d hotkey-setup disable 2 3 4
 Disabling system startup links for /etc/init.d/hotkey-setup ...
 Removing any system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup
   /etc/rc2.d/S85hotkey-setup
   /etc/rc3.d/S85hotkey-setup
   /etc/rc4.d/S85hotkey-setup
   /etc/rc5.d/S85hotkey-setup
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/S85hotkey-setup -> ../init.d/hotkey-setup


--- update-rc.d hotkey-setup reenable 3 4
 Re-enabling system startup links for /etc/init.d/hotkey-setup ...
 Removing any system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup
   /etc/rc2.d/K15hotkey-setup
   /etc/rc3.d/K15hotkey-setup
   /etc/rc4.d/K15hotkey-setup
   /etc/rc5.d/S85hotkey-setup
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/K15hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/S85hotkey-setup -> ../init.d/hotkey-setup


--- update-rc.d hotkey-setup reenable
 Re-enabling system startup links for /etc/init.d/hotkey-setup ...
 Removing any system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup
   /etc/rc2.d/K15hotkey-setup
   /etc/rc3.d/S85hotkey-setup
   /etc/rc4.d/S85hotkey-setup
   /etc/rc5.d/S85hotkey-setup
 Adding system startup links for /etc/init.d/hotkey-setup ...
   /etc/rc1.d/K20hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc2.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc3.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc4.d/S85hotkey-setup -> ../init.d/hotkey-setup
   /etc/rc5.d/S85hotkey-setup -> ../init.d/hotkey-setup
---
--- 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
---


Reply to: