A rough idea how this check could look like:
1/ grep for Default-Start and Default-Stop in the LSB header
2/ To check if a service is enabled:
   for i in Default-Start: check if /etc/rc$i.d/S??$service
   for i in Default-Stop: check if /etc/rc$i.d/K??$service
if all of those checks are true, is-enabled returns true
3/ To check if a service is disabled:
   for i in Default-Start: check if exists /etc/rc$i.d/K??$service
   for i in Default-Stop: check if  /etc/rc$i.d/K??$service
if all of those checks are true, is-enabled returns false

otherwise return unknown. I'm not quite sure yet how to map that to
return codes, i.e. if we treat unknown as enabled or disabled. Probably
the latter.

Roger, do you know of a better idea to implement this check? Does that
check work correctly for rcS services?

A few examples:

a/ typical multi-user service: rsyslog
root@pluto:~# grep -E "Default-Start|Default-Stop" /etc/init.d/rsyslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6

root@pluto:~# ls /etc/rc?.d/???rsyslog
/etc/rc0.d/K04rsyslog  /etc/rc1.d/K04rsyslog  /etc/rc2.d/S01rsyslog
/etc/rc3.d/S01rsyslog  /etc/rc4.d/S01rsyslog  /etc/rc5.d/S01rsyslog
/etc/rc6.d/K04rsyslog

root@pluto:~# update-rc.d rsyslog disable
update-rc.d: using dependency based boot sequencing
insserv: warning: current start runlevel(s) (empty) of script `rsyslog'
overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script
`rsyslog' overrides LSB defaults (0 1 6).

root@pluto:~# ls /etc/rc?.d/???rsyslog
/etc/rc0.d/K04rsyslog  /etc/rc1.d/K04rsyslog  /etc/rc2.d/K04rsyslog
/etc/rc3.d/K04rsyslog  /etc/rc4.d/K04rsyslog  /etc/rc5.d/K04rsyslog
/etc/rc6.d/K04rsyslog

b/ rcS-type service: hdparm
root@pluto:~# grep -E "Default-Start|Default-Stop" /etc/init.d/hdparm
# Default-Start:     S
# Default-Stop:

root@pluto:~# ls /etc/rc?.d/???hdparm
/etc/rcS.d/S05hdparm

root@pluto:~# update-rc.d hdparm disable
update-rc.d: using dependency based boot sequencing
insserv: warning: current start runlevel(s) (empty) of script `hdparm'
overrides LSB defaults (S).
insserv: warning: current stop runlevel(s) (S) of script `hdparm'
overrides LSB defaults (empty).

root@pluto:~# ls /etc/rc?.d/???hdparm
/etc/rcS.d/K05hdparm



Michael

-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to