qpage Resource Agent

This script is used for the alphapager software, qpage. When used with Heartbeat Version 2, it provides monitoring of the qpage daemon.

code_script: 
#!/bin/bash
#
#      qpage Resource Agent (RA) for Heartbeat.
#      Copyright (c) 2007 Ingrafted Software Inc., Dave Augustus
#                    All Rights Reserved.
#
# 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.
#
#
# Startup for qpage
#
# OCF parameters:
#  OCF_RESKEY_binary
#  OCF_RESKEY_config
#  OCF_RESKEY_pidfile

HA_VARRUNDIR=${HA_VARRUN}

. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs

# Fill in some defaults if no values are specified
: ${OCF_RESKEY_binary="/usr/local/bin/qpage"}
: ${OCF_RESKEY_config="/etc/qpage.cf"}
: ${OCF_RESKEY_pidfile="/var/run/qpage.pid"}

# Source function library.
. /etc/rc.d/init.d/functions

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

<longdesc lang="en">
This is a qpage Resource Agent.
</longdesc>
<shortdesc lang="en">qpage Resource Agent</shortdesc>

<parameters>
<parameter name="state" unique="1">
<longdesc lang="en">
Location to store the resource state in.
</longdesc>
<shortdesc lang="en">State file</shortdesc>
<content type="string" default="${HA_RSCTMP}/qpage-{OCF_RESOURCE_INSTANCE}.state" />
</parameter>

</parameters>

<actions>
<action name="start"        timeout="90" />
<action name="stop"         timeout="100" />
<action name="monitor"      timeout="20" interval="10" depth="0" start-delay="0" />
<action name="reload"       timeout="90" />
<action name="meta-data"    timeout="5" />
<action name="verify-all"   timeout="30" />
</actions>
</resource-agent>
END

}
qpage_status()
{
    if [ -n "$OCF_RESKEY_pidfile" -a -f $OCF_RESKEY_pidfile ]; then
        # probably running
        PID=`cat $OCF_RESKEY_pidfile`
        if [ -n "$PID" ]; then
            if ps -p $PID | grep qpage >/dev/null ; then
                ocf_log info "qpage daemon running"
                return $OCF_SUCCESS
            else
                ocf_log info "qpage daemon is not running but pid file exists"
                return $OCF_ERR_GENERIC
            fi
        else
            ocf_log err "PID file empty!"
            return $OCF_ERR_GENERIC
        fi
    fi

    # not running
    ocf_log info "qpage daemon is not running"
    return $OCF_NOT_RUNNING
}

qpage_start()
{
        qpage_status
    retVal=$?
    if [ $retVal -eq $OCF_SUCCESS ]; then
        exit $OCF_SUCCESS
    elif [ $retVal -ne $OCF_NOT_RUNNING ]; then
        ocf_log err "Error. Unknown status."
        exit $OCF_ERR_GENERIC
    fi

        $OCF_RESKEY_binary -q10 -C $OCF_RESKEY_config

    if [ $? = 0 ]
        then
                pidofproc $OCF_RESKEY_binary > $OCF_RESKEY_pidfile
        exit $OCF_SUCCESS
    fi
        exit $OCF_ERR_GENERIC
}

qpage_stop()
{
        echo -n $"Stopping: "
        echo
        killproc $OCF_RESKEY_binary
}

qpage_reload()
{
    echo -n $"Reloading: "
    echo
}
qpage_monitor()
{
        qpage_status
    if [ -f $OCF_RESKEY_pidfile ]; then
    pid=`cat $OCF_RESKEY_pidfile`
    fi
    if [ ! -z $pid ]; then
        kill -0 $pid
        if [ $? = 0 ]; then
                        echo "qpage is running"
            exit $OCF_SUCCESS
        fi
    fi
        echo "qpage is NOT running"
    exit $OCF_NOT_RUNNING
}

qpage_validate-all()
{
    echo -n $"Validating: "
    echo
}

qpage_notify()
{
    echo -n $"Notifying: "
    echo
}
qpage_promote()
{
    echo -n $"Promoting: "
    echo
}

qpage_demote()
{
    echo -n $"Demoting: "
    echo
}
qpage_migrate_to()
{
    ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_to}."
    qpage_stop
}
qpage_migrate_from()
{
    ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrated_from}."
    qpage_start
}
usage() {
  cat << END
usage: $0 action

action:
    start   start the sshd server
    stop    stop the sshd server
    status  return the status of sshd server, run or down
    monitor  return TRUE if the sshd server appears to be working.
    meta-data   show meta data message
    validate-all    validate the instance parameters
    notify
    promote
    demote
    migrate_to
    migrate_from
END
  exit $OCF_ERR_ARGS
}

case "$1" in
    start)
        qpage_start
        ;;
    stop)
        qpage_stop
        ;;
    reload)
        ocf_log err "Reloading..."
        qpage_start
        ;;
    monitor)
        qpage_monitor
        ;;
    meta-data)
        qpage_meta-data
        exit $OCF_SUCCESS
        ;;
    validate-all)
        qpage_validate-all
                exit $OCF_SUCCESS
        ;;
    notify)
        qpage_notify
        ;;
    promote)
        qpage_promote
        ;;
    demote)
        qpage_demote
        ;;
    migrate_to)
        qpage_migrate_to
        ;;
    migrate_from)
        qpage_migrate_from
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|monitor|meta-data|validate-all|notify|promote|demote|migrate_to|migrate_from}"
                exit $OCF_ERR_UNIMPLEMENTED
        ;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
AttachmentSize
qpage5.84 KB
Submitted by davea on Tue, 2007-12-18 08:25.