Hi,
thanks for the responses.
While I agree that the default behavior makes fully sense for most (or nearly all)
modules, still there are usecases where a more tolerant handling would be nice.
In my case, this is a multi-node homer-installation (as advised here:
https://github.com/sipcapture/homer/issues/254 ) - the kamailio (used as
sipcapture-server) uses a local sipcapture database, but all nodes share the same
statistics database (accessed by sqlops) - in case the statistics-DB is not reachable
temporarily during startup, I'd rather keep the sipcapture DB (and lose the
statistics) than blocking startup of kamailio and losing both.
I'm not experienced in kamailio-development, still I tried to implement that
functionality - in
https://github.com/kamailio/kamailio/blob/master/src/modules/sqlops/sqlops.c I changed the
static int child_init(int rank) to always return 0 (regardless of the return-value of
sql_connect() ):
```
static int child_init(int rank)
{
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
return 0;
int sql_result = sql_connect();
LM_INFO("SQL result: %d \n", sql_result);
return 0;
}
```
The effect was, that kamailio starts even if the database is not reachable (and
sql_connect() returns -1):
```
INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1
ERROR: db_postgres [km_pg_con.c:115]: db_postgres_new_connection(): could not connect to
server: Connection refused
ERROR: db_postgres [km_pg_con.c:148]: db_postgres_new_connection(): cleaning up
0x7f858b5d6f88=pkg_free()
ERROR: <core> [db.c:318]: db_do_init2(): could not add connection to the pool
ERROR: sqlops [sql_api.c:164]: sql_connect(): failed to connect to the database [cb]
INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1
INFO: ctl [io_listener.c:210]: io_listen_loop(): io_listen_loop: using epoll_lt as the io
watch method (auto detected)
ERROR: db_postgres [km_pg_con.c:115]: db_postgres_new_connection(): could not connect to
server: Connection refused
ERROR: db_postgres [km_pg_con.c:148]: db_postgres_new_connection(): cleaning up
0x7f858b5d6f88=pkg_free()
ERROR: <core> [db.c:318]: db_do_init2(): could not add connection to the pool
ERROR: sqlops [sql_api.c:164]: sql_connect(): failed to connect to the database [cb]
INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1
INFO: <script>: INSERT INTO stats_ip_mem as stats ( method, source_ip, total)
VALUES('INVITE', ...
ERROR: <core> [db_query.c:176]: db_do_raw_query(): invalid parameter value
ERROR: sqlops [sql_api.c:265]: sql_do_query(): cannot do the query [INSERT INTO
stats_ip_mem as stats ( method, source_ip, total) VA]
```
However, the module does not "recover" if the database gets reachable afterwards
- I still get the error-message
`ERROR: <core> [db_query.c:176]: db_do_raw_query(): invalid parameter value`
for each sql_query in the script.
Can somebod advise my where/when I could trigger the re-connect after the DB comes up
again?
As sqlops does that properly for DB-outages after a successful sql_connect(), I hoped it
would work also in this case - but it seems that this case needs separate handling.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1681#issuecomment-434053799