TIPS Power Failure Bug

Julian

New Member
Joined
Aug 8, 2016
Messages
5
Reaction score
0
Hello all, new member.

I currently run PIAF through VirtualBox off of an Intel NUC. Occasionally in my service area, we do get hit with power outages from time to time. A problem I've seen is that while the VM is starting up, if there is no local internet connection, PIAF will continue its startup, but will not search for an internet connection if there is no initial network connection at startup.

Basically, PIAF in VB will only register trunks and work if it has an initial connection. If PIAF starts up and loses internet connection, it will attempt to reconnect successfully. But if there is no internet connection at the time of startup, it does not bother trying to establish a connection and register the trunks or anything for that matter. A lot of times the NUC will be up and running before our routers are finished with their boot.

I know an obvious suggestion would be to reboot the VM after the connection to the local machine is reestablished. I've even created a batch to delay the start of VB, but is there a better solution for this bug?

Thanks in advance.
 

Julian

New Member
Joined
Aug 8, 2016
Messages
5
Reaction score
0
We have some available but that doesn't address the issue with PIAF not registering
 

islandtech

Wassamassaw
Joined
Jan 11, 2009
Messages
679
Reaction score
137
If the outages don't last for hours at a time and all of your equipment including the ISP interconnect device are on battery backup, whats to restart?
 
Last edited:

atsak

