Hi,

New ejabberd ocf script in attach.

Dejan Muhamedagic wrote:
Hi,

On Fri, Nov 07, 2008 at 04:17:58PM +0000, Igor Neves wrote:
Hi,

I'm writing this email to both lists, to let the community know this too. It's possible to add this code with all the other OCF scripts?

Sure. A few notes on the scripts.

Sure, you're welcome, I hope I get some more.

ejabberd:

1.

# * OCF_RESKEY_waitup # * OCF_RESKEY_waitdown
You can remove these two: the best practice is that the RA keeps
trying in a loop and we let the administrator configure timeouts
in the CIB.

Sorry, that waitup and waitdown are not used in the loop time, that it's managed by heartbeat.

This waitup and waitdown it's the time we use in the sleep, before starting the loop. The idea of this two variables, it's to avoid the code getting in the loop, when it's not necessary.

2. In check_ejabberd_running this test is necessary (should be
done in the validate action):

    if [ -f "$EJABBERDCTL" ]; then


I removed that verification and added that to _validate() function.

3. In check_msn_tranport_running the last if-else is not
necessary (superfluous). But you should check if the pid file
exists before kill.


This function "check_msn_transport_running" only signals the process to check it's running, I must do that if-else, because I use the return codes of the function in other parts of the code.

Yes, I have fixed that, I will send the new version.

4. You should invoke _validate for all actions. Move the
meta-data, usage, and help up, so that you have two sets of
actions and validate in between. See other RAs.

Ok, let's see if it's ok now.

5. Not sure, but it looks like the monitor operation is not
correct. Shouldn't it check both ejabberd and the msn_transport?
There's also a typo: search for "tranport".

I think it should, because they are separated process's. If anyone enables msn transport agent, probably he wants to monitor it too.

I changed monitor function to monitor msn transport only if it's enable, this was missing. Sorry.

6. In validate, if the required program's missing (*ctl), you
should exit with OCF_ERR_INSTALLED.

Ok, didn't know that, just fixed, now i use check_binary for everything.

7. Drop the ocf_log info message from validate: it will be
annoying.

Did you use ocf-tester to test the RA?

Yes, without problems.
No time now to check the other RA. Tomorrow probably.

Thanks,

Many thanks for the contribution.

Cheers,

Dejan

My English it's not great, and I'm not a guru, if I make mistake somewhere please tell where, so I can correct.

The OCF script are attached and all have the copyright stuff. If something it's missing about authorizations, please tell me.

Thanks,

--
Igor Neves <[EMAIL PROTECTED]>
3GNTW - Tecnologias de Informa??o, Lda

SIP/JID/MSN: [EMAIL PROTECTED] Mobile Phone: 00351914503611
Local Phone: 00351252377120



#!/bin/sh
#
# CGatePro OCF resource agent
#
# Description:  Manages a CGatePro High-Availability Resource
#
# Author:       Igor Neves  <igor AT 3gnt DOT net>
#                           <neves DOT igor AT gmail DOT com>
# License:      GNU General Public License (GPL)
#
# Copyright:    (C) 2008 3GNTW - Tecnologias de Informacao, Lda
#               All Rights Reserved.
#
# OCF parameters:
#   * OCF_RESKEY_basefolder
#   * OCF_RESKEY_application
#   * OCF_RESKEY_waitdown
#   * OCF_RESKEY_waitup
#   * OCF_RESKEY_supplyparams
#
#################################################################
# Source ocf shell functions
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs

# Variable configuration
#################################################################
# Who much time (in sec) we will wait until check if CGatePro its UP # (default: 10sec)
CGPRO_WAIT_UP="$OCF_RESKEY_waitup"

# Who much time (in sec) we will wait until check if CGatePro its DOWN # (default: 10sec)
CGPRO_WAIT_DOWN="$OCF_RESKEY_waitdown"

# Directory where all the cgpro apps live
APPLICATION="$OCF_RESKEY_application"

# All my data and configuration directory
BASEFOLDER="$OCF_RESKEY_basefolder"

# Extra params
SUPPLPARAMS="$OCF_RESKEY_supplyparams"

# CGPRO lock file
CGATE_LOCK_FILE="/var/lock/subsys/CommuniGate"

#################################################################
# Internal functions

