Sip Trunk turns to "Rejected" and only Re-Registers after a reload

Hi, pietervos,

i got some new trunk settings from my provider and had no issues in the past.

But for sure i wrote a Script which checks the connection every minute and reloads asterisk in the case of the state “Rejected”.
Maybe it is a workaround for you.

sudo touch /home/asterisk/reloadlog.txt

sudo nano /home/asterisk/checkregistry.php

add that:

<?php
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
  include_once('/etc/asterisk/freepbx.conf');
}
if($astman->connected()) {
$out = $astman->Command('sip show registry');
echo $out['data'];
if (strpos($out['data'], 'Rejected') !== false) {
echo 'true';
$output = shell_exec('/sbin/fwconsole reload');
echo "<pre>$output</pre>";
file_put_contents("/home/asterisk/reloadlog.txt", (new \DateTime())->format('Y-m-d H:i:s') . "\n", FILE_APPEND);
}


} else {
echo "not asterisk manager connection";
}

Then this commands:

sudo chown asterisk:asterisk /home/asterisk/checkregistry.php
sudo chown asterisk:asterisk /home/asterisk/reloadlog.txt

Then make the cronjob as root user:
If you make the cronjob with the asterisk user, it can happen, that freepbx does not autostart anymore on boot if you use the SNG7 distro!

export VISUAL=nano; crontab -e

add the line:
* * * * * su asterisk -c "/usr/bin/php /home/asterisk/checkregistry.php" >/dev/null 2>&1

This is my workaround in the case that the trunk turns into “rejected”.

Asterisk will reload.

The reloadlog shows you when this happened.

I do not give any warranty for this. Use this at your own risk!!!