Which Tool To Automatically Restart Asterisk ?

Home » Asterisk Users » Which Tool To Automatically Restart Asterisk ?
Asterisk Users 9 Comments

Hello,

Years ago, I used Monit to monitor Asterisk and restart it whenever it failed.

Now, I wonder which tool I should pick for an Debian 8 (current) or CentOS
7 (future) environment. The main reason I’m looking for this tool is to avoid as much as possible, current 5 minutes delay between Asterisk’s stop and first cutomers complains.

1. I always install Asterisk from source but I’ve read in Debian Stretch
/etc/defaul/asterisk file, the following:
# RUNASTSAFE: run safe_asterisk rather than asterisk (will auto-restart upon
# crash). This is generally less tested and has some known issues
# with properly starting and stopping Asterisk. Where I can read about those known issues ?
(not found in [1]).

2. For systemd envs where /etc/init.d files are still used, what do you recommend ?

3. For systemd envs where /etc/init.d files are not used anymore, what do you recommend ?

4. Suggestions ?

Regards

[1] https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=asterisk;dist=unstable

9 thoughts on - Which Tool To Automatically Restart Asterisk ?

  • Even if /etc/init.d/ files are still used for other services, asterisk may have a unit file in /etc/systemd/system/

    [Unit]
    Description=Asterisk
    …..

    [Service]
    Restart=on-failure RestartSecs ExecStopPost=-/usr/local/bin/send-some-mail
    …..

  • Hello;

    Over time, we’ve built a huge enterprise level monitoring system for our internal and customer PBX’s. Using Nagios as the core, along with Grafana, Graphite, Carbon, Whisper, etc. so we can also create custom dynamic dashboards, we typically monitor over 1,000 different metrics for each PBX. For something like monitoring a system process like Asterisk, besides just checking to see if the process is running or not, we also check about a dozen or so related metrics like memory and cpu usage. If anything gets out of whack, the system runs the event handler to restart Asterisk. All the plugins are written in Perl, so they’re very easy to modify. What I can do if there is an interest is take the Asterisk plugin, strip out everything that wouldn’t apply to someone not using our system, and make it available to the general public. It’s up to you guys. What do you think? Would people find that useful?

    Regards;

    John V.

    From: asterisk-users-bounces@lists.digium.com [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Olivier Sent: Friday, February 17, 2017 10:39 AM
    To: Asterisk Users Mailing List – Non-Commercial Discussion Subject: [asterisk-users] Which tool to automatically restart Asterisk ?

    Hello,

    Years ago, I used Monit to monitor Asterisk and restart it whenever it failed.

    Now, I wonder which tool I should pick for an Debian 8 (current) or CentOS 7 (future) environment.

    The main reason I’m looking for this tool is to avoid as much as possible, current 5 minutes delay between Asterisk’s stop and first cutomers complains.

    1. I always install Asterisk from source but I’ve read in Debian Stretch /etc/defaul/asterisk file, the following:
    # RUNASTSAFE: run safe_asterisk rather than asterisk (will auto-restart upon
    # crash). This is generally less tested and has some known issues
    # with properly starting and stopping Asterisk.

    Where I can read about those known issues ?

    (not found in [1]).

    2. For systemd envs where /etc/init.d files are still used, what do you recommend ?

    3. For systemd envs where /etc/init.d files are not used anymore, what do you recommend ?

    4. Suggestions ?

    Regards

    [1] https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=asterisk;dist=unstable

  • Hi, Oliver.

    Maybe something like this (add this script to your crontab):

    ————————8<------------------------

  • Both Debian 8 and CentOS 7 have systemd. Systemd gives you this type of monitoring almost for free (see previous reply).

    Using cron is generally not a good idea here:

    1. No way to stop Asterisk when you need it.

    2. If Asterisk has failed, it may take up to a minute to restart it.

  • Sorry , I forget it for another monitoring tool monit that we have used in our production systems to restart asterisk in case of asterisk crash or halt.

    I have attached a monit configuration for your reference. it will work almost in all cases

    This configuration will check Asterisk for following

    1. will check for Asterisk process.
    2. will check Asterisk via AMI
    3. will check Asterisk by sending a SIP request

    You simply need to install monit and place attached file on your server as
    /etc/monit.d/asterisk.conf and then restart monit service daemon

    *Tahir Almas*

    Managing Partner ICT Innovations http://www.ictbroadcast.com http://www.ictinnovations.com Leveraging open source in ICT

  • [snip]

    Some notes regarding the asterisk monit configuration:

    If you use systemd, this ulimit will have no effect: when you restart a service, it is restarted from a separate systemd context (cgroup) and not directly under your own.

    It would generalyl be a good idea not to embed such settings in your scripts and rather put them in a proper configuration file. What happens in you happen to run ‘/etc/init.d/asterisk restart’? It seems that all’s well, until you’re suddenly out of file descriptors.

    Nice.

    Also: what happens when you run ‘core stop now’ from within asterisk?