kamailio-tricksWhen Kamailio starts up, it forks into multiple processes and starts executing the routing script for every SIP request and response. Did you know that there is a simple way to execute Kamailio scripts at startup?

Using the htable module

The htable module has an event route that is started as soon as the module is initialized, but before actual message handling begins. Regardless if you use htables, you can use the module for startup items.

An event_route is a special kind of route that is not triggered by messages, it’s triggered by special events. There are a few event_routes in Kamailio modules, and more is added at every release. In Dispatcher, there are event routes that are executed when servers that are monitored become marked inactive and when they come back again.

The htable module implements the table:mod-init event route that you can use like this:

event_route[htable:mod-init] {
xlog("L_INFO", "*** Kamailio starting!\n");

This example will simply add a log entry to your syslog that Kamailio is starting. You can set shared variables, execute external scripts and do the thing this route was meant for – initialize hash tables.

Have fun scripting!