On 13.11.23 11:17, Benoit Panizzon via sr-users wrote:
Hi
I'm still looking for a better way to tell Kamailio that we want to
enter 'maintenance' and STAY in maintenance after a restart.
Maintenance is: Reject all messages without totag with 503 to prevent
creating new dialogues.
I could use a shared pv and the use kamcmd pv.shvSet to toggle it.
But when kamailio is restarted, that pv is also reset to it's initial
state. Not good, if I want to make sure the node stays in maintenance
mode after a restart as for example after pushing a config change via
ansible.
So what comes to my mind is to check for the presence of a file.
something like:
route[CHECK_MAINTENANCE]
{
if (!has_totag() && is_method("INVITE")) {
if (file_exist("/etc/kamailio/maintenance.flag")) {
xlog("L_ERR", "Maintenance flag present! Rejecting INVITE\n");
t_send_reply("503", "Maintenance mode - no new calls accepted");
exit;
}
}
}
I would really avoid checking/reading a file for every new sip call,
especially on production system with decent volume of calls. But if
suits your needs and system, look at corex module, there is a function
to read the content of a file.
I would rather find a solution where the state is kept in memory, like
still using $shv(...) and change kamailio.cfg to init in maintenance
mode via pv parameter which can set $shv(...) at startup, or using
htable with database backend that loads at startup.
Cheers,
Daniel
--
Daniel-Constantin Mierla (@
asipto.com)
twitter.com/miconda --
linkedin.com/in/miconda
Kamailio Consultancy and Development Services