# Check if this use exists, if ok return 0
check_user ()
{
# arg1 should be the username
    ID="$1"
id "$ID" 2>/dev/null
    if [ "$?" = "0" ]; then
        return 0
    else
        return 1
    fi
}

# Check if CGatePro it's running
check_cgpro_lock ()
{
# lets see if there is any lock file
# we should return 1, if there is no lock file
    if [ -f "/var/lock/subsys/CommuniGate" ]; then
        return 0;
    else
        return 1;
    fi
}

# Check if the is any cgpro running
check_cgpro_running ()
{

    if [ -f "/var/CommuniGate/ProcessID" ]; then
        PID=`cat /var/CommuniGate/ProcessID`

        kill -0 $PID 1> /dev/null 2> /dev/null

        if [ "$?" = "0" ]; then
            return 0
        else
            ocf_log info "CGatePro not running, removing old PID file"
            rm -f "/var/CommuniGate/ProcessID"
            return 1
        fi
    else
        return 1
    fi

}

#################################################################
# Main functions

# show how to use this script
_usage () {
cat <<END
usage: $0 {start|stop|status|monitor|meta-data|validate-all}

Expects to have a fully populated OCF RA-compliant environment set.
END
}

# All the verifications we need to do
_validate() {

# verify if exists the binary of cgpro
    if [ ! -f ${APPLICATION}/CommuniGate/CGServer ]; then
        ocf_log err "CommuniGate bin file, was not found in: 
${APPLICATION}/CommuniGate/CGServer"
        exit $OCF_ERR_GENERIC
    fi

# verify if exists base folder, if not create if [ ! -d ${BASEFOLDER} ] ; then
        ocf_log info "We will try to create CGatePRO base folder: ${BASEFOLDER}"

        mkdir ${BASEFOLDER} 2> /dev/null
        if [ "$?" = "0" ]; then
            ocf_log info "Base folder created: ${BASEFOLDER}"

            if check_user "mail"; then
                chgrp mail ${BASEFOLDER}
                chmod 2770 ${BASEFOLDER}
            else
                ocf_log err "Could not find user <mail>, this use should exist to 
get CGatePro running."
                exit $OCF_ERR_GENERIC
            fi
        else
            ocf_log err "Could not create CGatePro base folder, check your 
configurations or data store location."
            exit $OCF_ERR_GENERIC
        fi
    fi

# verify if there is a lock file
    if check_cgpro_lock; then
        ocf_log warn "We found one old lock file, we will remove it: 
/var/lock/subsys/CommuniGate"
        rm -f "$CGATE_LOCK_FILE"
    fi

# if it gets here, everything its ok
    return $OCF_SUCCESS
}

###### start ######
_start() {

# we will now check if there is any cgpro running
    if check_cgpro_running; then
        ocf_log warn "There is already one cgpro running, we will leave it."
    else
# start the daemon
        ${APPLICATION}/CommuniGate/CGServer --Base ${BASEFOLDER} --Daemon 
${SUPPLPARAMS}
    fi

# lets give some time to cgpro to get up
    sleep "$CGPRO_WAIT_UP"

# check if CGatePro its already running, if not, we will wait until it goes up
# we dont need timeout stuff, crm will care of that
    if ! check_cgpro_running; then
        RUNNING=0
        while [ $RUNNING = 0 ]; do
            ocf_log info "CGatePro not running yet, we will wait a litle bit 
more"
            sleep 5
            if check_cgpro_running; then
                RUNNING=1
            fi
        done
    fi
        
# create the lock file for application
    touch $CGATE_LOCK_FILE

# everything went fine
    return $OCF_SUCCESS

}

###### stop ######
_stop() {

# check if CGatePro its already running
    if check_cgpro_running; then
# its running, lets find PID
        CGPRO_PID=""
        if [ -f ${BASEFOLDER}/ProcessID ]; then
            CGPRO_PID=`cat ${BASEFOLDER}/ProcessID`
        else
            CGPRO_PID=`/sbin/pidof CGServer`
        fi

# we have PID, not lets kill it normally
        kill $CGPRO_PID

# lets wait a couple of time, until its down
        sleep $CGPRO_WAIT_DOWN
        
# now lets check if its really down, if not we will wait a couple
# we dont need timeout stuff, crm will care of that
        RUNNING=0
        while [ $RUNNING = 0 ]; do
            ocf_log info "CGatePro still running, we will wait a litle bit more"
            sleep 5
            if ! check_cgpro_running; then
                RUNNING=1
            fi
        done
    else
        ocf_log info "CGatePro not running, nothing to stop"
    fi
        
    rm -f $CGATE_LOCK_FILE

    return $OCF_SUCCESS

}

