Friday, August 27, 2010

Watchdog Script for the Linux Processes (Asterisk)

1. Create a script file. Let's say astSvcControl.sh at /root

#!/bin/bash
#script file: astSvcControl.sh

PROCESS="asterisk"

PROCCHK=$(ps aux|grep -c $PROCESS)
if [ $PROCCHK -eq 1 ]
then
/usr/sbin/asterisk
echo "Started Asterisk Service at $(date)" >> /var/log/asterisk/asterisk-check.log
else
echo "$PROCESS is running $PROCCHK processes" >> /var/log/asterisk/asterisk-check.log
fi

[Note: In SuSE linux, ps aux|grep -c < process name > returns 1 if the process is not running and returns 2 or more if the process is running
In SuSE linux, grep
< process name > also returns grep < process name > as one of the process, thus it always returns 1
But some flavors of linux, it returns 0 if the process is not running and returns 1 or more if the process is running
]
2. Make sure that script is executable

#chmod 770 astSvcControl.sh

3. Run the script periodically using cronjobs

#crontab -e
* * * * * bash /root/astSvcControl.sh

(run every minute)


If you want to run the script every 5 mintutes , do this

#crontab -e
*/5 * * * * bash /root/astSvcControl.sh



More on cronjobs for Linux/Unix:
http://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/
http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/

Wednesday, August 11, 2010

Asterisk PRI Trunk Group customization - Top-Down/Bottom-Up Hunting

A glare condition is quite often issue, if the PRIs at PBX and CO is not configured properly for outbound/inbound calls to hunt the B channels.

You might be wondering, what the hell is 'a glare condition'?

A glare condition is the situation when the when a outbound call finds a clear channel and a new inbound call arrives at the very same instant, the inbound call wins, the outbound call gets "all circuts are busy"or vice versa.

So, how to fix it?

Let's say we have 23 channel PRI with D channel - 24. Telco is sending the inbound calls to hunt from channel 1 -> 23. So, I need to set outbound calls to hunt from channel 23 -> 1 to avoid the Channel Busy before ANY possibility of call collision.

How can I do that in Asterisk?

You specify which of four methods the Zap channel module is to use to select a non-busy channel from the channel group by prefixing the group number with one of the letters g, G, r, or R:
g: select the lowest-numbered non-busy Zap channel (aka. ascending sequential hunt group).
G: select the highest-numbered non-busy Zap channel (aka. descending sequential hunt group).
r: use a round-robin search, starting at the next highest channel than last time (aka. ascending rotary hunt group).
R: use a round-robin search, starting at the next lowest channel than last time (aka. descending rotary hunt group). [/color]

Create a new ZAP trunk and specify G0 as the trunk ID, go to your outbound routes. replace any routes calling for the trunk g0 and replace with new trunk G0. Go back and delete the g0 trunk so it will not be accidently selected as it is going to be the first trunk in the pull down list.