<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <tt>I'm working on update-rc.d to add this feature (got bitten by
      this using saltstack service states on Jessie w/ systemd).<br>
      <br>
      I simplified Michael's idea a little bit (I think).<br>
      <br>
      Instead of checking if links correspond to Default-Start +
      Default-Stop, i'm just checking if there are all the Default-Start
      links available.<br>
      <br>
      For is-disabled I'm only checking that there are no S links
      present in Default-Start runlevels.<br>
      <br>
      IMO, no links == disabled (I know they get recreated on upgrades,
      but that is out of scope for this feature).<br>
      <br>
      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).<br>
      <br>
      <br>
      <br>
      sub is_enabled_disabled {<br>
          my ($act, $name) = (shift, shift);<br>
          my ($defstart_lvls, $defstop_lvls, @start_links, $lvl);<br>
          my $lsb_header = lsb_header_for_script($name);<br>
          my @runlevels = split('','S2345');<br>
      <br>
          ($defstart_lvls, $defstop_lvls) =
      parse_def_start_stop($lsb_header);<br>
      <br>
          #print "start levels: @$defstart_lvls\n";<br>
          #print "stop levels: @$defstop_lvls\n";<br>
      <br>
          foreach $lvl (@runlevels) {<br>
              push(@start_links,$_) for
      glob("/etc/rc$lvl.d/S[0-9][0-9]$name");<br>
          }<br>
      <br>
          if("is-enabled" eq $act) {<br>
              foreach $lvl (@$defstart_lvls) {<br>
                  if ( !grep( m{^/etc/rc$lvl.d/}, @start_links) ) {<br>
                      #not enabled in all runlevels, return error<br>
                      print "$name not started in runlevel $lvl\n";<br>
                      exit 1;<br>
                  }<br>
              }<br>
              exit 0;<br>
          }<br>
      <br>
          if("is-disabled" eq $act) {<br>
            foreach $lvl (@$defstart_lvls) {<br>
              if ( grep( m{^/etc/rc$lvl.d/}, @start_links) ) {<br>
                print "$name starts in runlevel $lvl, not disabled.\n";<br>
                exit 1;<br>
              }<br>
            }<br>
            exit 0;<br>
          }<br>
      }<br>
      <br>
    </tt>
  </body>
</html>