# Monitor if CGatePro it's running
_monitor() {

# we will check if CGatePro it's running
    if check_cgpro_running; then
        ocf_log info "CGatePro runnning."
        return $OCF_SUCCESS
    else
        ocf_log warn "CGatePro not runnning."
        return $OCF_NOT_RUNNING
    fi

}

# Print metadata informations
_meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="cgatepro">
<version>0.1</version>
<longdesc lang="en">
OCF script that control cgatepro server, in failover scenario
</longdesc>
<shortdesc lang="en">CGatePro server resource script</shortdesc>

<parameters>

<parameter name="basefolder" unique="0" required="1">
<longdesc lang="en">
CGatePro BaseFolder, where all your data and configurations will live
</longdesc>
<shortdesc lang="en">CGatePro BaseFolder</shortdesc>
<content type="string" default="/var/CommuniGate"/>
</parameter>

<parameter name="supplyparams" unique="0" required="1">
<longdesc lang="en">
CGatePro Supply Params argument
</longdesc>
<shortdesc lang="en">cgatepro supplyparams</shortdesc>
<content type="string" default=""/>
</parameter>

<parameter name="application" unique="0" required="1">
<longdesc lang="en">
CGatePro Application Path
</longdesc>
<shortdesc lang="en">cgatepro app path</shortdesc>
<content type="string" default="/opt"/>
</parameter>

<parameter name="waitup" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its UP
</longdesc>
<shortdesc lang="en">Time UP</shortdesc>
<content type="integer" default="10"/>
</parameter>

<parameter name="waitdown" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its DOWN
</longdesc>
<shortdesc lang="en">Time DOWN</shortdesc>
<content type="integer" default="10"/>
</parameter>

</parameters>

<actions>
<action name="start" timeout="60" />
<action name="stop" timeout="60" />
<action name="monitor" timeout="15" interval="300" depth="0"
start-delay="30"/>
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}

# See how we were called
#################################################################

case $1 in

meta-data)
    _meta_data
    exit $OCF_SUCCESS
    ;;
start)
    _validate
    _start
    ;;
stop)
    _stop
    ;;
status|monitor)
    _monitor
    ;;
usage|help)
    _usage
    exit $OCF_SUCCESS
    ;;
validate-all)
    _validate
    ;;
*)
    _usage
    exit $OCF_ERR_UNIMPLEMENTED
    ;;
esac
exit $?

#!/bin/sh
#
# Description:  Manages a ejabberd High-Availability Resource
#
# Author: Igor Neves <igor AT 3gnt DOT net> # <neves DOT igor AT gmail DOT com>
# License:      GNU General Public License (GPL)
#
# Copyright:    (C) 2008 3GNTW - Tecnologias de Informacao, Lda
#               All Rights Reserved.
#
# OCF parameters:
# * OCF_RESKEY_ejabberdctl # * OCF_RESKEY_waitup # * OCF_RESKEY_waitdown # * OCF_RESKEY_msntransportenable
#   * OCF_RESKEY_msntransportpath
#
# IMPORTANT:
# - To make msn transport agent working, I changed the first like # of 'PyMSNt.py' to: '#!/usr/bin/env /usr/bin/python'
#
#################################################################
# Source ocf shell functions
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs

# Variable configuration
#################################################################
# Path to ejabberdctl file
EJABBERDCTL="$OCF_RESKEY_ejabberdctl"

# How much time (in sec) we will wait until check if ejabberd its UP
# (default: 15sec)
EJABBERD_WAIT_UP="$OCF_RESKEY_waitup"

# How much time (in sec) we will wait until check if ejabberd its DOWN
# (default: 15sec)
EJABBERD_WAIT_DOWN="$OCF_RESKEY_waitdown"

# Boolen to enable or disable starting the msn transport
EJABBERD_MSN_TRANS_ENABLE="$OCF_RESKEY_msntransportenable"

# Path to msn transport agent
EJABBERD_MSN_TRANS_PATH="$OCF_RESKEY_msntransportpath"
#################################################################
# Internal functions

