Or better yet use an htable

On Mon, 13 Nov 2023 at 13:31, Henning Westerholt via sr-users <sr-users@lists.kamailio.org> wrote:
Hello,

just to add another common method, you could also just use a cfg file variable that you can modify later with kamcmd, kamcli etc.. There is a prepared variable (pstn..) in the default cfg.

Cheers,

Henning


--
Henning Westerholt - https://skalatan.de/blog/
Kamailio services - https://gilawa.com



> -----Original Message-----
> From: Daniel-Constantin Mierla via sr-users <sr-users@lists.kamailio.org>
> Sent: Montag, 13. November 2023 11:46
> To: Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org>
> Cc: Daniel-Constantin Mierla <miconda@gmail.com>
> Subject: [SR-Users] Re: How to check for presence of a file from a route? (Or
> any other way to tell kamailio not to accept new calls)
>
> 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
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe
> send an email to sr-users-leave@lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the
> sender!
> Edit mailing list options or unsubscribe:
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-leave@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe: