Script to disable/enable trunk?


I am trying to write a shell script to automatically test the reachability of trunks, and to enable/disable the trunks in the FreePBX files.

Basically my script tests for the trunk being available, and then sets the “trunk disabled” flag as follows:

update asterisk.trunks set disabled=‘on’ where trunkid=‘22’;

It then sets the “reload required” flag:
update asterisk.admin set value=‘true’ where variable=“need_reload”;

Finally, outside mysql, I issue the reload command:

/var/lib/asterisk/bin/module_admin reload

This seems to correctly flag the trunks as enabled/disabled, but the asterisk sip configuration files are not regenerated, and a “sip show registry” will still show the disabled trunk.

What additional flags to I need to set to cause the module reload command to regenerate the asterisk sip configurations?


Does anyone with more “development” experience than me have a comment on this?

Why not add your available trunks to a route based on priority and let asterisk handle the fail over?

The problem is that Asterisk dies if a sip trunk is referred to by symbolic name, rather than ip address, and becomes unreachable. There are many threads on this (and other) forums discussing how to mitigate this using a caching DNS server, or a full version of BIND, but I was looking to develop a script just to disable the relevant trunks if they became unavailable.