# Check if there is any ejabberd running
check_ejabberd_running ()
{

    if [ -f "$EJABBERDCTL" ]; then

        $EJABBERDCTL status 1>/dev/null 2>/dev/null

        if [ "$?" = "0" ]; then
            return 0
        else
            ocf_log info "Ejabberd not running"
            return 1
        fi
    else
        ocf_log err "EjabberdCtl binary not found"
        return 1
    fi

}

# Check if there is any msn transport running
check_msn_tranport_running ()
{
    FILE="`/bin/basename $EJABBERD_MSN_TRANS_PATH .py`.pid"
    PATH="`/usr/bin/dirname $EJABBERD_MSN_TRANS_PATH`"
    PID="`/bin/cat $PATH/$FILE`"

    kill -0 $PID

    if [ "$?" = "0" ]; then
        return 0
    else
        return 1
    fi

}
#################################################################
# Main functions

# show how to use this script
_usage () {
cat <<END
usage: $0 {start|stop|status|monitor|meta-data|validate-all}

Expects to have a fully populated OCF RA-compliant environment set.
END
}

# All the verifications we need to do
_validate() {

# verify if exists the binary of ejabberd
    if [ ! -f "$EJABBERDCTL" ]; then
        ocf_log err "EjabberdCtl, was not found in: $EJABBERDCTL"
        exit $OCF_ERR_GENERIC
    fi

# verify msn transport agent exists if it is enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        if [ ! -f "$EJABBERD_MSN_TRANS_PATH" ]; then
            ocf_log err "Ejabberd msn transport agent enable, but transport agent 
binary not found: $EJABBERD_MSN_TRANS_PATH"
            exit $OCF_ERR_GENERIC
        fi
    else
        ocf_log info "Ejabberd msn transport agent disable."
    fi
# if it gets here, everything its ok
    return $OCF_SUCCESS
}

###### start ######
_start() {

# we will now check if there is any ejabberd running
    if check_ejabberd_running; then
        ocf_log warn "There is already one ejabberd running, we will leave it."
    else
# start the daemon
        ${EJABBERDCTL} start
    fi

# lets give some time to ejabberd to get up
    sleep "$EJABBERD_WAIT_UP"

# check if ejabberd its already running, if not, we will wait until it goes up
# we dont need timeout stuff, crm will care of that
    if ! check_ejabberd_running; then
        RUNNING=0
        while [ $RUNNING = 0 ]; do
            ocf_log info "Ejabberd not running yet, we will wait a litle bit 
more"
            sleep 5
            if check_ejabberd_running; then
                RUNNING=1
            fi
        done
    fi

# Now that ejabberd its running, lets start the transports if enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        if check_msn_tranport_running; then
            ocf_log warn "There is already a transport agent running, we will not 
touch it."
        else
            $EJABBERD_MSN_TRANS_PATH
        fi
    fi

# Everything went fine
    return $OCF_SUCCESS

}

###### stop ######
_stop() {

# check if Ejabberd its already running
    if check_ejabberd_running; then

        $EJABBERDCTL stop 1>/dev/null 2>/dev/null

# lets wait a couple of time, until its down
        sleep $EJABBERD_WAIT_DOWN

        if check_ejabberd_running; then
# its still running, lets find PID and kill the m'fucker
            EJ_PID=`/sbin/pidof beam.smp`

# lets se if we have found any PID
            if [ -n "$EJ_PID"  ]; then
                kill -9 "$EJ_PID"
            fi
        
# now lets check if its really down, if not we will wait a couple
# we dont need timeout stuff, crm will care of that
            RUNNING=0
            while [ $RUNNING = 0 ]; do
                ocf_log info "Ejabberd still running, we will wait a litle bit 
more"
                sleep 5
                if ! check_ejabberd_running; then
                    RUNNING=1
                fi
            done
        fi      
    else
        ocf_log info "Ejabberd not running, nothing to stop"
    fi

# ejabberd its not running anymore, lets stop all the transports if enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        FILE="`/bin/basename $EJABBERD_MSN_TRANS_PATH .py`.pid"
        PATH="`/usr/bin/dirname $EJABBERD_MSN_TRANS_PATH`"
        PID="`/bin/cat $PATH/$FILE`"

        if check_msn_tranport_running; then
            kill -9 $PID
        else
            ocf_log info "No msn transport agent running"
        fi

        if [ "$PATH" -ne "/" ]; then
            rm $PATH/$LOGFILE
        fi
    fi

    return $OCF_SUCCESS
}

