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

administration of initscripts



...in debian has been no pleasure for some time now.

Hello readers.


Well the reason i write this, is i found a solution that works for me which i
would like to share with you.

Following goals had been set:
1) Do not clash with existing system tools.
   It is notably that it has even been said on debian-devel, that update-rc.d
   is a API for developers only and not even been considered to be used by
   administrators (search for it).
2) Upgrade of packages shall be handled correctly.
   When a service is disabled, do not reactivate it on package upgrades.

gentoo has a rather nice API for an administrator to handle initscripts s.th. i
always missed in debian. So i modelled this solution somewhat after the gentoo API.


Here are the unvoidable screenshots:

initial situation:
# find /etc/rc[S0-6].d/ -iname '*cups*'
/etc/rc1.d/K01cups
/etc/rc2.d/S18cups
/etc/rc3.d/S18cups
/etc/rc4.d/S18cups
/etc/rc5.d/S18cups

# rc-update cups show
K:01:1:cups
S:18:2 3 4 5:cups

say we want cups deactivated:
# rc-update cups del

# find /etc/rc[S0-6].d/ -iname '*cups*'
/etc/rc1.d/K01cups

# rc-update cups show
K:01:1:cups


At this stage cups is deactivated and since upgrade-rc.d will respect the
existing last link, it will not touch the links on package upgrades.
The stop link has been deliberately put into /etc/rc1.d/ as this is the single
user runlevel in debian.

Say we want cups reactivated:
# rc-update cups add

# find /etc/rc[S0-6].d/ -iname '*cups*'
/etc/rc1.d/K01cups
/etc/rc2.d/S18cups
/etc/rc3.d/S18cups
/etc/rc4.d/S18cups
/etc/rc5.d/S18cups

# rc-update cups show
K:01:1:cups
S:18:2 3 4 5:cups

The nice thing here is, we reuse the LSB headers that are inside of cups script
and therefore the start links are recreated as they had been before!

If you like it here is it:

/-------------------------------------------------------------------------------

_rc-update()
{
    local cur prev words cword
    _init_completion || return

    # don't complete past 2nd token
    [[ $cword -gt 2 ]] && return 0

    if [[ $cword -eq 1 && $prev == ?(*/)rc-update ]]; then
        _services
        [[ -e /etc/mandrake-release ]] && _xinetd_services
    else
        local sysvdirs
        _sysvdirs
        COMPREPLY=( $( compgen -W 'enable disable remove add del show' -- "$cur" ) )
    fi
}
builtin complete -F _rc-update rc-update


rc-update()
{
   case "${2}" in
    enable|add)
	insserv -d "${1}"
	;;

    disable|remove|del)
	insserv -r "${1}"
	insserv -f "${1}",start=,stop=1
	;;

    show)
	insserv -s | \grep -i "${1}"
	;;

    *)
	printf "usage:   rc-update <service> enable|disable|show\n\n"
	printf "enable:  Use default runlevels as defined in the scripts.\n"
	printf "disable: Remove the listed scripts from all runlevels.\n"
	printf "show:    Output runlevel and sequence information of service.\n"
	;;

    esac
}

-------------------------------------------------------------------------------/

As you can see these rc-update() is a wrapper around insserv and _rc-update()
provides tab-completion. Details can be read in insserv(8).

Good night!
-- 
Regards,
Thilo

4096R/0xC70B1A8F
721B 1BA0 095C 1ABA 3FC6  7C18 89A4 A2A0 C70B 1A8F



Reply to: