[sr-dev] Again about return code when start action fails

Iñaki Baz Castillo ibc at aliax.net
Fri Jun 10 14:58:03 CEST 2011


2011/6/10 Iñaki Baz Castillo <ibc at aliax.net>:
> Ok, it's not a problem in kamailio code, but just in the kamailio init
> script. It fails and always return 0. I will inspect it.

I've found the problem. The init script is as follows:

---------------------
set -e

[...]

case "$1" in
  start|debug)
        [...]

        echo -n "Starting $DESC: $NAME"
        start-stop-daemon --start --quiet --pidfile $PIDFILE \
                --exec $DAEMON -- $OPTIONS || echo -n " already running"
        echo "."
        ;;
---------------------

It's very wrong:

- It does not use --oknodo option, so in case the daemon is already
running the method return 1 and "echo 'already running'" is printed.
So finally it retuns 0 (OK). Yes, it seems correct but...

- In case start-stop-daemon returns error (!= 0) due to a *real*
error, then "already running" is also printed so 0 returned. Wrong.


Solution (I will improve it a bit more and commit it soon):

        echo -n "Starting $DESC: $NAME"
        start-stop-daemon --oknodo --start --quiet --pidfile $PIDFILE \
                --exec $DAEMON -- $OPTIONS
        echo "."
        ;;


To check wheter kamailio is running, we can test it before trying to
start it with start-stop-daemon, so it could print "already running"
and return 0. But with my change, status codes are ok.




-- 
Iñaki Baz Castillo
<ibc at aliax.net>



More information about the sr-dev mailing list