# Monitor if Ejabberd it's running
_monitor() {

# we will check if Ejabberd it's running
    if check_ejabberd_running; then
        ocf_log info "Ejabberd runnning."
        return $OCF_SUCCESS
    else
        ocf_log warn "Ejabberd not runnning."
        return $OCF_NOT_RUNNING
    fi

    if check_msn_tranport_running; then
        ocf_log info "Ejabberd msn transport agent runnning."
        return $OCF_SUCCESS
    else
        ocf_log warn "Ejabberd msn transport agent not runnning."
        return $OCF_NOT_RUNNING
    fi
}

# Print metadata informations
_meta_data() {
    cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="ejabberd">
<version>0.1</version>
<longdesc lang="en">
OCF script that control ejabberd server, in failover scenario
</longdesc>
<shortdesc lang="en">Ejabberd server resource script</shortdesc>

<parameters>

<parameter name="ejabberdctl" unique="0" required="1">
<longdesc lang="en">
Ejabberd ctl binary path
</longdesc>
<shortdesc lang="en">EjabberdCtl binary path</shortdesc>
<content type="string" default="/opt/ejabberd/bin/ejabberdctl"/>
</parameter>

<parameter name="waitup" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its UP
</longdesc>
<shortdesc lang="en">Time UP</shortdesc>
<content type="integer" default="15"/>
</parameter>

<parameter name="waitdown" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its DOWN
</longdesc>
<shortdesc lang="en">Time DOWN</shortdesc>
<content type="integer" default="15"/>
</parameter>

<parameter name="msntransportenable" unique="0" required="1">
<longdesc lang="en">
This is a simple boolean value if enable or not the transport agent
</longdesc>
<shortdesc lang="en">Enable or Disable MSN transport agent</shortdesc>
<content type="boolean" default="0"/>
</parameter>

<parameter name="msntransportpath" unique="0" required="1">
<longdesc lang="en">
Path to PyMSNt.py
</longdesc>
<shortdesc lang="en">Path to PyMSNt.py</shortdesc>
<content type="string" default="/opt/pymsnt/PyMSNt.py"/>
</parameter>

</parameters>

<actions>
<action name="start" timeout="30" />
<action name="stop" timeout="30" />
<action name="monitor" timeout="15" interval="300" depth="0"
start-delay="30"/>
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}

# See how we were called
#################################################################

case $1 in

meta-data)
    _meta_data
    exit $OCF_SUCCESS
    ;;
start)
    _validate
    _start
    ;;
stop)
    _stop
    ;;
status|monitor)
    _monitor
    ;;
usage|help)
    _usage
    exit $OCF_SUCCESS
    ;;
validate-all)
    _validate
    ;;
*)
    _usage
    exit $OCF_ERR_UNIMPLEMENTED
    ;;
esac
exit $?

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

--
Igor Neves <[EMAIL PROTECTED]>
3GNTW - Tecnologias de Informação, Lda

SIP/JID/MSN: [EMAIL PROTECTED] Mobile Phone: 00351914503611
Local Phone: 00351252377120


#!/bin/sh
#
# Description:  Manages a ejabberd High-Availability Resource
#
# Author:       Igor Neves  <igor AT 3gnt DOT net> 
#                           <neves DOT igor AT gmail DOT com>
# License:      GNU General Public License (GPL)
#
# Copyright:    (C) 2008 3GNTW - Tecnologias de Informacao, Lda
#               All Rights Reserved.
#
# OCF parameters:
#   * OCF_RESKEY_ejabberdctl 
#   * OCF_RESKEY_waitup 
#   * OCF_RESKEY_waitdown 
#   * OCF_RESKEY_msntransportenable
#   * OCF_RESKEY_msntransportpidfile
#   * OCF_RESKEY_msntransportpath
#
# IMPORTANT:
#   - To make msn transport agent working, I changed the first like 
#   of 'PyMSNt.py' to: '#!/usr/bin/env /usr/bin/python'
#
#################################################################
# Source ocf shell functions
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs

