Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/heartbeat/kamailio.in b/heartbeat/kamailio.in
index 4f6af3dbd..ae890581a 100644
--- a/heartbeat/kamailio.in
+++ b/heartbeat/kamailio.in
@@ -1,741 +1,841 @@
#!@BASH_SHELL@
#
# OCF resource agent for Kamailio for pacemaker
#
# Copyright (c) 2013 FREQUENTIS AG,
# Authors: Stefan Wenk
# Rainer Brestan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
# OCF input parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_conffile
# OCF_RESKEY_pidfile
# OCF_RESKEY_monitoring_ip
# OCF_RESKEY_listen_address
# OCF_RESKEY_port
# OCF_RESKEY_proto
# OCF_RESKEY_sipsak
# OCF_RESKEY_kamctl
# OCF_RESKEY_kamctlrc
# OCF_RESKEY_kamuser
# OCF_RESKEY_kamgroup
# OCF_RESKEY_extra_options
+# OCF_RESKEY_systemd
+# OCF_RESKEY_register
+# OCF_RESKEY_register_array
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
#######################################################################
# Defaults
RESKEY_binary_default="/usr/sbin/kamailio"
RESKEY_conffile_default="/etc/kamailio/kamailio.cfg"
RESKEY_pidfile_default="/var/run/kamailio_${OCF_RESOURCE_INSTANCE}/kamailio.pid"
RESKEY_monitoring_ip_default=127.0.0.1
RESKEY_port_default=5060
RESKEY_proto_default="udptcp"
RESKEY_sipsak_default="/usr/bin/sipsak"
RESKEY_kamctl_default="/usr/bin/kamctl"
RESKEY_kamctlrc_default="/etc/kamailio/kamctlrc"
RESKEY_kamuser_default=""
RESKEY_kamgroup_default=""
RESKEY_extra_options_default=""
+RESKEY_systemd_default=false
+RESKEY_register_default=false
+RESKEY_register_array_default="127.0.0.1;100;test.domain.com;sip1234"
#######################################################################
: ${OCF_RESKEY_binary=${RESKEY_binary_default}}
: ${OCF_RESKEY_conffile=${RESKEY_conffile_default}}
: ${OCF_RESKEY_pidfile=${RESKEY_pidfile_default}}
: ${OCF_RESKEY_monitoring_ip=${RESKEY_monitoring_ip_default}}
: ${OCF_RESKEY_port=${RESKEY_port_default}}
: ${OCF_RESKEY_proto=${RESKEY_proto_default}}
: ${OCF_RESKEY_sipsak=${RESKEY_sipsak_default}}
: ${OCF_RESKEY_kamctl=${RESKEY_kamctl_default}}
: ${OCF_RESKEY_kamctlrc=${RESKEY_kamctlrc_default}}
: ${OCF_RESKEY_kamuser=${RESKEY_kamuser_default}}
: ${OCF_RESKEY_kamgroup=${RESKEY_kamgroup_default}}
: ${OCF_RESKEY_extra_options=${RESKEY_extra_options_default}}
+: ${OCF_RESKEY_systemd=${RESKEY_systemd_default}}
+: ${OCF_RESKEY_register=${RESKEY_register_default}}
+: ${OCF_RESKEY_register_array=${RESKEY_register_array_default}}
#######################################################################
usage() {
cat <<END
usage: $0 {start|stop|status|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="kamailio" version="1.0">
<version>1.0</version>
<longdesc lang="en">
Resource agent for the Kamailio SIP proxy/registrar.
Multiple instances are possible when using following parameter combinations:
Parameters for Kamailio instance 1:
listen_address=192.168.159.128
monitoring_ip=192.168.159.128
proto=udptcp
port=5060
Parameters for Kamailio instance 2:
listen_address=192.168.159.128
monitoring_ip=192.168.159.128
proto=udp
port=5070
conffile=/etc/kamailio/kamailio2.cfg
kamctlrc=""
Only one instance can be monitored via the command "kamctl monitor"
because the kamctl tool of kamailio 4.x is not designed for multiple
instances. Therefore, the provided kamctrlrc file path needs to be
empty for instance 2, 3 ...
Parameters for a third Kamailio instance:
listen_address=192.168.159.128
monitoring_ip=192.168.159.128
proto=tcp
port=5080
conffile=/etc/kamailio/kamailio3.cfg
kamctlrc=""
</longdesc>
<shortdesc lang="en">Resource agent for Kamailio</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">The kamailio binary</longdesc>
<shortdesc lang="en">The kamailio binary</shortdesc>
<content type="string" default="${RESKEY_binary_default}" />
</parameter>
<parameter name="conffile" unique="0" required="0">
<longdesc lang="en">
The kamailio configuration file name with full path.
For example, "/etc/kamailio/kamailio.cfg" , which is the default value.
Make sure to use unique names in case of having multiple instances.
</longdesc>
<shortdesc lang="en">Configuration file name with full path</shortdesc>
<content type="string" default="${RESKEY_conffile_default}" />
</parameter>
<parameter name="pidfile" unique="0" required="0">
<longdesc lang="en">
The kamailio PID file. The directory used must be writable by kamailio
process user. Be sure to use unique name for running more than one
instance. Try to use absolute path names.
If empty, resource agent create a unique directory from the resource
instance name for the PID file and assign it to the process user.
</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="${RESKEY_pidfile_default}" />
</parameter>
<parameter name="monitoring_ip" unique="0" required="0">
<longdesc lang="en">
SIP IP Address of the kamailio instance used for SIP OPTIONS polling monitoring.
Usually the same IP address value as for parameter listen_address should be
provided.
- In order to respond with a 200 OK response to the SIP OOPTION requests,
+ In order to respond with a 200 OK response to the SIP OPTION requests,
the kamailio.cfg file needs to contain following section:
- Note: The following "kamailio.cfg" code snippet is part of an XML section.
+ Note: The following "kamailio.cfg" code snippet is part of an XML section.
Therefore it contains two &amp; characters, which need to be replaced
with two ampersand characters within "kamailio.cfg":
if (is_method("OPTIONS") &amp;&amp; ($ru=~"sip:monitor@.*")) {
##
## If the method is an OPTIONS we are simply going to respond
## with a 200 OK.
# xlog("L_INFO", "Method is an OPTIONS, probably just monitoring\n");
sl_send_reply("200", "Kamailio is alive");
exit;
}
</longdesc>
<shortdesc lang="en">Monitoring IP address used for SIP OPTIONS polling.</shortdesc>
<content type="string" default="${RESKEY_monitoring_ip_default}" />
</parameter>
- <parameter name="listen_address" unique="0" required="1">
+ <parameter name="listen_address" unique="0" required="0">
<longdesc lang="en">
SIP IP address the kamailio will listen on.
</longdesc>
<shortdesc lang="en">Listening SIP address</shortdesc>
<content type="string" />
</parameter>
<parameter name="port" unique="0" required="0">
<longdesc lang="en">
SIP port for the kamailio instance.
</longdesc>
<shortdesc lang="en">SIP Port</shortdesc>
<content type="string" default="${RESKEY_port_default}" />
</parameter>
<parameter name="extra_options" unique="0" required="0">
<longdesc lang="en">
Extra options to add to kamailio start.
</longdesc>
<shortdesc lang="en">extra_options</shortdesc>
<content type="string" default="${RESKEY_extra_options}" />
</parameter>
<parameter name="proto" unique="0" required="0">
<longdesc lang="en">
The protocol used for SIP proto = udp|tcp|udptcp|conf_udp|conf_tcp|conf_udptcp.
Using the options "conf_*" does not add any "-l" parameters to the kamailio command,
the "listen" parameters from kamailio.conf are used instead. The sipsak checks are
performed depending what protocol is defined after the underscore.
</longdesc>
<shortdesc lang="en">protocol</shortdesc>
<content type="string" default="${RESKEY_proto_default}" />
</parameter>
<parameter name="sipsak" unique="0" required="0">
<longdesc lang="en">
The installation path of the sipsak tool, which is used
for monitoring Kamailio via SIP OPTIONS polling.
</longdesc>
<shortdesc lang="en">sipsak path</shortdesc>
<content type="string" default="${RESKEY_sipsak_default}" />
</parameter>
<parameter name="kamctl" unique="0" required="0">
<longdesc lang="en">
The installation path of the "kamctl" control tool.
</longdesc>
<shortdesc lang="en">kamctl path</shortdesc>
<content type="string" default="${RESKEY_kamctl_default}" />
</parameter>
+ <parameter name="systemd" unique="0" required="0">
+ <longdesc lang="en">
+ If systemd is used for management of the Kamailio process, its possible to keep it,
+ setting systemd=true.
+ Consider that in this case, all other parameters are overridden and should be defined
+ inside Kamailio systemd definition, with exception of pidfile and monitoring_ip
+ are used for monitoring and may be defined.
+ </longdesc>
+ <shortdesc lang="en">systemd management</shortdesc>
+ <content type="boolean" default="${RESKEY_systemd_default}" />
+ </parameter>
+
+
<parameter name="kamctlrc" unique="0" required="0">
<longdesc lang="en">
The location of the "kamctlrc" file for the Kamailio instance.
The file "kamctlrc" is the Kamailio configuration file for its "kamctl" control tool.
This parameter only needs to be provided in case of using multiple Kamailio server
instances on a single cluster node:
In case that the parameter "kamctlrc" is not empty, this resource agent monitors
the health state of the Kamailio server via the command "kamctl monitor 1". This
setting is recommended in case of using a single Kamailio server instance.
In case that the parameter "kamctlrc" is empty, the resource agent does not
monitor the health state of the Kamailio server instance via the "kamctl" command.
Please note that the "kamctl" control command of Kamailio 4.x does not support
running multiple Kamailio instances on one host. Nevertheless this resource agent
does allow multiple Kamailio instances per host. The result of the "kamctl"
limitation in terms of number of Kamailio server instances is that the health
check via "kamctl monitor 1" can be configured for a single Kamailio instance
only.
Please refer to the long description of this resource agent for an example
of parameter combinations in case that multiple instances are to be
configured per cluster node.
</longdesc>
<shortdesc lang="en">kamctlrc path</shortdesc>
<content type="string" default="${RESKEY_kamctlrc_default}" />
</parameter>
<parameter name="kamuser" unique="0" required="0">
<longdesc lang="en">
The user account for kamailio process to run with.
Uses the current user, if not specified or empty.
There is no check, if running kamailio with the specified user account is possible.
</longdesc>
<shortdesc lang="en">kamailio user</shortdesc>
<content type="string" default="${RESKEY_kamuser_default}" />
</parameter>
<parameter name="kamgroup" unique="0" required="0">
<longdesc lang="en">
The group for kamailio process to run with.
Uses the current group, if not specified or empty.
</longdesc>
<shortdesc lang="en">kamailio group</shortdesc>
<content type="string" default="${RESKEY_kamgroup_default}" />
</parameter>
+
+ <parameter name="register" unique="0" required="0">
+ <longdesc lang="en">
+ Monitor if kamailio can register an extension. In some cases, kamailio responds to options
+ but is not possible to register an extension. Uses UDP to send the register message.
+ If enabled, use register_array to set the register parameters.
+ </longdesc>
+ <shortdesc lang="en">enable extension register</shortdesc>
+ <content type="string" default="${RESKEY_register_default}" />
+ </parameter>
+
+ <parameter name="register_array" unique="0" required="0">
+ <longdesc lang="en">
+ The extension parameters to use in the registration monitoring. It is possible to set multiple
+ extensions to test.
+ The extensions must be separated by a space (" "), each extension
+ containing the following parameters, separated by a semicolon:
+ Socket IP: The kamailio interface to send the register to (Ex:127.0.0.1);
+ Extension: The extension;
+ Domain: The domain to register the extension;
+ Extension password: The password of the extension;
+ Ex: "127.0.0.1;1000;test.domain.com;sip1234 192.168.0.1;2000;test.domain.com;sip5678"
+ </longdesc>
+ <shortdesc lang="en">register extension</shortdesc>
+ <content type="string" default="${RESKEY_register_array_default}" />
+ </parameter>
</parameters>
<actions>
<action name="start" timeout="60s" />
<action name="stop" timeout="30s" />
<action name="status" timeout="30s" interval="10s" />
<action name="monitor" timeout="30s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="5s" />
<action name="notify" timeout="5s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
#######################################################################
###
#Check if a process with given PID is running
# Parameter 1: PID
###
isRunning_PID()
{
kill -s 0 "$1" > /dev/null 2>&1
}
###
#Check if an instance with given command line is running
# Parameter 1: command line.
###
isRunning_cmd()
{
pkill --signal 0 -f -x "$1" > /dev/null 2>&1
}
###
# Formats the result of a command.
#
# Parameter 1: Exit status.
# Parameter 2: Standard output (stdout).
# Parameter 3: Error output (stderr).
# Returns: Formatted result.
kamailio_format_result() {
local exitstatus="$1"
local value="$2"
local error="$3"
echo -n "exit status: ${exitstatus}"
if [ -n "$value" ]; then
echo -n ", value: ${value}"
fi
if [ -n "$error" ]; then
echo -n ", error: ${error}"
fi
echo
}
###
# Put the command line, how the kamailio process is started according
# to the configured parameters, into the variable "kam_cmd".
###
kamailio_cmd()
{
case ${OCF_RESKEY_proto} in
udp) listen_param="-T -l udp:${OCF_RESKEY_listen_address}:${OCF_RESKEY_port} -l udp:127.0.0.1:${OCF_RESKEY_port}"
;;
tcp) listen_param="-l tcp:${OCF_RESKEY_listen_address}:${OCF_RESKEY_port} -l tcp:127.0.0.1:${OCF_RESKEY_port}"
;;
udptcp) listen_param1="-l udp:${OCF_RESKEY_listen_address}:${OCF_RESKEY_port} -l udp:127.0.0.1:${OCF_RESKEY_port}"
listen_param2="-l tcp:${OCF_RESKEY_listen_address}:${OCF_RESKEY_port} -l tcp:127.0.0.1:${OCF_RESKEY_port}"
listen_param="${listen_param1} ${listen_param2}"
;;
conf_*)
# doing nothing, no listen_param set
;;
*) listen_param="-T"
;;
esac
kam_cmd="${OCF_RESKEY_binary} -P ${OCF_RESKEY_pidfile} -f ${OCF_RESKEY_conffile}"
if [ -n "${listen_param}" ]; then
kam_cmd="${kam_cmd} ${listen_param}"
fi
if [ -n "${OCF_RESKEY_kamuser}" ]; then
kam_cmd="${kam_cmd} -u ${OCF_RESKEY_kamuser}"
fi
if [ -n "${OCF_RESKEY_kamgroup}" ]; then
kam_cmd="${kam_cmd} -g ${OCF_RESKEY_kamgroup}"
fi
if [ -n "${OCF_RESKEY_extra_options}" ]; then
kam_cmd="${kam_cmd} ${OCF_RESKEY_extra_options}"
fi
}
###
# Gets the PID for the running Kamailio instance.
#
# Returns: The variable $PID contains the found PID value or an empty string.
# Exit Status: Zero if the PID file was found and this process run under
# the command line parameters of our instance.
# 1) if the PID file is not present and no process running under
# our command line options is active.
# 2) in all other fatal cases, which we classify in the followig
# as OCF_ERR_genering. These are folloing cases:
# a) The PID file contains a PID value which does no match to
# to our instance
# b) The PID contains a empty string in its first line
# c) The PID file contains some text and some processeses
# from our instance are still active
kamailio_get_pid() {
if [ -f ${OCF_RESKEY_pidfile} ]; then
PID=`head -n 1 $OCF_RESKEY_pidfile`
- if [ ! -z "$PID" ]; then
- #Cross check if the PID file really contains a process of our kamailio instance:
- kamailio_cmd
- CROSSPID=`pgrep -o -f "${kam_cmd}"`
- if [ x"$PID" == x"$CROSSPID" ]; then
- #ocf_log debug "Found kamailio process PID with value: $PID."
- return 0
- fi
- #ocf_log debug "PID file does not contain a PID of a $OCF_RESKEY_binary process!"
+
+ if [ -z "$PID" ]; then
+ #PID file does not contain a valid PID
+ rm -f ${OCF_RESKEY_pidfile}
return 2
fi
- #PID file does not contain a valid PID
- rm -f ${OCF_RESKEY_pidfile}
+ # if systemd is defined, one can not validate our own kamailio instance
+ if [ $OCF_RESKEY_systemd == true ]; then
+ #ocf_log debug "Found kamailio process PID with value: $PID."
+ return 0
+ fi
+
+ #Cross check if the PID file really contains a process of our kamailio instance:
+ kamailio_cmd
+ CROSSPID=`pgrep -o -f "${kam_cmd}"`
+ if [ x"$PID" == x"$CROSSPID" ]; then
+ #ocf_log debug "Found kamailio process PID with value: $PID."
+ return 0
+ fi
+ #ocf_log debug "PID file does not contain a PID of a $OCF_RESKEY_binary process!"
return 2
fi
# No PID file found!
# Check if still a process exists even though we don't have the PID any longer:
kamailio_cmd
pgrep -f "${kam_cmd}"
if [ $? -eq 0 ]; then
ocf_log info "PID file does not contain a valid PID, but kamailio process is still active"
return 2
fi
ocf_log info "No PID file found and our kamailio instance is not active"
return 1
}
kamailio_status() {
local not_running_log_level="warn"
local errorfile error output
if [ "$__OCF_ACTION" = "start" ]; then
not_running_log_level="debug"
fi
kamailio_get_pid >/dev/null
RET=$?
if [ $RET -ne 0 ]; then
if [ $RET -eq 2 ]; then
ocf_log $not_running_log_level "PID file does not contain a PID of a ${OCF_RESKEY_binary} process!"
return $OCF_ERR_GENERIC
fi
return $OCF_NOT_RUNNING
fi
PID=`head -n 1 $OCF_RESKEY_pidfile`
isRunning_PID "$PID"
RET=$?
if [ "$RET" -ne 0 ]; then
ocf_log $not_running_log_level "PID from $PID from ${OCF_RESKEY_pidfile} not running"
rm -f ${OCF_RESKEY_pidfile}
return $OCF_NOT_RUNNING
fi
rc=0
- # In case that OCF_RESKEY_kamctlrc we perfom a health check via "kamctl monitor 1"
+ # In case that OCF_RESKEY_kamctlrc we perform a health check via "kamctl monitor 1"
if [ ! -z ${OCF_RESKEY_kamctlrc} ]; then
# PID is running now but it is not save to check via kamctl without care, because
# the implementation analysis in the case that we kill all running processes
# shows that in case that the fifo cannot be read, then kamctl blocks. This needs
# to be avoided.
# In order to be on the safe side, we run this check therefore under "timeout" control:
rc=1
timeout 3 ${OCF_RESKEY_kamctl} monitor 1 |grep "since" ; rc=$?
fi
if [ $rc -ne 0 ]; then
ocf_log $not_running_log_level "Kamailio is not up according to kamctl monitor!"
return $OCF_NOT_RUNNING
fi
errorfile=`mktemp`
case ${OCF_RESKEY_proto} in
udp) output=`$OCF_RESKEY_sipsak -s sip:monitor@$OCF_RESKEY_monitoring_ip:${OCF_RESKEY_port} -H localhost --transport udp>/dev/null 2>>$errorfile`
result=$?
;;
tcp) output=`$OCF_RESKEY_sipsak -s sip:monitor@$OCF_RESKEY_monitoring_ip:${OCF_RESKEY_port} -H localhost --transport tcp>/dev/null 2>>$errorfile`
result=$?
;;
udptcp) output=`$OCF_RESKEY_sipsak -s sip:monitor@$OCF_RESKEY_monitoring_ip:${OCF_RESKEY_port} -H localhost --transport tcp>/dev/null 2>>$errorfile`
result=$?
if [ $result -eq 0 ]; then
output=`$OCF_RESKEY_sipsak -s sip:monitor@$OCF_RESKEY_monitoring_ip:${OCF_RESKEY_port} -H localhost --transport udp>/dev/null 2>>$errorfile`
result=$?
fi
;;
*) output=`$OCF_RESKEY_sipsak -s sip:monitor@$OCF_RESKEY_monitoring_ip:${OCF_RESKEY_port} -H localhost --transport udp>/dev/null 2>>$errorfile`
result=$?
;;
esac
error=`cat $errorfile`
rm -f $errorfile
if [ $result -ne 0 ]; then
- ocf_log $not_running_log_level "Kamailio is running, but not functional as sipsak ${OCF_RESKEY_proto} failed with $(kamailio_format_result $result "$output" "$error")"
+ ocf_log $not_running_log_level "Kamailio is running, but not functional as sipsak OPTIONS ${OCF_RESKEY_proto} failed with $(kamailio_format_result $result "$output" "$error")"
return $OCF_ERR_GENERIC
fi
+
+ # Checks if it is possible to register an extension.
+ if [ ${OCF_RESKEY_register} == true ]; then
+ # Iterate on the extensions array
+ for extension in ${OCF_RESKEY_register_array[@]}; do
+ # Split the extension parameters into an array:
+ # Ex: "127.0.0.1;100;test.domain.com;sip1234" -> ("127.0.0.1" "100" "test.domain.com" "sip1234")
+ IFS=';' read -ra EXTADDR <<< "$extension"
+ reg_hostname=${EXTADDR[0]}
+ reg_extension=${EXTADDR[1]}
+ reg_domain=${EXTADDR[2]}
+ [[ -z ${EXTADDR[3]} ]] && reg_password="" || reg_password="-a ${EXTADDR[3]}"
+
+ # Builds sipsak usrloc-mode string.
+ reg_forced_timeout="timeout 3"
+ reg_sipsak_opts="-U -d -x 5 -p $reg_hostname -H $reg_hostname"
+ reg_sip_uri="-s sip:$reg_extension@$reg_domain"
+ output=`${reg_forced_timeout} $OCF_RESKEY_sipsak ${reg_sipsak_opts} ${reg_sip_uri} ${reg_password}>/dev/null 2>>$errorfile`
+ result=$?
+
+ error=`cat $errorfile`
+ rm -f $errorfile
+ # If cannot register the extension, raise an OCF_ERR
+ if [ $result -ne 0 ]; then
+ ocf_log $not_running_log_level "Kamailio is running, but not functional as sipsak REGISTER ${OCF_RESKEY_proto} failed with $(kamailio_format_result $result "$output" "$error")"
+ return $OCF_ERR_GENERIC
+ fi
+ echo "RESULT: $result"
+ done
+ fi
return $OCF_SUCCESS
}
kamailio_monitor() {
kamailio_status
}
kamailio_start() {
local errorfile error output piddir
if
kamailio_status
then
ocf_log info "kamailio already running."
return $OCF_SUCCESS
fi
# if pidfile directory does not exist, create it with kamailio process owner
piddir=`dirname "${OCF_RESKEY_pidfile}"`
if [ ! -d "$piddir" ]; then
mkdir -p "$piddir"
if [ "$OCF_RESKEY_kamuser" != "" ]; then
chown ${OCF_RESKEY_kamuser} "$piddir"
fi
fi
- kamailio_cmd
- if [ "$OCF_RESKEY_kamuser" != "" ]; then
- kam_cmd="su -s @BASH_SHELL@ $OCF_RESKEY_kamuser -c \"$kam_cmd\""
- fi
+ if
+ $OCF_RESKEY_systemd
+ then
+ ocf_log info "start kamailio with systemd."
+ systemctl start kamailio
+ result=$?
+ else
+ kamailio_cmd
+ if [ "$OCF_RESKEY_kamuser" != "" ]; then
+ kam_cmd="su -s @BASH_SHELL@ $OCF_RESKEY_kamuser -c \"$kam_cmd\""
+ fi
- ocf_log info "start kamailio with $kam_cmd."
- errorfile=`mktemp`
- output=$(eval ${kam_cmd} 2>>$errorfile)
- result=$?
- error=`cat $errorfile`
- rm -f $errorfile
+ ocf_log info "start kamailio with $kam_cmd."
+ errorfile=`mktemp`
+ output=$(eval ${kam_cmd} 2>>$errorfile)
+ result=$?
+ error=`cat $errorfile`
+ rm -f $errorfile
+ fi
if [ $result -eq 0 ]; then
result=1
while [ $result -ne 0 ]; do
sleep 1
kamailio_get_pid >/dev/null
result=$?
done
ocf_log info "kamailio instance PID=$PID started."
# check with monitor operation if running correctly
result=$OCF_ERR_GENERIC
while [ $result -ne $OCF_SUCCESS ]; do
sleep 1
kamailio_monitor
result=$?
ocf_log info "monitor in start returned $result"
done
ocf_log info "kamailio started successful."
else
ocf_log err "kamailio instance could not be started, $(kamailio_format_result $result "$output" "$error")"
result=$OCF_ERR_GENERIC
fi
return $result
}
kamailio_stop() {
local piddir
local TRIES=0
result=$OCF_SUCCESS
- kamailio_cmd
+ if
+ $OCF_RESKEY_systemd
+ then
+ ocf_log info "stop kamailio with systemd."
+ systemctl stop kamailio
+ else
+ kamailio_cmd
+
+ ocf_log info "Stopping kamailio by sending SIGTERM to ${kam_cmd}"
+ pkill -SIGTERM -x -f "${kam_cmd}"
+ if [ $? -eq 1 ]; then
+ # already stopped. no processes found
+ # in case of not specified pidfile, delete the created directory
+ # otherwise only the pidfile itself
+ if [ "${OCF_RESKEY_pidfile}" == "${RESKEY_pidfile_default}" ]; then
+ piddir=`dirname "${OCF_RESKEY_pidfile}"`
+ rm -rf "$piddir"
+ else
+ rm -f "${OCF_RESKEY_pidfile}"
+ fi
+ return $result
+ fi
- ocf_log info "Stopping kamailio by sending SIGTERM to ${kam_cmd}"
- pkill -SIGTERM -x -f "${kam_cmd}"
- if [ $? -eq 1 ]; then
- # already stopped. no processes found
- # in case of not specified pidfile, delete the created directory
- # otherwise only the pidfile itself
- if [ "${OCF_RESKEY_pidfile}" == "${RESKEY_pidfile_default}" ]; then
- piddir=`dirname "${OCF_RESKEY_pidfile}"`
- rm -rf "$piddir"
+ if [ "$OCF_RESKEY_CRM_meta_timeout" != "" ]; then
+ KAMAILIO_STOP_TIMEOUT=$(( ($OCF_RESKEY_CRM_meta_timeout/1000) - 7 ))
else
- rm -f "${OCF_RESKEY_pidfile}"
+ KAMAILIO_STOP_TIMEOUT=20
fi
- return $result
- fi
- if [ "$OCF_RESKEY_CRM_meta_timeout" != "" ]; then
- KAMAILIO_STOP_TIMEOUT=$(( ($OCF_RESKEY_CRM_meta_timeout/1000) - 7 ))
- else
- KAMAILIO_STOP_TIMEOUT=20
- fi
-
- while isRunning_cmd "${kam_cmd}" && [ "$TRIES" -lt "${KAMAILIO_STOP_TIMEOUT}" ]
- do
- sleep 1
- ocf_log info "kamailio ${kam_cmd} is still running after SIGTERM"
- ((TRIES++))
- done
-
- isRunning_cmd "${kam_cmd}"
- RET=$?
-
- if [ "$RET" -eq 0 ]; then
- ocf_log info "Killing ${kam_cmd} with SIGKILL"
- TRIES=0
- pkill -SIGKILL -x -f "${kam_cmd}" > /dev/null 2>&1
-
- while isRunning_cmd "${kam_cmd}" && [ "$TRIES" -lt 3 ]
+ while isRunning_cmd "${kam_cmd}" && [ "$TRIES" -lt "${KAMAILIO_STOP_TIMEOUT}" ]
do
sleep 1
- ocf_log info "kamailio ${kam_cmd} is still running after SIGKILL"
+ ocf_log info "kamailio ${kam_cmd} is still running after SIGTERM"
((TRIES++))
done
isRunning_cmd "${kam_cmd}"
RET=$?
+
if [ "$RET" -eq 0 ]; then
- ocf_log fatal "kamailio is still running even after SIGKILL"
- result=$OCF_ERR_GENERIC
+ ocf_log info "Killing ${kam_cmd} with SIGKILL"
+ TRIES=0
+ pkill -SIGKILL -x -f "${kam_cmd}" > /dev/null 2>&1
+
+ while isRunning_cmd "${kam_cmd}" && [ "$TRIES" -lt 3 ]
+ do
+ sleep 1
+ ocf_log info "kamailio ${kam_cmd} is still running after SIGKILL"
+ ((TRIES++))
+ done
+
+ isRunning_cmd "${kam_cmd}"
+ RET=$?
+ if [ "$RET" -eq 0 ]; then
+ ocf_log fatal "kamailio is still running even after SIGKILL"
+ result=$OCF_ERR_GENERIC
+ fi
+ else
+ ocf_log info "${kam_cmd} has stopped."
fi
- else
- ocf_log info "${kam_cmd} has stopped."
fi
# in case of not specified pidfile, delete the created directory
# otherwise only the pidfile itself
if [ "${OCF_RESKEY_pidfile}" == "${RESKEY_pidfile_default}" ]; then
piddir=`dirname "${OCF_RESKEY_pidfile}"`
rm -rf "$piddir"
else
rm -f "${OCF_RESKEY_pidfile}"
fi
return $result
}
kamailio_validate_all() {
# Check if kamailio configuration is valid before starting the server
if [ ! -f $OCF_RESKEY_binary ]; then
ocf_log err "File OCF_RESKEY_binary [${OCF_RESKEY_binary}] does not exist!"
return $OCF_NOT_INSTALLED
fi
out=$($OCF_RESKEY_binary -c 2>&1 > /dev/null)
retcode=$?
if [ "$retcode" -ne '0' ]; then
ocf_log info "Not starting kamailio: $OCF_RESKEY_binary does not start!"
return $OCF_ERR_CONFIGURED
fi
case $OCF_RESKEY_monitoring_ip in
"") ocf_log err "Required parameter OCF_RESKEY_monitoring_ip is missing!"
return $OCF_ERR_CONFIGURED
;;
[0-9]*.[0-9]*.[0-9]*.[0-9]*) : OK
;;
*) ocf_log err "Parameter OCF_RESKEY_monitoring_ip [$OCF_RESKEY_monitoring_ip] is not an IP address!"
return $OCF_ERR_CONFIGURED
;;
esac
case $OCF_RESKEY_listen_address in
"") ocf_log err "Required parameter $OCF_RESKEY_listen_address is missing!"
return $OCF_ERR_CONFIGURED
;;
[0-9]*.[0-9]*.[0-9]*.[0-9]*) : OK
;;
*) ocf_log err "Parameter OCF_RESKEY_listen_address [$OCF_RESKEY_listen_address] not an IP address!"
return $OCF_ERR_CONFIGURED
;;
esac
if [ ! -f ${OCF_RESKEY_sipsak} ]; then
ocf_log err "sipsak [${OCF_RESKEY_sipsak}] does not exist!"
return $OCF_NOT_INSTALLED
fi
if [ ! -z ${OCF_RESKEY_kamctlrc} ]; then
if [ ! -f ${OCF_RESKEY_kamctlrc} ]; then
ocf_log err "kamctlrc file [${kamctlrc}] does not exist!"
return $OCF_NOT_INSTALLED
fi
else
ocf_log debug "No monitoring via kamctl monitor because the parameter [kamctlrc] is empty."
fi
if [ ! -f ${OCF_RESKEY_conffile} ]; then
ocf_log err "Kamailio configuration file provided in the parameter conffile [${OCF_RESKEY_conffile}] does not exist!"
return $OCF_ERR_CONFIGURED
fi
case $OCF_RESKEY_proto in
"") ocf_log err "Parameter $OCF_RESKEY_proto is empty!"
return $OCF_ERR_CONFIGURED
;;
udp|tcp|udptcp) : OK
;;
*) ocf_log err "Parameter value $OCF_RESKEY_proto for parameter [proto] not yet supported!"
return $OCF_ERR_CONFIGURED
;;
esac
return $OCF_SUCCESS
}
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
case $__OCF_ACTION in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start|stop|status|monitor)
kamailio_${__OCF_ACTION}
;;
validate-all) kamailio_validate_all
;;
notify) exit $OCF_SUCCESS
;;
usage) usage
exit $OCF_SUCCESS
;;
# reload) #Not supported by Kamailio, but not needed by pacemaker
# ;;
# recover #Not needed by pacemaker
# ;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 5:57 AM (15 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1018273
Default Alt Text
(32 KB)

Event Timeline