Has anyone written a script that can be used as a cron job or similar that will test if Asterisk is running and if not restart it?? I have just had an issue where asterisk crashed and someone was trying to call me.. it would be nice if it could have been automatically restarted.. I was thinking of a simple bash script something like running "ps -aux |grep asterisk" and then some kind of "if" to say that if the result is nothing then execute asterisk.. Problem with that theory is that the "ps" command will show up as well so i will have to work out a way to drop that.. Of course I may be missing a simpler or far better solution so thats why I am asking here first.. Later.. -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze
You can always use the "safe_asterisk" script...it's in the /usr/src directory. That's what I use. Joe -----Original Message----- From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users-admin@lists.digium.com] On Behalf Of WipeOut . Sent: Wednesday, September 24, 2003 11:02 AM To: asterisk-users@lists.digium.com Subject: [Asterisk-Users] Check and restart script.. Has anyone written a script that can be used as a cron job or similar that will test if Asterisk is running and if not restart it?? I have just had an issue where asterisk crashed and someone was trying to call me.. it would be nice if it could have been automatically restarted.. I was thinking of a simple bash script something like running "ps -aux |grep asterisk" and then some kind of "if" to say that if the result is nothing then execute asterisk.. Problem with that theory is that the "ps" command will show up as well so i will have to work out a way to drop that.. Of course I may be missing a simpler or far better solution so thats why I am asking here first.. Later.. -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users
Could you not just add it to your /etc/inittab? -----Original Message----- From: WipeOut . [mailto:wipeout@linuxmail.org] Sent: 24 September 2003 16:02 To: asterisk-users@lists.digium.com Subject: [Asterisk-Users] Check and restart script.. Has anyone written a script that can be used as a cron job or similar that will test if Asterisk is running and if not restart it?? I have just had an issue where asterisk crashed and someone was trying to call me.. it would be nice if it could have been automatically restarted.. I was thinking of a simple bash script something like running "ps -aux |grep asterisk" and then some kind of "if" to say that if the result is nothing then execute asterisk.. Problem with that theory is that the "ps" command will show up as well so i will have to work out a way to drop that.. Of course I may be missing a simpler or far better solution so thats why I am asking here first.. Later.. -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users
Something like this can tell if asterisk is running. You can modify it as needed. Doesn't match the "ps": if [ "A`ps -e | grep asterisk | grep -v grep`" = "A" ]; then echo echo "It's not running" echo else echo echo "It's running" echo fi Scott M. Stingel Emerging Voice Technology Inc. Email: scott@evtmedia.com <mailto:scott@evtmedia.com> URL: www.evtmedia.com <http://www.evtmedia.com>> -----Original Message----- > From: asterisk-users-admin@lists.digium.com > [mailto:asterisk-users-admin@lists.digium.com] On Behalf Of WipeOut . > Sent: Wednesday, September 24, 2003 4:02 PM > To: asterisk-users@lists.digium.com > Subject: [Asterisk-Users] Check and restart script.. > > > Has anyone written a script that can be used as a cron job or > similar that will test if Asterisk is running and if not restart it?? > > I have just had an issue where asterisk crashed and someone > was trying to call me.. it would be nice if it could have > been automatically restarted.. > > I was thinking of a simple bash script something like running > "ps -aux |grep asterisk" and then some kind of "if" to say > that if the result is nothing then execute asterisk.. Problem > with that theory is that the "ps" command will show up as > well so i will have to work out a way to drop that.. > > Of course I may be missing a simpler or far better solution > so thats why I am asking here first.. > > Later.. > -- > ______________________________________________ > http://www.linuxmail.org/ > Now with e-mail forwarding for only US$5.95/yr > > Powered by Outblaze > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > >
On Wed, 2003-09-24 at 10:01, WipeOut . wrote:> Has anyone written a script that can be used as a cron job or similar > that will test if Asterisk is running and if not restart it?? > > I have just had an issue where asterisk crashed and someone was trying > to call me.. it would be nice if it could have been automatically > restarted.. > > I was thinking of a simple bash script something like running "ps -aux > |grep asterisk" and then some kind of "if" to say that if the result > is nothing then execute asterisk.. Problem with that theory is that > the "ps" command will show up as well so i will have to work out a way > to drop that..I'm assuming you are doing something like ps axuwww|grep asterisk If you use a character class on the command line, the command line won't show up, but what your searching for will, ie. ps axuwww|grep [a]sterisk> Of course I may be missing a simpler or far better solution so thats > why I am asking here first..Maybe you should look at init. From the init man page... When starting a new process, init first checks whether the file /etc/initscript exists. If it does, it uses this script to start the process. Each time a child terminates, init records the fact and the reason it died in /var/run/utmp and /var/log/wtmp, provided that these files exist. The first paragraph is important to make sure your modules are loaded at boot time, and the second line is important for debugging the reason why asterisk tripped up. Also init will make sure asterisk is running all the time you are in the appropriate runlevel you have defined. -- Steven Critchfield <critch@basesys.com>
3 ways: 1. in /etc/inittab : d1:23:respawn:/usr/sbin/asterisk -fvvvvv 2. use daemontools from DJB (this is what I use) 3 safe_asterisk (maybe is better this way) :-) WipeOut . wrote:>Has anyone written a script that can be used as a cron job or similar that will test if Asterisk is running and if not restart it?? > >I have just had an issue where asterisk crashed and someone was trying to call me.. it would be nice if it could have been automatically restarted.. > >I was thinking of a simple bash script something like running "ps -aux |grep asterisk" and then some kind of "if" to say that if the result is nothing then execute asterisk.. Problem with that theory is that the "ps" command will show up as well so i will have to work out a way to drop that.. > >Of course I may be missing a simpler or far better solution so thats why I am asking here first.. > >Later.. > >
> Maybe you should look at init. From the init man page... > When starting a new process, init first checks whether the file > /etc/initscript exists. If it does, it uses this script to start the > process. > > Each time a child terminates, init records the fact and the reason it > died in /var/run/utmp and /var/log/wtmp, provided that these files > exist. > > The first paragraph is important to make sure your modules are loaded at > boot time, and the second line is important for debugging the reason why > asterisk tripped up. Also init will make sure asterisk is running all > the time you are in the appropriate runlevel you have defined. >Hi Steven, Would you say init is better than safe_asterisk? or do they both cover the same bases.. Thanks -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze
yes, it is not cron but a daemon. Iactually got the suggestion from this list. You can get all the glory details from: http://cr.yp.to/daemontools.html Dr. Bernstein tools. I have been using it with asterisk successfully for 4 months. Regards, Uriel -----Original Message----- From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users-admin@lists.digium.com]On Behalf Of WipeOut . Sent: Wednesday, September 24, 2003 11:02 AM To: asterisk-users@lists.digium.com Subject: [Asterisk-Users] Check and restart script.. Has anyone written a script that can be used as a cron job or similar that will test if Asterisk is running and if not restart it?? I have just had an issue where asterisk crashed and someone was trying to call me.. it would be nice if it could have been automatically restarted.. I was thinking of a simple bash script something like running "ps -aux |grep asterisk" and then some kind of "if" to say that if the result is nothing then execute asterisk.. Problem with that theory is that the "ps" command will show up as well so i will have to work out a way to drop that.. Of course I may be missing a simpler or far better solution so thats why I am asking here first.. Later.. -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users
> I was thinking of a simple bash script something like running "ps -aux > |grep asterisk" and then some kind of "if" to say that if the result is > nothing then execute asterisk.. Problem with that theory is that the "ps" > command will show up as well so i will have to work out a way to drop > that..Anything particularly wrong with while [ 1 ] ; do /path/to/asterisk -vvvgcf ; sleep 1 ; done ? Stopping it might be a pain but that's easy to add in. I have just this morning run into an asterisk box (phonejack PCI and X100P fxo) which seemed to forget about the FXS port entirely. It was otherwise up and running fine, but had to be restarted. I bypassed the asterisk box for the day so my wife wouldn't have to put up with spotty phone service. :-) Regards, Andrew
>...verify that all FXS/FXO/IAX2?/SIP/H323 > processess are running normally? >Now that would be nice but I don't think it would be that easy to do.. Later.. -- ______________________________________________ http://www.linuxmail.org/ Now with e-mail forwarding for only US$5.95/yr Powered by Outblaze
> -----Original Message----- > From: Garry Adkins [mailto:gpa2@netacs.net] > > I agree... As a unix support person at work, I find that I have towrite> these types of watchdogs often... Sometimes an application willpartially> fail, or fail but not exit, ending up as some zombie. (I've tried the > ps -auxw, and it's not smart enough to see a program has hung... andyour> load average is now about 80...)A good, no, excellent, monitoring system is Nagios (www.nagios.org). It uses the concepts of plugins to monitor 'OK', 'WARNING' and 'CRITICAL' states. A variety of plugin's for * could monitor the main process, loop back inside of * (via AGI), grep of /var/log/asterisk/messages for channel errors, etc. Nagios can also use event handlers to do things such as restarting processes (*). You're points make sense Garry, and are appreciated. Methods for monitoring the health of * is something to do once I integrate * into our production facility for out-calling of alerts using festival. Until then, I'll rely upon our organic monitoring system, the users. :) Regards, --- Gavin