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

Re: service helper package



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!

> # 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.

> 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.

> # 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.

> # echo an error message and quit
> fatal() {
>     echo " - failed: "

You should get familiar with LSB log function. See lsb-base.

> # 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.

Bye, Jörg.
-- 
Es liegt in der Natur des Menschen, vernünftig zu denken und
unlogisch zu handeln! Das Gesagte ist nicht das Gemeinte und das Gehörte
nicht das Verstandene!



Reply to: