#!/bin/sh # # # opensips # # Description: Manages an Opensips as an HA resource # : ${OCF_FUNCTIONS_DIR=/usr/lib/ocf/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### # Fill in some defaults if no values are specified HOSTOS=`uname` OCF_RESKEY_user_default="root" OCF_RESKEY_group_default="root" #OCF_RESKEY_binary_default="opensips" #OCF_RESKEY_canary_binary_default="astcanary" #OCF_RESKEY_config_default="/etc/opensips/opensips.conf" #OCF_RESKEY_additional_parameters_default="-g -vvv" #OCF_RESKEY_realtime_default="false" #OCF_RESKEY_maxfiles_default="8192" #: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} #: ${OCF_RESKEY_canary_binary=${OCF_RESKEY_canary_binary_default}} #: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} #: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} #: ${OCF_RESKEY_group=${OCF_RESKEY_group_default}} #: ${OCF_RESKEY_additional_parameters=${OCF_RESKEY_additional_parameters_default}} #: ${OCF_RESKEY_realtime=${OCF_RESKEY_realtime_default}} #: ${OCF_RESKEY_maxfiles=${OCF_RESKEY_maxfiles_default}} ####################################################################### usage() { cat < 1.0 Resource agent for the opensips May manage an opensips in MOR High Availability Cluster setup Manages an opensips END } # Functions invoked by resource manager actions opensips_validate() { true } opensips_status() { if systemctl is-active --quiet opensips; then return $OCF_SUCCESS else ocf_log info "Opensips is not running" return $OCF_NOT_RUNNING fi } opensips_monitor() { local rc #Check if opensips is running opensips_status rc=$? # If status returned an error, return that immediately if [ $rc -ne $OCF_SUCCESS ]; then return $rc fi # Put any other monitoring logging check here: # Cheeck if not freezed, if respond to sipsak, whatever ocf_log debug "Opensips monitor succeeded" return $OCF_SUCCESS } opensips_start() { local rc if systemctl is-active --quiet opensips; then ocf_log info "Opensips already running" return $OCF_SUCCESS fi systemctl start opensips 2>/dev/null # Spin waiting for the server to come up. # Let the CRM/LRM time us out if required while true; do opensips_monitor rc=$? [ $rc -eq $OCF_SUCCESS ] && break if [ $rc -ne $OCF_NOT_RUNNING ]; then ocf_log err "Opensips start failed" exit $OCF_ERR_GENERIC fi sleep 2 done ocf_log info "Opensips started" return $OCF_SUCCESS } opensips_stop() { local rc opensips_status rc=$? if [ $rc -eq $OCF_NOT_RUNNING ]; then ocf_log info "Opensips already stopped" return $OCF_SUCCESS fi systemctl stop opensips # stop waiting shutdown_timeout=15 if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) fi count=0 while [ $count -lt $shutdown_timeout ]; do opensips_status rc=$? if [ $rc -eq $OCF_NOT_RUNNING ]; then break fi count=`expr $count + 1` sleep 1 ocf_log debug "Opensips still hasn't stopped yet. Waiting ..." done opensips_status rc=$? if [ $rc -ne $OCF_NOT_RUNNING ]; then ocf_log info "Opensis failed to stop after ${shutdown_timeout}s. Trying SIGKILL ..." ocf_run pkill -9 opensips fi ocf_log info "Opensips stopped" return $OCF_SUCCESS } ####################################################################### case "$1" in meta-data) meta_data exit $OCF_SUCCESS;; usage|help) usage exit $OCF_SUCCESS;; esac # Anything except meta-data and help must pass validation opensips_validate || exit $? # What kind of method was invoked? case "$1" in start) opensips_start;; stop) opensips_stop;; status) opensips_status;; monitor) opensips_monitor;; validate-all) ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac