Bug#597713: A Debian tested clvmd RA script

Dave Whitla dave.whitla at ocean.net.au
Wed Jul 13 14:19:16 UTC 2011


The script linked to by the OP is loaded with bugs and will not run on Debian.

Below is one I have developed on Debian Squeeze based loosely on the SUSE script.
I'd like to see this make it into our distro also, as to this point building a fully functional Pacemaker cluster on Squeeze has been much more difficult that it need be.
I hope this helps others.

Dave


#!/bin/bash

# OCF initialization
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
. /lib/lsb/init-functions

# Parameter defaults
: ${OCF_RESKEY_CRM_meta_globally_unique:="false"}
: ${OCF_RESKEY_daemon_timeout:="80"}
: ${OCF_RESKEY_daemon_options:="-d 0"}

exec="/usr/sbin/clvmd"

function check_status() {
    local pid=$(pidofproc $exec)
    [ -n "$pid" ] || return $OCF_NOT_RUNNING
    return $OCF_SUCCESS
}

clvmd_start() {
    local elapsed=0 base=$(basename $exec)
    ocf_log info "Starting $OCF_RESOURCE_INSTANCE"
    if [ ! -e "$exec" ]; then
        ocf_log err "Required binary not found: $exec"
        return $OCF_ERR_INSTALLED
    fi
    /sbin/start-stop-daemon --start --nicelevel 0 --quiet --chdir "$PWD" --exec $exec -- "$OCF_RESKEY_daemon_options"
    case "$?" in
        1)
            ocf_log warn "$base already running with pid $(pidof $exec)."
            return $OCF_SUCCESS
            ;;
        3)
            ocf_log err "Unable to start $base."
            return $OCF_ERR_GENERIC
            ;;
    esac

    # wait for the daemon to start
    while ! check_status; do
        if (( ++elapsed > OCF_RESKEY_daemon_timeout )); then
            ocf_log err "$base invocation returned without error but is still not started after $OCF_RESKEY_daemon_timeout seconds."
            return $OCF_ERR_GENERIC
        fi
        sleep 1
    done

    ocf_log info "$base started."
    return $OCF_SUCCESS
}

clvmd_stop() {
    ocf_log info "Stopping $OCF_RESOURCE_INSTANCE"
    local elapsed=0 base=$(basename $exec)
    /sbin/start-stop-daemon --stop --quiet --exec $exec
    case "$?" in
        1)
            ocf_log info "No need to stop $base as it isn't running."
            return $OCF_NOT_RUNNING
            ;;
        3)
            ocf_log err "Stopping $base with SIG$signal returned an error. Fail."
            return $OCF_ERR_GENERIC
            ;;
    esac

    # wait for the daemon to stop
    while check_status; do
        if (( ++elapsed > OCF_RESKEY_daemon_timeout )); then
            ocf_log err "$base is still not stopped after $OCF_RESKEY_daemon_timeout seconds. Killing it."
            if ! /sbin/start-stop-daemon --stop --oknodo --signal KILL --exec $exec ; then
                ocf_log err "Unable to kill $base: $output"
                return $OCF_ERR_GENERIC
            fi
            ocf_log warn "$base killed. Yep - killed it dead."
        fi
        sleep 1
    done

    ocf_log info "$base stopped."
    return $OCF_SUCCESS
}

clvmd_monitor() {
    clvmd_validate
    check_status
}

clvmd_usage() {
    echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
    echo "  Expects to have a fully populated OCF RA-compliant environment set."
    echo "  In particular, a value for OCF_ROOT."
}

clvmd_validate() {
    case ${OCF_RESKEY_CRM_meta_globally_unique} in
        yes|Yes|true|True|1) 
            ocf_log err "$OCF_RESOURCE_INSTANCE must be configured with the gloablly_unique=false meta attribute"
            exit $OCF_ERR_CONFIGURED
            ;;
    esac
    return $OCF_SUCCESS
}

meta_data() {
    cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="clvmd">
    <version>1.0</version>
    <longdesc lang="en">
        This is a clvmd Resource Agent.
        It starts clvmd as anonymous clones.
    </longdesc>
    <shortdesc lang="en">clvmd resource agent</shortdesc>

    <parameters>
        <parameter name="daemon_timeout" unique="0">
            <longdesc lang="en">
                Number of seconds to allow the control daemon to come up and down
            </longdesc>
            <shortdesc lang="en">Daemon Timeout</shortdesc>
            <content type="string" default="80"/>
        </parameter>
        <parameter name="daemon_options" unique="0">
            <longdesc lang="en">
                Options to clvmd. Refer to clvmd.8 for detailed descriptions.
            </longdesc>
            <shortdesc lang="en">Daemon Options</shortdesc>
            <content type="string" default="-d0"/>
        </parameter>
    </parameters>

    <actions>
        <action name="start"         timeout="90" />
        <action name="stop"          timeout="100" />
        <action name="monitor"       timeout="20" depth="0"/>
        <action name="meta-data"     timeout="5" />
        <action name="validate-all"  timeout="30" />
    </actions>
</resource-agent>
END
    return $OCF_SUCCESS
}

case $__OCF_ACTION in
    meta-data)
        meta_data
        ;;
    start)
        clvmd_start
        ;;
    stop)
        clvmd_stop
        ;;
    monitor)
        clvmd_monitor
        ;;
    validate-all)
        clvmd_validate
        ;;
    usage|help)    
        clvmd_usage
        exit $OCF_SUCCESS
        ;;
    *)
        clvmd_usage >&2
        exit $OCF_ERR_UNIMPLEMENTED
        ;;
esac

exit $?






More information about the pkg-lvm-maintainers mailing list