Restart Computer Script, after internet outage?

About a week ago my ISP implemented a new Failover system, this system has not been working properly and causes me to lose connectivity for about 4 seconds every 6 hours, the cable modem itself never goes offline, it all happens on their end on their servers.

Every time it happens I end up with a new IP address.

4 seconds later once I have my internet back, all the computer on my network are able to access websites etc as if it was just really bad lag.

My Asterisk phone system uses Google Voice and Sipgate, for just my family as a Free phone, This has been working great for over a year now, until this little hangup.

The asterisk server never re-registers with sipgate.

The only way I have found to restore functionality is to restart the asterisk machine.

Using the web interface: http://192.168.1.130/maint/index.php?astInfo
I can see:

Sip Peers
Name/username              Host            Dyn Nat ACL Port     Status     
sipgate                    204.155.28.10        N      5060     UNREACHABLE 
702/702                    192.168.1.127    D   N   A  5061     OK (19 ms) 
701/701                    192.168.1.127    D   N   A  5060     OK (12 ms) 
3 sip peers [Monitored: 2 online, 1 offline Unmonitored: 0 online, 0 offline]

701 and 702 are the two phone lines that go through my Linksys PAP2T ATA.

Is there a way to write a script, that every minute or so checks for the sipgate line, and if it says “UNREACHABLE” then restart the machine?

To clarify I am not asking anyone to write the script for me, I know thats asking a to much, I have done coding on plenty of projects in various coding languages but I am pretty unfamiliar with asterisk. So I just need some pointers or references.

Like use X command to check X file for unreachable/offline status, then issue X command to restart asterisk machine. Place script in X location and add X Line to this file to initiate the script.

Rebooting the machine makes no sense at all. See if a ‘service network restart’ fixes it.

Is your machine behind NAT?

Ah SkykingOH, I remember reading over some posts you made on another post.

My setup is Cable Modem --> PFSense Router --> 24port Switch --> Asterisk

my PFSense router uses the default configuration with DHCP, should use NAT I have not disabled it.

I have tried ‘service network restart’ that command issues successfully but does not resolve the Unreachable problem.

I also tried: amportal stop, amportal start, which issues successfully but does not resolve the issue either.

I also tried: ‘service asterisk restart’ this one does not want to work, it outputs:

mpg123: no process killed
Asterisk ended with exit status 1
Asterisk died with code 1
Automatically restarting Asterisk

and it just loops those lines non stop.

I tried all of these things prior to making this post. I was actually trying to resolve this issue on my own without posting for help, but I ran out of things that I knew of to try.

Thank you for your response, and please let me know if you know of anything else I can try. At the moment I manually restart my asterisk computer a few times a day, it is especially important in the afternoon because I have to pick up the kids at school when they call and let me know that their after school activities have ended.

Prior to the changes my ISP made, I could have the Asterisk computer on for a month without a problem, the only time I had to restart it was when there was a power outage or we lost the internet.

Asking for help is not the issue, using a reboot as a troubleshooting step is!

The issue is Asterisk thinks it can’t get to your carrier. So when this is happening can you ping the URL in your trunk from the CentOS command line?

Personally I think that the pfsense is losing the inbound NAT translation.

Are you using any type of dynamic DNS?

Sorry I have not replied sooner, I read your post last night but my ISP had not changed my IP address yet, so there issue was not yet present on my asterisk PC

My asterisk PC now has "sipgate 204.155.28.10 N 5060 UNREACHABLE " again.

I did ping sipgate.com from the CentOS command line and all pings go through no problem with an average of 35 ms

I do not believe I am using a Dynamic DNS.

My Pfsense router does have DNS fields in the general settings, and I have used those fields a few times when our ISP’s DNS server has issues but internet connectivity is otherwise OK, we just set them to the google public DNS.

However currently those DNS fields in Pfsense are blank, which means I should be using my ISP default DNS servers for my ISP. (I normally only use google public DNS when my ISP’s DNS is having issues, once the problem is resolved I clear those fields.)

Thank you for your reply.

SkykingOH, your post saying: Personally I think that the pfsense is losing the inbound NAT translation.

That got me thinking, and I was wondering if theres a way to check that so I started going through all the pages on my pfsense system in the webgui.

on the main status page it shows the state table size “86/324000” and below that number you can click show states, I found the entries for sipgates IP, “204.155.28.10” and removed them, and within 10 seconds my asterisk PC cleared up.

I found a post that seem related to this issue on pfsense forums, Apparently in 2.1 snapshot it will reset states on Gateway IP change, going to give it a shot.

Thank you for your help SkykingOH

http://forum.pfsense.org/index.php/topic,43112.msg289336.html#msg289336