Hi, I've submitted some patches to the SR tracker in order to improve
something that I consider buggy (and for sure it is):
http://sip-router.org/tracker/index.php?do=details&task_id=66
As explained in the tracker, in daemonize mode kamailio doesn't return
the proper status code. If for example the listen address is not local
or a DB connection uses an invalid password, then the command
"kamailio" would return 0 (OK) anyway (even if it fails to start).
This occurs because all those checking (socket, DB connections...) are
performed *after* invoking daemonize() so the parent process (which
could be invoked by "/etc/init.d/kamailio start") returns 0 knowing
nothing about those errors. In fact the only checking done before
daemonizing is the config file parsing.
The patches I've upload to the tracker improve/fix it by doing the following:
- 'daemonize()' function doesn't exit the parent process, instead the
parent process gets blocked in 'main()' function reading a pipe.
- When the main process initializes the modules, sockets and so, it
writes into the pipe so the parent process exists with 0.
- If the main process fails to start then the pipe write fd is closed
with no more processes writting into it so the parent process detects
it and exists with -1 error.
I've checked it and works ok. You can try to set a wrong MySQL
password or a wrong listen address and run kamailio in daemonize mode.
Check the exit status so you will get error code rather than 0 (as
occurs without these changes).
This is strongly required when working with HeartBeat (and any other
software managing daemons) because HeartBeat relies on the init script
returned status codes.
Imagine for example that a MySQL password is changed. For any reason
HeartBeat decides to change the service to nodo-2. This is what would
happen without the proposed changes:
- HeartBeat invokes "/etc/init.d/kamailio start".
- It returns 0 even if it fails to start due to MySQL password.
- HeartBeat invokes periodically "/etc/init.d/kamailio monitor"
(similar to "status") which would return 1 (it's not running).
- Then HeartBeat tries to start it again. And of course, it receives 0 again.
- Loop...
This is, a init script return codes are *important* and current
SR/Kamailio doesn't do it well as it fails in daemonize mode.
I will use these patches in production very soon as I'm building some
platforms of Kamailio+HeartBeat and this is really required. If
somebody could review than patches it should be great.
Regards.
--
Iñaki Baz Castillo
<ibc(a)aliax.net>