[Asterisk-Users] Check and restart script..
Steven Critchfield
critch at basesys.com
Wed Sep 24 08:30:10 MST 2003
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 at basesys.com>
More information about the asterisk-users
mailing list