# Variable configuration
#################################################################
# Path to ejabberdctl file
EJABBERDCTL="$OCF_RESKEY_ejabberdctl"

# How much time (in sec) we will wait until check if ejabberd its UP
# (default: 15sec)
EJABBERD_WAIT_UP="$OCF_RESKEY_waitup"

# How much time (in sec) we will wait until check if ejabberd its DOWN
# (default: 15sec)
EJABBERD_WAIT_DOWN="$OCF_RESKEY_waitdown"

# Boolen to enable or disable starting the msn transport
EJABBERD_MSN_TRANS_ENABLE="$OCF_RESKEY_msntransportenable"

# path to msn transport pid file
EJABBERD_MSN_TRANS_PID_FILE="$OCF_RESKEY_msntransportpidfile"

# Path to msn transport agent
EJABBERD_MSN_TRANS_PATH="$OCF_RESKEY_msntransportpath"
#################################################################
# Internal functions

# Check if there is any ejabberd running
check_ejabberd_running ()
{

# lets check status, we dont need to check if EJABBERDCTL exists, 
# we already do that in validate

    $EJABBERDCTL status 1>/dev/null 2>/dev/null

    if [ "$?" = "0" ]; then
        return 0
    else
        ocf_log info "Ejabberd not running"
        return 1
    fi

}

# Check if there is any msn transport running
check_msn_transport_running ()
{
    if [ -f "$EJABBERD_MSN_TRANS_PID_FILE" ]; then
        PID="`cat $EJABBERD_MSN_TRANS_PID_FILE`"
    fi

# if there is no pid, we will assume its not running
    if [ -z "$PID" ]; then
        return 1
    fi

# we just signalize the process, just to check if its running
    kill -0 $PID 1> /dev/null 2> /dev/null

    if [ "$?" = "0" ]; then
        return 0
    else
        return 1
    fi

}
#################################################################
# Main functions

# show how to use this script
_usage () 
{
cat <<END
usage: $0 {start|stop|status|monitor|meta-data|validate-all}

Expects to have a fully populated OCF RA-compliant environment set.
END
}

# All the verifications we need to do
_validate() 
{

# we use this binarys, lets check them
    check_binary cat
    check_binary pidof

# verify if exists the binary of ejabberd
    check_binary $EJABBERDCTL

# verify msn transport agent exists if it is enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        check_binary $EJABBERD_MSN_TRANS_PATH
    fi
    
# if it gets here, everything its ok
    return $OCF_SUCCESS
}

###### start ######
_start() 
{

# we will now check if there is any ejabberd running
    if check_ejabberd_running; then
        ocf_log warn "There is already one ejabberd running, we will leave it."
    else
# start the daemon
        ${EJABBERDCTL} start
    fi

# lets give some time to ejabberd to get up
    sleep "$EJABBERD_WAIT_UP"

# check if ejabberd its already running, if not, we will wait until it goes up
# we dont need timeout stuff, crm will care of that
    if ! check_ejabberd_running; then
        RUNNING=0
        while [ $RUNNING = 0 ]; do
            ocf_log info "Ejabberd not running yet, we will wait a litle bit 
more"
            sleep 5
            if check_ejabberd_running; then
                RUNNING=1
            fi
        done
    fi

# Now that ejabberd its running, lets start the transports if enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        if check_msn_transport_running; then
            ocf_log warn "There is already a transport agent running, we will 
not touch it."
        else
            $EJABBERD_MSN_TRANS_PATH
        fi
    fi

# Everything went fine
    return $OCF_SUCCESS

}

