Difference between revisions of "Asterisk keepalive script"
(Created page with '=Description= Keepalive script sends OPTIONS packets to Asterisk. If Asterisk does not respond to these packets, script consider that Asterisk is not functioning properly and ac…') |
|||
(14 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
=Installation= | =Installation= | ||
rm -fr /usr/src/mor && svn co http://svn.kolmisoft.com/mor/install_script/trunk/ | == X16 == | ||
/usr/src/mor/ | rm -fr /usr/src/mor && svn co http://svn.kolmisoft.com/mor/install_script/trunk/ /usr/src/mor | ||
/usr/src/mor/x16/helpers/asterisk_keep_alive/install.sh | |||
== X17 and later versions == | |||
/usr/src/mor/sh_scripts/asterisk/asterisk_keep_alive/install.sh | |||
After installation, keepalive script will be located here: | After installation, keepalive script will be located here: | ||
Line 13: | Line 17: | ||
/etc/cron.d/asterisk_keep_alive | /etc/cron.d/asterisk_keep_alive | ||
=Configuration= | |||
Before configuring script actions, we recommend to check log file /var/log/mor/mor_asterisk_keep_alive.log | |||
tail -f /var/log/mor/mor_asterisk_keep_alive.log | |||
If file contains lines: | |||
[root@localhost ~]# tail -f /var/log/mor/mor_asterisk_keep_alive.log | |||
2020-02-06 14:31:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 | |||
2020-02-06 14:32:01 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 | |||
2020-02-06 14:33:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 | |||
It means that current script configuration is correct and you can enable actions as described bellow. | |||
If log show actions with WARNING, it means that Asterisk does not respond to OPTION packets | |||
2020-02-06 14:23:18 [WARNING] Ping IP is 192.168.5.5 | |||
2020-02-06 14:23:18 [WARNING] Asterisk did not respond to OPTIONS packets. Trying one more time | |||
2020-02-06 14:23:38 [WARNING] Asterisk did not respond to OPTIONS packets second time | |||
== In MOR X16 == | |||
It either means that Asterisk is down or configuration is incorrect. If Asterisk is running and you see such lines in log, do not set RESTART to 1, as in this case Asterisk will be restarted incorrectly. | |||
You can change/enable actions in script itself. Open script /usr/local/mor/asterisk_keep_alive.sh and change options as documented in script. By default all actions are set to 0 | |||
# 1 - Restart Asterisk, 0 - do not restart Asterisk | # 1 - Restart Asterisk, 0 - do not restart Asterisk | ||
RESTART= | RESTART=0 | ||
# 1 - Generate core dump, 0 - do not generate core dump | # 1 - Generate core dump, 0 - do not generate core dump | ||
GENERATE_CORE_DUMP=0 | GENERATE_CORE_DUMP=0 | ||
# | # 1 - Send email notification, 0 - do not send email notification | ||
# Email is sent using MOR SMPT server details from MOR GUI (if exist) | # Email is sent using MOR SMPT server details from MOR GUI (if exist) | ||
SEND_EMAIL=0 | SEND_EMAIL=0 | ||
Line 30: | Line 52: | ||
# Email address to send notification, taken into account only if SEND_EMAIL = 1 | # Email address to send notification, taken into account only if SEND_EMAIL = 1 | ||
EMAIL_ADDRESS="" | EMAIL_ADDRESS="" | ||
# IP to send OPTION packets | |||
# IF left empty (recommended), 127.0.0.1 will be used if binaddr 0.0.0.0, or bindarr otherwise | |||
PING_IP="" | |||
Text of notification email is within script file. You can alter if needed. | |||
== From MOR X17 == | |||
Asterisk Keep-Alive install script adds these variables to /etc/mor/system.conf | |||
asterisk_keepalive_active = 1 | |||
asterisk_keepalive_restart = 1 | |||
asterisk_keepalive_generate_core_dump = 0 | |||
asterisk_keepalive_send_email = 1 | |||
asterisk_keepalive_email_address = support@kolmisoft.com | |||
asterisk_keepalive_ping_ip = default | |||
asterisk_keepalive_ping_port = 5060 | |||
asterisk_keepalive_ping_attempts = 2 | |||
asterisk_keepalive_ping_timeout = 20 | |||
asterisk_keepalive_vip_check = 1 | |||
asterisk_keepalive_set_cluster_maintenance = 1 | |||
Variables can be edited and changes are reflected instantly, it does not require any reload or restart. | |||
* '''asterisk_keepalive_active''' - controls if the script is executed or not. If set to 0, the script simply exits. Default 1. | |||
* '''asterisk_keepalive_restart''' - controls if Asterisk is restarted if the script detects that Asterisk does not respond to OPTION packets. 1 - Restart, 0 - Do NOT restart. Default 1. | |||
* '''asterisk_keepalive_generate_core_dump''' - controls if the script generates a core dump of Asterisk. 1 - Generate, 0 - Do NOT generate. Default 0. | |||
* '''asterisk_keepalive_send_email''' - control if the script sends an email. 1 - Send email, 0 - Do NOT send email. Default 1. | |||
* '''asterisk_keepalive_email_address''' - email address to send a report. Only checked if asterisk_keepalive_send_email set to 1. Several emails can be set using semicolons, for example, asterisk_keepalive_email_address = person1@email.com;person2@email.com. Default value support@kolmisoft.com | |||
* '''asterisk_keepalive_ping_ip''' - IP to send OPTION packets to. Special value '''default''' means that OPTIONS packets are sent to 127.0.0.1 if bindaddr in /etc/asterisk/sip.conf is set to 0.0.0.0, and to bindaddr IP otherwise. Default is special value '''default'''. | |||
* '''asterisk_keepalive_ping_port''' - Port to send OPTION packets to. The default value is 5060. | |||
* ''' asterisk_keepalive_ping_attempts''' - how many times sent OPTION packets until Asterisk is considered as non-reachable. The default value is 2. | |||
* '''asterisk_keepalive_ping_timeout''' - time in seconds to wait before sending OPTION packets. The default value is 20. | |||
* '''asterisk_keepalive_vip_check''' - if bindaddr is not 0.0.0.0, send OPTION packets only if IP is assigned to the server where the script is running. This prevents situations in floating IP environments, where the script ping IP is assigned to another server, but restarts local Asterisk. The default value is 1. | |||
* '''asterisk_keepalive_set_cluster_maintenance''' - if the script running on the server where pcs (corosync/pacemaker) cluster is running, if this setting is enabled, the cluster is set to maintenance mode just before the restart and maintenance mode is disabled after the restart. If maintenance mode was already enabled, the script does not disable it after Asterisk restarts. The default value is 1. | |||
If the system has an old script version with values embedded in the script itself, the installation script automatically extracts non-default values and correctly adds them to the appropriate settings in the system.conf | |||
= Log = | |||
Asterisk keepalive log is available here: | Asterisk keepalive log is available here: | ||
/var/log/mor/mor_asterisk_keep_alive.log | /var/log/mor/mor_asterisk_keep_alive.log | ||
If Asterisk respond to OPTIONS packets, you will see entries with [NOTICE] like this. | |||
2020-02-06 14:31:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 | |||
If Asterisk does not respond to OPTIONS packets, you will see entries with [WARNING] | |||
2020-02-06 14:23:18 [WARNING] Asterisk did not respond to OPTIONS packets. Trying one more time | |||
= How to disable = | |||
Remove cron: | |||
rm -f /etc/cron.d/asterisk_keep_alive | |||
service crond restart |
Latest revision as of 10:50, 12 December 2024
Description
Keepalive script sends OPTIONS packets to Asterisk. If Asterisk does not respond to these packets, script consider that Asterisk is not functioning properly and acts according to configuration (possible actions are restart asterisk, send email, generate core dump).
Installation
X16
rm -fr /usr/src/mor && svn co http://svn.kolmisoft.com/mor/install_script/trunk/ /usr/src/mor /usr/src/mor/x16/helpers/asterisk_keep_alive/install.sh
X17 and later versions
/usr/src/mor/sh_scripts/asterisk/asterisk_keep_alive/install.sh
After installation, keepalive script will be located here:
/usr/local/mor/asterisk_keep_alive.sh
New cron will be added, which will execute script every minute:
/etc/cron.d/asterisk_keep_alive
Configuration
Before configuring script actions, we recommend to check log file /var/log/mor/mor_asterisk_keep_alive.log
tail -f /var/log/mor/mor_asterisk_keep_alive.log
If file contains lines:
[root@localhost ~]# tail -f /var/log/mor/mor_asterisk_keep_alive.log 2020-02-06 14:31:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 2020-02-06 14:32:01 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1 2020-02-06 14:33:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1
It means that current script configuration is correct and you can enable actions as described bellow.
If log show actions with WARNING, it means that Asterisk does not respond to OPTION packets
2020-02-06 14:23:18 [WARNING] Ping IP is 192.168.5.5 2020-02-06 14:23:18 [WARNING] Asterisk did not respond to OPTIONS packets. Trying one more time 2020-02-06 14:23:38 [WARNING] Asterisk did not respond to OPTIONS packets second time
In MOR X16
It either means that Asterisk is down or configuration is incorrect. If Asterisk is running and you see such lines in log, do not set RESTART to 1, as in this case Asterisk will be restarted incorrectly.
You can change/enable actions in script itself. Open script /usr/local/mor/asterisk_keep_alive.sh and change options as documented in script. By default all actions are set to 0
# 1 - Restart Asterisk, 0 - do not restart Asterisk RESTART=0 # 1 - Generate core dump, 0 - do not generate core dump GENERATE_CORE_DUMP=0 # 1 - Send email notification, 0 - do not send email notification # Email is sent using MOR SMPT server details from MOR GUI (if exist) SEND_EMAIL=0 # Email address to send notification, taken into account only if SEND_EMAIL = 1 EMAIL_ADDRESS="" # IP to send OPTION packets # IF left empty (recommended), 127.0.0.1 will be used if binaddr 0.0.0.0, or bindarr otherwise PING_IP=""
Text of notification email is within script file. You can alter if needed.
From MOR X17
Asterisk Keep-Alive install script adds these variables to /etc/mor/system.conf
asterisk_keepalive_active = 1 asterisk_keepalive_restart = 1 asterisk_keepalive_generate_core_dump = 0 asterisk_keepalive_send_email = 1 asterisk_keepalive_email_address = support@kolmisoft.com asterisk_keepalive_ping_ip = default asterisk_keepalive_ping_port = 5060 asterisk_keepalive_ping_attempts = 2 asterisk_keepalive_ping_timeout = 20 asterisk_keepalive_vip_check = 1 asterisk_keepalive_set_cluster_maintenance = 1
Variables can be edited and changes are reflected instantly, it does not require any reload or restart.
- asterisk_keepalive_active - controls if the script is executed or not. If set to 0, the script simply exits. Default 1.
- asterisk_keepalive_restart - controls if Asterisk is restarted if the script detects that Asterisk does not respond to OPTION packets. 1 - Restart, 0 - Do NOT restart. Default 1.
- asterisk_keepalive_generate_core_dump - controls if the script generates a core dump of Asterisk. 1 - Generate, 0 - Do NOT generate. Default 0.
- asterisk_keepalive_send_email - control if the script sends an email. 1 - Send email, 0 - Do NOT send email. Default 1.
- asterisk_keepalive_email_address - email address to send a report. Only checked if asterisk_keepalive_send_email set to 1. Several emails can be set using semicolons, for example, asterisk_keepalive_email_address = person1@email.com;person2@email.com. Default value support@kolmisoft.com
- asterisk_keepalive_ping_ip - IP to send OPTION packets to. Special value default means that OPTIONS packets are sent to 127.0.0.1 if bindaddr in /etc/asterisk/sip.conf is set to 0.0.0.0, and to bindaddr IP otherwise. Default is special value default.
- asterisk_keepalive_ping_port - Port to send OPTION packets to. The default value is 5060.
- asterisk_keepalive_ping_attempts - how many times sent OPTION packets until Asterisk is considered as non-reachable. The default value is 2.
- asterisk_keepalive_ping_timeout - time in seconds to wait before sending OPTION packets. The default value is 20.
- asterisk_keepalive_vip_check - if bindaddr is not 0.0.0.0, send OPTION packets only if IP is assigned to the server where the script is running. This prevents situations in floating IP environments, where the script ping IP is assigned to another server, but restarts local Asterisk. The default value is 1.
- asterisk_keepalive_set_cluster_maintenance - if the script running on the server where pcs (corosync/pacemaker) cluster is running, if this setting is enabled, the cluster is set to maintenance mode just before the restart and maintenance mode is disabled after the restart. If maintenance mode was already enabled, the script does not disable it after Asterisk restarts. The default value is 1.
If the system has an old script version with values embedded in the script itself, the installation script automatically extracts non-default values and correctly adds them to the appropriate settings in the system.conf
Log
Asterisk keepalive log is available here:
/var/log/mor/mor_asterisk_keep_alive.log
If Asterisk respond to OPTIONS packets, you will see entries with [NOTICE] like this.
2020-02-06 14:31:02 [NOTICE] Asterisk responded to OPTION packets sent to 127.0.0.1
If Asterisk does not respond to OPTIONS packets, you will see entries with [WARNING]
2020-02-06 14:23:18 [WARNING] Asterisk did not respond to OPTIONS packets. Trying one more time
How to disable
Remove cron:
rm -f /etc/cron.d/asterisk_keep_alive service crond restart