Hi, let me reopen this discussion about status code of the init script (kamailio master process which runs daemonized main process).
I'm pretty sure that lot time ago, when I submitted a commit for daemonice.c (including a PIPE to comunicate main process with master process) it did work as expected. This is, if I set a listen address in which my system cannot bind, I got error status code (1) when running kamailio in daemonized mode (/etc/init.d/kamailio start returned error).
Later I know there were some changes about such code, not sure which ones as I didn't inspect them. However thinkgs don't work at all in 3.1.2 (or they work bad, as in Kamailio <= 1.5).
Basically I set a wrong listen address (not a local address), so kamailio fails to start, but the init script returns 0 (OK). This is making crazy my HeartBeat systems. Kamailio logs:
init script return code: ------------------------------------- ~# /etc/init.d/kamailio start ; echo "*** status code: $?"
Starting kamailio: kamailioloading modules under /usr/lib/kamailio/modules_k:/usr/lib/kamailio/modules
Listening on udp: X.X.X.X [X.X.X.X]:5060 tcp: X.X.X.X [X.X.X.X]:5060 Aliases: *: xxxxxx.xxxxxx.xx:* . *** status code: 0 -------------------------------------
kamailio log: ------------------------------------- ERROR: <core> [udp_server.c:400]: ERROR: udp_init: bind(7, 0x8e53f4, 16) on X.X.X.X: Cannot assign requested address ------------------------------------
Could I know which is the expected behaviour (about return codes) in latest version of Kamailio?
Thanks a lot.
2011/6/10 Iñaki Baz Castillo ibc@aliax.net:
init script return code: ------------------------------------- ~# /etc/init.d/kamailio start ; echo "*** status code: $?"
Starting kamailio: kamailioloading modules under /usr/lib/kamailio/modules_k:/usr/lib/kamailio/modules
Listening on udp: X.X.X.X [X.X.X.X]:5060 tcp: X.X.X.X [X.X.X.X]:5060 Aliases: *: xxxxxx.xxxxxx.xx:* . *** status code: 0 -------------------------------------
kamailio log: ------------------------------------- ERROR: <core> [udp_server.c:400]: ERROR: udp_init: bind(7, 0x8e53f4, 16) on X.X.X.X: Cannot assign requested address ------------------------------------
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.
2011/6/10 Iñaki Baz Castillo ibc@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.
2011/6/10 Iñaki Baz Castillo ibc@aliax.net:
2011/6/10 Iñaki Baz Castillo ibc@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.
The problem was present in debian init script for "leeny", "squeeze" and "lucid". However the init script for generic "debian" does the work correctly.
Anyhow I've improved all the deb init scripts to behave correctly:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=cb30...
Regards.