###### stop ######
_stop() 
{

# check if Ejabberd its already running
    if check_ejabberd_running; then

        $EJABBERDCTL stop 1>/dev/null 2>/dev/null

# lets wait a couple of time, until its down
        sleep $EJABBERD_WAIT_DOWN

        if check_ejabberd_running; then
# its still running, lets find PID and kill
            EJ_PID=`pidof beam.smp`

# lets see if we have found any PID
            if [ ! -z "$EJ_PID"  ]; then
                kill -9 "$EJ_PID"
            fi
        
# now lets check if its really down, if not we will wait a couple
# we dont need timeout stuff, crm will care of that
            RUNNING=0
            while [ $RUNNING = 0 ]; do
                ocf_log info "Ejabberd still running, we will wait a litle bit 
more"
                sleep 5
                if ! check_ejabberd_running; then
                    RUNNING=1
                fi
            done
        fi      
    else
        ocf_log info "Ejabberd not running, nothing to stop"
    fi

# ejabberd its not running anymore, lets stop all the transports if enable
    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then

        if [ -f "$EJABBERD_MSN_TRANS_PID_FILE" ]; then
            PID="`cat $EJABBERD_MSN_TRANS_PID_FILE`"
        fi

# if there is no pid, we will assume its not running
        if [ -z "$PID" ]; then
            ocf_log info "no msn transport pid found, should not be running"
        else
            if check_msn_transport_running; then
                kill -9 $PID 1> /dev/null 2> /dev/null
            else
                ocf_log info "No msn transport agent running"
            fi
        fi
# at this state msn transport should be dead already
# lets make sure no pid file is left behind
        if [ "$EJABBERD_MSN_TRANS_PID_FILE" != "/" ]; then
            rm "$EJABBERD_MSN_TRANS_PID_FILE" 1> /dev/null 2> /dev/null
        fi
    fi

    return $OCF_SUCCESS
}

# Monitor if Ejabberd it's running
_monitor() 
{

# we will check if Ejabberd it's running
    if check_ejabberd_running; then
        return $OCF_SUCCESS
    else
        ocf_log warn "Ejabberd not runnning."
        return $OCF_NOT_RUNNING
    fi

    if [ "$EJABBERD_MSN_TRANS_ENABLE" = "1" ]; then
        if check_msn_transport_running; then
            return $OCF_SUCCESS
        else
            ocf_log warn "Ejabberd msn transport agent not runnning."
            return $OCF_NOT_RUNNING
        fi
    fi
}

# Print metadata informations
_meta_data() 
{
    cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="ejabberd">
<version>0.1</version>
<longdesc lang="en">
OCF script that control ejabberd server, in failover scenario
</longdesc>
<shortdesc lang="en">Ejabberd server resource script</shortdesc>

<parameters>

<parameter name="ejabberdctl" unique="0" required="1">
<longdesc lang="en">
Ejabberd ctl binary path
</longdesc>
<shortdesc lang="en">EjabberdCtl binary path</shortdesc>
<content type="string" default="/opt/ejabberd/bin/ejabberdctl"/>
</parameter>

<parameter name="waitup" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its UP
</longdesc>
<shortdesc lang="en">Time UP</shortdesc>
<content type="integer" default="15"/>
</parameter>

<parameter name="waitdown" unique="0" required="1">
<longdesc lang="en">
How much time will this script wait to check if CGatePro its DOWN
</longdesc>
<shortdesc lang="en">Time DOWN</shortdesc>
<content type="integer" default="15"/>
</parameter>

<parameter name="msntransportenable" unique="0" required="1">
<longdesc lang="en">
This is a simple boolean value if enable or not the transport agent
</longdesc>
<shortdesc lang="en">Enable or Disable MSN transport agent</shortdesc>
<content type="boolean" default="0"/>
</parameter>

<parameter name="msntransportpath" unique="0" required="1">
<longdesc lang="en">
Path to PyMSNt.py
</longdesc>
<shortdesc lang="en">Path to PyMSNt.py</shortdesc>
<content type="string" default="/opt/pymsnt/PyMSNt.py"/>
</parameter>

<parameter name="msntransportpidfile" unique="0" required="1">
<longdesc lang="en">
Path to pid file for PyMSNt.py
</longdesc>
<shortdesc lang="en">path to pid file</shortdesc>
<content type="string" default="/opt/pymsnt/PyMSNt.pid"/>
</parameter>


</parameters>

<actions>
<action name="start" timeout="30" />
<action name="stop" timeout="30" />
<action name="monitor" timeout="15" interval="300" depth="0"
start-delay="30"/>
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}

# See how we were called
#################################################################

case $1 in

meta-data)
    _meta_data
    exit $OCF_SUCCESS
    ;;
start)
    _validate
    _start
    ;;
stop)
    _validate
    _stop
    ;;
status|monitor)
    _validate
    _monitor
    ;;
usage|help)
    _usage
    exit $OCF_SUCCESS
    ;;
validate-all)
    _validate
    ;;
*)
    _usage
    exit $OCF_ERR_UNIMPLEMENTED
    ;;
esac
exit $?
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to