Guru
Joined
Sep 7, 2009
Messages
2,386
Reaction score
440
That is a known issue with Asterisk IIRC. I would fix it by inserting a delay in the startup script (I don't know how to do this but should be googleable somewhere) so it waits a minute or two (or however long your routers/firewall take to boot) during the sequence before it does the service start for asterisk.
 

Julian

New Member
Joined
Aug 8, 2016
Messages
5
Reaction score
0
I've already set a batch to delay the startup and that works fine. But thank you for the input. UPSs are always a good investment.
 

Julian

New Member
Joined
Aug 8, 2016
Messages
5
Reaction score
0
Taking the power issue away, is there a fix to the bug of Asterisk starting without an internet connection and never attempting to search for one after it finishes its startup?
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,634
Reaction score
846
Asterisk is not responsible for configuring your network beyond arranging for NAT traversal through your router(s). If you don't have a static IP for your PBX and your NUC, you REALLY NEED to fix that, the network interface will always be on when you start the machine, whether virtual or real., but if you rely on a DHCP server, presumably on the host machine or higher, is mis-configured then look to your underlying OS and network infrastructure as to why. In fact if any part of your networking doesn't work, it will be with your host (or higher)
 
Last edited:

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
Asterisk is not responsible for the network, but it could certainly handle this scenario more gracefully.

For a work around, I would test for connectivity instead of adding a generic delay, and probably do it inside the VM vs outside.
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,634
Reaction score
846
With respect, that makes no sense, Asterisk merely sends SIP/IAX2/whatever signalling to whatever endpoint, by IP or DNS address is programmed, if the network don't work because of broken routes/DNS/routers not working/etc. than that bit will fail. When it works properly, then the signalling will go through and then the audio, it's as simple as that but as I say if you don't have a static IP it might take longer than you want, it might possibly never work until you restart your lower level network services on every link in the chain to the endpoint.
 
Last edited:

islandtech

Wassamassaw
Joined
Jan 11, 2009
Messages
679
Reaction score
137
I have many small hardware systems using DHCP and on UPS. Never had an internet issue after a building power outage.
 

jerrm

Guru
Joined
Sep 23, 2015
Messages
838
Reaction score
405
With respect, that makes no sense, Asterisk merely sends SIP/IAX2/whatever signalling to whatever endpoint, by IP or DNS address is programmed, if the network don't work because of broken routes/DNS/routers not working/etc. than that bit will fail. When it works properly, then the signalling will go through and then the audio, it's as simple as that but as I say if you don't have a static IP it might take longer than you want, it might possibly never work until you restart your lower level network services on every link in the chain to the endpoint.
Plenty of programs will retry connections. Asterisk handles things pretty well if a connection bounces after startup, it is at initial start that there is an issue. Whether "bug fix" or feature, retrying for some sane amount/interval is a reasonable request.

Step back a decade or two to an old school PBX. Would anyone have accepted a PBX that had to be rebooted if a PRI/T was down on initial boot?
 

dicko

Still learning but earning
Joined
Oct 30, 2015
Messages
1,634
Reaction score
846
There are plenty of "programs" like mon etc. that can be used to monitor and if necessary, restart services when something is broken (it is not necessary to restart asterisk, in effect your legacy PBX with a PRI, it will always be something at a lower network level), it is just not within the purview of asterisk to check whether it can connect to an endpoint before it tries to to connect to that endpoint, if it fails and there is a "next route" (which could easily be a PRI/FXO where no IP network is needed), then it would continue, if they all fail it will terminate the call with an error. If you rely on an internet connection, then rely on something other than asterisk to fix that absence if possible. Does THAT make sense?
 
Last edited:

chris_c_

Active Member
Joined
Aug 19, 2010
Messages
509
Reaction score
67
Taking the power issue away, is there a fix to the bug of Asterisk starting without an internet connection and never attempting to search for one after it finishes its startup?

You could add the following script at startup to check for a valid internet connection.
credit: stackexchange.

When it detects no internet connection, it runs the command amportal restart to restart asterisk and give it another try at connecting.

You could easily change that to wait a second and try again to detect the internet connection, until a valid internet connection is detected, then proceed to start asterisk.

Code:
#!/bin/bash

GW=`/sbin/ip route | awk '/default/ { print $3 }'`
checkdns=`cat /etc/resolv.conf | awk '/nameserver/ {print $2}' | awk 'NR == 1 {print; exit}'`
checkdomain=google.com

#some functions

function portscan
{
  tput setaf 6; echo "Starting port scan of $checkdomain port 80"; tput sgr0;
  if nc -zw1 $checkdomain  80; then
    tput setaf 2; echo "Port scan good, $checkdomain port 80 available"; tput sgr0;
  else
    echo "Port scan of $checkdomain port 80 failed."
  fi
}

function pingnet
{
  #Google has the most reliable host name. Feel free to change it.
  tput setaf 6; echo "Pinging $checkdomain to check for internet connection." && echo; tput sgr0;
  ping $checkdomain -c 4

  if [ $? -eq 0 ]
    then
      tput setaf 2; echo && echo "$checkdomain pingable. Internet connection is most probably available."&& echo ; tput sgr0;
      #Insert any command you like here
    else
      echo && echo "Could not establish internet connection. Something may be wrong here." >&2
      #Insert any command you like here
#      exit 1
  fi
}

function pingdns
{
  #Grab first DNS server from /etc/resolv.conf
  tput setaf 6; echo "Pinging first DNS server in resolv.conf ($checkdns) to check name resolution" && echo; tput sgr0;
  ping $checkdns -c 4
    if [ $? -eq 0 ]
    then
      tput setaf 6; echo && echo "$checkdns pingable. Proceeding with domain check."; tput sgr0;
      #Insert any command you like here
    else
      echo && echo "Could not establish internet connection to DNS. Something may be wrong here." >&2
      #Insert any command you like here
#     exit 1
  fi
}

function httpreq
{
  tput setaf 6; echo && echo "Checking for HTTP Connectivity"; tput sgr0;
  case "$(curl -s --max-time 2 -I $checkdomain | sed 's/^[^ ]*  *\([0-9]\).*/\1/; 1q')" in
  [23]) tput setaf 2; echo "HTTP connectivity is up"; tput sgr0;;
  5) echo "The web proxy won't let us through";exit 1;;
  *)echo "Something is wrong with HTTP connections. Go check it."; exit 1;;
  esac
#  exit 0
}


#Ping gateway first to verify connectivity with LAN
tput setaf 6; echo "Pinging gateway ($GW) to check for LAN connectivity" && echo; tput sgr0;
if [ "$GW" = "" ]; then
    tput setaf 1;echo "There is no gateway. Probably disconnected..."; tput sgr0;
#    exit 1
fi

ping $GW -c 4

if [ $? -eq 0 ]
then
  tput setaf 6; echo && echo "LAN Gateway pingable. Proceeding with internet connectivity check."; tput sgr0;
  pingdns
  pingnet
  portscan
  httpreq
  exit 0
else
  echo && echo "Something is wrong with LAN (Gateway unreachable)"
  pingdns
  pingnet
  portscan
  httpreq

  #Insert any command you like here
amportal restart
#  exit 1
fi
credit 4 stackexchange users:
http://unix.stackexchange.com/quest...proper-way-to-check-for-internet-connectivity
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,202
Reaction score
5,224
Newer Incredible PBX servers always do an amportal restart and iptables-restart as the last two steps in rc.local. That catches about 99% of the problems.
 
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top