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

Re: service helper package



On Mon, 2007-11-26 at 12:32 +0000, Jörg Sommer wrote:
> Hallo C.J.,
> 
> C.J. Adams-Collier <cjcollier@gmail.com> wrote:
> > is there something like a service-common package that provides a helper
> > script like the following for services to source?
> >
> > I'm thinking that it would belong somewhere like
> > /usr/share/service-common/init.sh.  I have not tested the following yet, and
> > I'm a sucky bash programmer.
> 
> Init scripts should not use Bash, they should be Posix Shell scripts!

Sure.. by "bash" I mean "POSIX shell"

> > # Fully qualified paths to required programs
> > START_STOP_DAEMON=/sbin/start-stop-daemon
> > CAT=/bin/cat
> > ECHO=/bin/echo
> 
> Why not use echo and cat? Calling echo this way the shell can't use the
> builtin echo command and must spawn a new process.

Is there a test to determine whether there is a builtin for a given
command?  If so, we could test for that and use it if it exists.
Otherwise, use the fully qualified version

> > if [ -z "$SERVICE_NAME" ] || \
> >    [ -z "$SERVICE_DESC" ] || \
> >    [ -z "$SERVICE_DAEMON" ]; then
> >   fatal( "Environment not configured correctly.\n\tService requires
> > definition of the following variables:\nSERVICE_NAME\nSERVICE_DESC\n
> > SERVICE_DAEMON" )
> > fi
> 
> Why you want to test these values everytime? If the maintainer forgot
> them one time, they are missing everytime.

Maybe they exist one time but get removed before the next run?

> > # We do not want to be affected by PATH tampering.  All calls to
> > # external programs will be fully qualified
> > PATH=""
> 
> You know what you are doing here? PATH is necessary for the daemon to
> find subcommands.

Yep.  I don't want to execute any but the fully qualified commands.
It's a security thing.

> > # echo an error message and quit
> > fatal() {
> >     echo " - failed: "
> 
> You should get familiar with LSB log function. See lsb-base.

I will.  Thanks.

> > # Check whether we were configured to not start the services.
> > check_for_no_start() {
> >     if [ "$SERVICE_DISABLED" = "yes" ]; then
> 
> This is such a broken behavior. Initscripts are enabled and disabled in
> the configuration of the init system.
> 
> IMO there's no need for such a script. Use /etc/init.d/skeleton as a
> template and adapt it to your service.

I agree... but existing scripts use such a beast, so I put it in here.

> Bye, Jörg.

Cheers,

C.J.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: