Hi Florian,

thanks a lot for your quick reply, I fixed those little errors and added a little feature that checks if the /var/run/firebird directory is writeable by the OCF_RESKEY_user or not.

Hope this is better :)

Frank

On 24.11.2010 13:53, Florian Haas wrote:
Hi Frank,

Great contribution, thanks! RA looks pretty good overall; a few comments
inline:

On 2010-11-24 13:38, Frank Lazzarini wrote:
#!/bin/sh
#
#
#       Firebird 2.5 OCF RA. Start Firebird 2.5 Superclassic server
#
#
# Author:       Frank Lazzarini
#
# Support:      [email protected]
# License:      GNU General Public License (GPL)
# Copyright:    (C) 2010 SitaSoftware S.A.
#
# See usage() function below for more details...
#
# OCF instance parameters:
#   OCF_RESKEY_binary
#   OCF_RESKEY_pid
#   OCF_RESKEY_user
#
#######################################################################
# Initialization:

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

#######################################################################

OCF_RESKEY_binary_default="/opt/firebird/bin/fbguard"
OCF_RESKEY_pid_default="/var/run/firebird/firebird.pid"
OCF_RESKEY_user_default="firebird"

: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}


meta_data() {
        cat<<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="firebird25" version="0.1">
<version>1.0</version>
I realize the fact that we can specify the RA version twice is
redundant, but the version numbers should match. :)

<longdesc lang="en">
This is a Resource Agent for Firebird 2.5 Superclassic server. The resource 
agent
simply starts fbguard with a few options. Fbguard is a process which starts the
Firebird 2.5 Superclassic server namely fb_snmp_server process and guards this
process.
</longdesc>
<shortdesc lang="en">Firebird 2.5 Superclassic Server Resource 
Agent.</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
        <shortdesc lang="en">Firebird 2.5 Guardian binary</shortdesc>
        <longdesc lang="en">Destination of the Firebird 2.5 Superclassic Guardian 
binary. (default: /opt/firebird/bin/fb_snmp_server)</longdesc>
You can just use:

<longdesc lang="en">Destination of the Firebird 2.5 Superclassic
Guardian binary. (default: $OCF_RESKEY_binary_default)</longdesc>

        <content type="string" default="$OCF_RESKEY_binary_default" />
</parameter>

<parameter name="pid" unique="0" required="0">
        <shortdesc lang="en">Firebird pid file</shortdesc>
        <longdesc lang="en">The pidfile to be used for fbguard (default: 
/var/run/firebird/firebird.pid)</longdesc>
As above.

        <content type="string" default="$OCF_RESKEY_pid_default" />
</parameter>

<parameter name="user" unique="0" required="0">
        <shortdesc lang="en">Firebird User</shortdesc>
        <longdesc lang="en">User running Firebird daemon (default: 
firebird)</longdesc>
As above.

        <content type="string" default="$OCF_RESKEY_user_default" />
</parameter>
</parameters>

<actions>
<action name="start"          timeout="20" />
<action name="stop"           timeout="20" />
I assume you've tested that the agent really has the capability of
starting and stopping its daemon within 20 seconds?

<action name="monitor"        timeout="20" interval="10" depth="0" />
<action name="reload"         timeout="20" />
<action name="migrate_to"     timeout="20" />
<action name="migrate_from"   timeout="20" />
The RA does not support migrate_to and migrate_from, so you shouldn't be
advertising these.

<action name="meta-data"      timeout="5"  />
<action name="validate-all"   timeout="20" />
</actions>
</resource-agent>
END
        exit $OCF_SUCCESS
}

#######################################################################

firebird25_usage() {
        cat<<END
usage: $0 {start|stop|monitor|meta-data}

END
}

firebird25_start() {
        # exit immediately if configuration is not valid
        firebird25_validate_all || exit $?

        # if resource is already running, bail out early
        if firebird25_monitor; then
                ocf_log info "Resource is already running"
        fi

        start-stop-daemon --start --quiet --oknodo --chuid $OCF_RESKEY_user 
--exec $OCF_RESKEY_binary -- -pidfile $OCF_RESKEY_pid -daemon -forever
Unfortunately start-stop-daemon is a Debian/Ubuntu-ism (it comes with
dpkg), so you'll have to change this to a distro independent invocation.

        return $OCF_SUCCESS
}

firebird25_stop() {
        local rc

        # exit immediately if configuration is not valid
        firebird25_validate_all || exit $?

        # check if firebird is running
        firebird25_monitor
        rc=$?

        case "$rc" in
                "$OCF_SUCCESS")
                        ocf_log debug "Resource is currently running"
                        ;;
                "$OCF_NOT_RUNNING")
                        ocf_log info "Resource is already stopped"
                        ;;
        esac

        if [ -f $OCF_RESKEY_pid ]
        then
                kill `cat $OCF_RESKEY_pid`
                if [ $? = 0 ]; then
                        return $OCF_SUCCESS
                fi
        fi

        while firebird25_monitor; do
                ocf_log debug "Resource has not stopped yet, waiting"
                sleep 1
        done

        return $OCF_SUCCESS
}

firebird25_monitor() {
        local rc
        firebird25_validate_all
Sure you don't want to exit here if validation fails?

        # Return OCF_NOT_RUNNING if no pid was found
        if [ ! -e $OCF_RESKEY_pid ]; then
                ocf_log debug "Firebird is not running"
                return $OCF_NOT_RUNNING
        fi

        # Check if firebird is running
        # first get the pid from the pidfile and check with
        # kill -0 pid if the process is running with the right pid
        pid=`cat $OCF_RESKEY_pid`
        kill -0 $pid>/dev/null 2>&1
Minor bashism here, the generic way to do this is to use kill -s 0 $pid.

        rc=$?

        # Return OCF_SUCCESS if process is running
        # Return OCF_NOT_RUNNING if process is not running but pid exists
        if [ $rc -eq 0 ]; then
                return $OCF_SUCCESS
        else
                ocf_log debug "Firebird is not running: removing old PID file"
                rm -f $OCF_RESKEY_pid
                return $OCF_NOT_RUNNING
        fi
}

firebird25_validate_all() {
        # Checking the parameters
        # check if binary exists and is executable
        if [ ! -x $OCF_RESKEY_binary ]; then
                ocf_log err "fbguard binary $OCF_RESKEY_binary does not exist or is 
not executable"
                return $OCF_ERR_INSTALLED
No need to return the $OCF_ERR status; you can just exit and leave it to
Pacemaker to recover.

        fi

        # check if user exits
        getent passwd $OCF_RESKEY_user>/dev/null 2>&1
        if [ ! $? -eq 0 ]; then
                ocf_log err "User $OCF_RESKEY_user doesn't exist"
                return $OCF_ERR_INSTALLED
Same here.

        fi
        true
}

case $__OCF_ACTION in
meta-data)      meta_data
                exit $OCF_SUCCESS
                ;;
start)          firebird25_start;;
stop)           firebird25_stop;;
monitor)        firebird25_monitor;;
reload)         ocf_log err "Reloading..."
                firebird25_start
                ;;
validate-all)   firebird25_validate_all;;
usage|help)     firebird25_usage
                exit $OCF_SUCCESS
                ;;
*)              firebird25_usage
                exit $OCF_ERR_UNIMPLEMENTED
                ;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
Thanks again -- keep up the good work!

Cheers,
Florian



_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

#!/bin/sh
#
#
#       Firebird 2.5 OCF RA. Start Firebird 2.5 Superclassic server
#
#
# Author:       Frank Lazzarini
#
# Support:      [email protected]
# License:      GNU General Public License (GPL)
# Copyright:    (C) 2010 SitaSoftware S.A.
#
# See usage() function below for more details...
#
# OCF instance parameters:
#   OCF_RESKEY_binary
#   OCF_RESKEY_pid
#   OCF_RESKEY_user
#
#######################################################################
# Initialization:

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

#######################################################################

OCF_RESKEY_binary_default="/opt/firebird/bin/fbguard"
OCF_RESKEY_pid_default="/var/run/firebird/firebird.pid"
OCF_RESKEY_user_default="firebird"

: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}


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

<longdesc lang="en">
This is a Resource Agent for Firebird 2.5 Superclassic server. The resource 
agent
simply starts fbguard with a few options. Fbguard is a process which starts the
Firebird 2.5 Superclassic server namely fb_snmp_server process and guards this
process.
</longdesc>
<shortdesc lang="en">Firebird 2.5 Superclassic Server Resource 
Agent.</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
        <shortdesc lang="en">Firebird 2.5 Guardian binary</shortdesc>
        <longdesc lang="en">Destination of the Firebird 2.5 Superclassic 
Guardian binary. (default: $OCF_RESKEY_binary_default)</longdesc>
        <content type="string" default="$OCF_RESKEY_binary_default" />
</parameter>

<parameter name="pid" unique="0" required="0">
        <shortdesc lang="en">Firebird pid file</shortdesc>
        <longdesc lang="en">The pidfile to be used for fbguard (default: 
$OCF_RESKEY_pid_default)</longdesc>
        <content type="string" default="$OCF_RESKEY_pid_default" />
