I'm working on update-rc.d to add this feature (got bitten by this using
saltstack service states on Jessie w/ systemd).
I simplified Michael's idea a little bit (I think).
Instead of checking if links correspond to Default-Start + Default-Stop,
i'm just checking if there are all the Default-Start links available.
For is-disabled I'm only checking that there are no S links present in
Default-Start runlevels.
IMO, no links == disabled (I know they get recreated on upgrades, but
that is out of scope for this feature).
Here is a function I added to update-rc.d. I welcome any comments. It
seems to work for me, but is more of a proof of concepts, needs cleaning
up (there's also a few lines in insserv_updatercd to call it when action
is is-enabled or is-disabled).
sub is_enabled_disabled {
my ($act, $name) = (shift, shift);
my ($defstart_lvls, $defstop_lvls, @start_links, $lvl);
my $lsb_header = lsb_header_for_script($name);
my @runlevels = split('','S2345');
($defstart_lvls, $defstop_lvls) = parse_def_start_stop($lsb_header);
#print "start levels: @$defstart_lvls\n";
#print "stop levels: @$defstop_lvls\n";
foreach $lvl (@runlevels) {
push(@start_links,$_) for glob("/etc/rc$lvl.d/S[0-9][0-9]$name");
}
if("is-enabled" eq $act) {
foreach $lvl (@$defstart_lvls) {
if ( !grep( m{^/etc/rc$lvl.d/}, @start_links) ) {
#not enabled in all runlevels, return error
print "$name not started in runlevel $lvl\n";
exit 1;
}
}
exit 0;
}
if("is-disabled" eq $act) {
foreach $lvl (@$defstart_lvls) {
if ( grep( m{^/etc/rc$lvl.d/}, @start_links) ) {
print "$name starts in runlevel $lvl, not disabled.\n";
exit 1;
}
}
exit 0;
}
}