[OpenSIPS-Users] opensips HA resource script (for Heartbeat)

Duane Larson duane.larson at gmail.com
Tue Dec 28 03:24:35 CET 2010


I am using the following attached resource with "OK" success.  I was having
some weird issues when restarting or moving the resource to another server
and it sounds like those issues might have something to do with what Inaki
was talking about.

So if OpenSIPS always returns 0 how are people making it redundant?  Monit
is very good but if you need OpenSIPS to use a Clustered IP address you
really need to use HA.




On Mon, Dec 27, 2010 at 7:55 PM, Iñaki Baz Castillo <ibc at aliax.net> wrote:

> 2010/12/22 Alexandr A. Alexandrov <shurrman at gmail.com>:
> > Does anyone by chance have opensips HA resource script (for using with
> > Heartbeat)?
>
> OpenSIPS is not good for init scripts as when running daemonized it
> returns 0 (ok) even if it fails to start (due to DB wrong connection
> or whatever module error).
>
> So HA would start OpenSIPS. The OpenSIPs init script (or HA LSB / OCF
> script) returns 0, but the fact is that the daemonized (forked)
> process has failed to start (i.e. any module error).
>
> Later HA monitors OpenSIPS status (by using the LSB script "status"
> action or the OCF script "monitor" action) and realizes that OpenSIPS
> is not running. Then HA tries to start it again, such action returns 0
> again (the script returns 0 as there are not grammar errors in the
> config script) so HA is happy, but again, OpenSIPS is not running, and
> so on.
>
> This makes OpenSIPS not valid for full HA environment, so be careful.
>
> --
> Iñaki Baz Castillo
> <ibc at aliax.net>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>



-- 
--
*--*--*--*--*--*
Duane
*--*--*--*--*--*
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20101227/f2d24394/attachment.htm>
-------------- next part --------------
#!/bin/sh

# Initialization:

. /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs

usage() {
cat <<-!
usage: $0 {start|stop|status|monitor|meta-data|validate-all}
!
}

meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="OpenSIPS">
<version>1.0</version>

<longdesc lang="en">
Resource Agent for the OpenSIPS SIP Proxy.
</longdesc>
<shortdesc lang="en">OpenSIPS resource agent</shortdesc>

<parameters>
<parameter name="ip" unique="0" required="1">
<longdesc lang="en">
IP Address of the OpenSIPS Instance. This is only used for monitoring.
</longdesc>
<shortdesc lang="en">IP Address</shortdesc>
<content type="string" default="" />
</parameter>

<parameter name="port" unique="0" required="1">
<longdesc lang="en">
Port of the OpenSIPS Instance. This is only used for monitoring.
</longdesc>
<shortdesc lang="en">Port</shortdesc>
<content type="string" default="5060" />
</parameter>
</parameters>

<actions>
<action name="start" timeout="60" />
<action name="stop" timeout="60" />
<action name="status" depth="0" timeout="30" interval="10" start-delay="60" />
<action name="monitor" depth="0" timeout="30" interval="10" start-delay="60" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="5" />
<action name="notify" timeout="5" />
<action name="promote" timeout="5" />
<action name="demote" timeout="5" />
</actions>
</resource-agent>
END
}

OpenSIPS_Status() {
/usr/bin/sipsak -s sip:LVSHeartbeatcheck@$OCF_RESKEY_ip -H 127.0.0.1 2>/dev/null >/dev/null
rc=$?
if
[ $rc -ne 0 ]
then
echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_STATUS(): RC [$rc] is not equal to 0" >> /var/log/syslog
return $OCF_NOT_RUNNING
else 
echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_STATUS(): RC [$rc] is equal to 0" >> /var/log/syslog
return $OCF_SUCCESS
fi
}

OpenSIPS_Monitor( ) {
echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Monitor(): Called" >> /var/log/syslog
OpenSIPS_Status
}

OpenSIPS_Start( ) {
        if
                OpenSIPS_Status
                then
                        ocf_log info "OpenSIPS already running."
                        echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Start(): OpenSIPS is already running" >> /var/log/syslog
                        return $OCF_SUCCESS
                else
                        /etc/init.d/opensips start >/dev/null
                        rc=$?
                if [ $rc -ne 0 ]
                then
                        echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Start(): RC [$rc] is not equal to 0 and we couldn't start OpenSIPS" >> /var/log/syslog
                        return $OCF_ERR_PERM
                else 
                        echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Start(): RC [$rc] is equal to 0 and we started OpenSIPS" >> /var/log/syslog
                        return $OCF_SUCCESS
                fi
        fi 
}

OpenSIPS_Stop( ) {
echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Stop(): About to stop OpenSIPS" >> /var/log/syslog
/etc/init.d/opensips stop >/dev/null
echo -e "`date +"%b %e %H:%M:%S"` OpenSIPS_Stop(): Just stopped OpenSIPS" >> /var/log/syslog 
return $OCF_SUCCESS
}

OpenSIPS_Validate_All( ) {
return $OCF_SUCCESS
}

if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi

case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) OpenSIPS_Start
;;
stop) OpenSIPS_Stop
;;
monitor) OpenSIPS_Monitor
;;
status) OpenSIPS_Status
;;
validate-all) OpenSIPS_Validate_All
;;
notify) exit $OCF_SUCCESS
;;
promote) exit $OCF_SUCCESS
;;
demote) exit $OCF_SUCCESS
;;
usage) usage
exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_ARGS
;;
esac
exit $?


More information about the Users mailing list