</parameter>

<parameter name="user" unique="0" required="0">
        <shortdesc lang="en">Firebird User</shortdesc>
        <longdesc lang="en">User running Firebird daemon (default: 
$OCF_RESKEY_user_default)</longdesc>
        <content type="string" default="$OCF_RESKEY_user_default" />
</parameter>
</parameters>

<actions>
<action name="start"          timeout="20" />
<action name="stop"           timeout="20" />
<action name="monitor"        timeout="20" interval="10" depth="0" />
<action name="reload"         timeout="20" />
<action name="meta-data"      timeout="5"  />
<action name="validate-all"   timeout="20" />
</actions>
</resource-agent>
END
        exit $OCF_SUCCESS
}

#######################################################################

firebird25_usage() {
        cat <<END
usage: $0 {start|stop|monitor|meta-data}

END
}

firebird25_start() {
        # exit immediately if configuration is not valid
        firebird25_validate_all || exit $?

        # if resource is already running, bail out early
        if firebird25_monitor; then
                ocf_log info "Resource is already running"
        fi

        # start fbguard with the specified user
        sudo -u $OCF_RESKEY_user $OCF_RESKEY_binary -pidfile $OCF_RESKEY_pid 
-daemon -forever

        return $OCF_SUCCESS
}

firebird25_stop() {
        local rc

        # exit immediately if configuration is not valid
        firebird25_validate_all || exit $?

        # check if firebird is running
        firebird25_monitor
        rc=$?

        case "$rc" in
                "$OCF_SUCCESS")
                        ocf_log debug "Resource is currently running"
                        ;;
                "$OCF_NOT_RUNNING")
                        ocf_log info "Resource is already stopped"
                        ;;
        esac

        if [ -f $OCF_RESKEY_pid ]
        then
                kill `cat $OCF_RESKEY_pid`
                if [ $? = 0 ]; then
                        return $OCF_SUCCESS
                fi
        fi

        while firebird25_monitor; do
                ocf_log debug "Resource has not stopped yet, waiting"
                sleep 1
        done

        return $OCF_SUCCESS
}

firebird25_monitor() {
        local rc
        firebird25_validate_all

        # Return OCF_NOT_RUNNING if no pid was found
        if [ ! -e $OCF_RESKEY_pid ]; then
                ocf_log debug "Firebird is not running"
                return $OCF_NOT_RUNNING
        fi

        # Check if firebird is running
        # first get the pid from the pidfile and check with
        # kill -0 pid if the process is running with the right pid
        pid=`cat $OCF_RESKEY_pid`
        kill -s 0 $pid >/dev/null 2>&1
        rc=$?

        # Return OCF_SUCCESS if process is running
        # Return OCF_NOT_RUNNING if process is not running but pid exists
        if [ $rc -eq 0 ]; then
                return $OCF_SUCCESS
        else
                ocf_log debug "Firebird is not running: removing old PID file"
                rm -f $OCF_RESKEY_pid
                return $OCF_NOT_RUNNING
        fi
}

firebird25_validate_all() {
        local rc

        # Checking the parameters
        # check if binary exists and is executable
        if [ ! -x $OCF_RESKEY_binary ]; then
                ocf_log err "fbguard binary $OCF_RESKEY_binary does not exist 
or is not executable"
                exit $OCF_ERR_INSTALLED
        fi

        # check if pid is writable
        sudo -u $OCF_RESKEY_user touch $OCF_RESKEY_pid >/dev/null 2>&1
        rc=$?
        if [ ! "$rc" -eq 0 ]; then
                ocf_log err "Cannot write $OCF_RESKEY_pid, please check 
permissions"
                exit $OCF_ERR_INSTALLED
        fi

        # check if user exits
        getent passwd $OCF_RESKEY_user >/dev/null 2>&1
        if [ ! $? -eq 0 ]; then
                ocf_log err "User $OCF_RESKEY_user doesn't exist"
                exit $OCF_ERR_INSTALLED
        fi
        true
}

case $__OCF_ACTION in
meta-data)      meta_data
                exit $OCF_SUCCESS
                ;;
start)          firebird25_start;;
stop)           firebird25_stop;;
monitor)        firebird25_monitor;;
reload)         ocf_log err "Reloading..."
                firebird25_start
                ;;
validate-all)   firebird25_validate_all;;
usage|help)     firebird25_usage
                exit $OCF_SUCCESS
                ;;
*)              firebird25_usage
                exit $OCF_ERR_UNIMPLEMENTED
                ;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc

_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to