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

How to use lsb init-functions



In trying to convert the initscripts in the "initscripts" package to use
the logging functions in /lib/lsb/init-functions I have run into some
problems.

Currently there are two sets of functions intended to implement the several
kinds of messages normally output by Debian and Ubuntu initscripts.  The
first is for reporting the starting and stopping of services:

    log_daemon_msg "Foo" "bar" ; log_progress_msg "baz" ; log_end_msg 0

    Debian:     Foo: bar baz.

    Ubuntu:     * Foo bar                          [ ok ]

The second is for reporting actions to be taken:

    log_action_msg "Foo"

    Debian:     Foo.

    Ubuntu:     * Foo

The third is for reporting actions to be taken and their completion:

    log_action_begin_msg "Foo" ; log_action_cont_msg "bar" ; log_action_end_msg 0

    Debian:     Foo...bar...done.

    Ubuntu:     * Foo...
                * bar...                           [ ok ]

In addition there is a function for reporting success:

    log_success_msg "Foo"

    Debian:    Foo

    Ubuntu:    * Foo

one for reporting failure:

    log_failure_msg "Foo"

    Debian:    * Foo   [asterisk is red]

    Ubuntu:    * Foo   [asterisk is red]

and a function for warning:

    log_warning_msg "Foo"

    Debian:    * Foo   [asterisk is amber]

    Ubuntu:    * Foo   [asterisk is amber]

Finally there is a log_begin_msg which seems to be obsolete.

Now my question.  Suppose I have a script that does something and I want to do
the following:

    * Report that foo will be done
    * Do foo
    * Report that foo has now been done

I am supposed to do:

    log_action_begin_msg "Will do foo"
    foo
    log_action_end_msg $?

But the problem is that foo may produce output and this will break up the nice
single-line format.  I don't mind deverting stdout to /dev/null, but I am
reluctant to divert stderr to /dev/null and error messages will also break up
formatting:

    Debian:    Foo...ERROR
               failed.   [in red]

    Ubuntu:    * Foo...
               ERROR
                                                      [fail]    [in red]

It seems that in many cases we will have to adopt the following schema:

    log_action_msg "Will do foo"
    if foo ; then log_success_msg "Done foo." ; else log_failure_msg "Foo failed." ; fi

Is this what I should do, or is there another solution I am overlooking; or
do we need more functions; or does the whole system need to be reworked?
-- 
Thomas Hood



Reply to: