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

Re: On init in Debian



On Sun, 18 Mar 2012 00:48:01 +0800, Thomas Goirand <zigo@debian.org> wrote:
> On 03/17/2012 08:40 PM, Philip Hands wrote:
...
> > so the thing that actually gets run is the /etc/rc.common, which sources
> > the init.d script at its end, so it is possible to override any part of
> > the common script by including functions in the service specific script,
> > but otherwise it just does the default.
> >   
> 
> The idea is nice, I think that being able to overwrite the functions
> you want is cool, even though there are many other ways to do it.
> But it seems to be a bit hard to integrate with dh_installinit, Probably,
> what we would like is a symlink to this rc.common,

No, I think you've misunderstood -- the normal script itself
(/etc/init.d/whatever) is run initially, which because of the #! is not
run as a shell script, but instead it runs the rc.common script, which
then uses the script you thought you were running as a configuration
file, by sourcing it at the end of the rc.common.

Maybe it'll be clearer if I paste an edited version of rc.common here:

=-=-=-=-=-=-
#!/bin/sh
# Copyright (C) 2006-2009 OpenWrt.org
                                     
. $IPKG_INSTROOT/etc/functions.sh    
                                 
initscript=$1                    
action=${2:-help}
shift 2          
       
start() {
        return 0
}               
 
stop() {
        return 0
}               
 
restart() {
        trap '' TERM
        stop "$@"
        start "$@"
}                 

...

. "$initscript"                                                      
                                                                     
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
list_contains ALL_COMMANDS "$action" || action=help                                                    
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'                             
$action "$@"                                                                                           
=-=-=-=-=-

so it works out what the script that called it was, and what it was
being asked to do, but because it sources the $initscript, you get the
chance to define your own versions of start() stop() etc.

It's really quite clever, but the main problem with it is that (as you
just found) people tend to misunderstand what's going on, which could
lead to more problems than it solves.  Also, if we were going to try to
get people to change their init scripts, it's probably better to breath
new life into the metainit idea.

Cheers, Phil.
-- 
|)|  Philip Hands [+44 (0)20 8530 9560]    http://www.hands.com/
|-|  HANDS.COM Ltd.                    http://www.uk.debian.org/
|(|  10 Onslow Gardens, South Woodford, London  E18 1NE  ENGLAND

Attachment: pgpzikAitRBSr.pgp
Description: PGP signature


Reply to: