5. Resource agent actions

Each action is typically implemented in a separate function or method in the resource agent. By convention, these are usually named <agent>_<action>, so the function implementing the start action in foobar would be named foobar_start().

As a general rule, whenever the resource agent encounters an error that it is not able to recover, it is permitted to immediately exit, throw an exception, or otherwise cease execution. Examples for this include configuration issues, missing binaries, permission problems, etc. It is not necessary to pass these errors up the call stack.

It is the cluster manager’s responsibility to initiate the appropriate recovery action based on the user’s configuration. The resource agent should not guess at said configuration.

5.1. start action

When invoked with the start action, the resource agent must start the resource if it is not yet running. This means that the agent must verify the resource’s configuration, query its state, and then start it only if it is not running. A common way of doing this would be to invoke the validate_all and monitor function first, as in the following example:

foobar_start() {
    # exit immediately if configuration is not valid
    foobar_validate_all || exit $?

    # if resource is already running, bail out early
    if foobar_monitor; then
        ocf_log info "Resource is already running"
        return $OCF_SUCCESS
    fi

    # actually start up the resource here (make sure to immediately
    # exit with an $OCF_ERR_ error code if anything goes seriously
    # wrong)
    ...

    # After the resource has been started, check whether it started up
    # correctly. If the resource starts asynchronously, the agent may
    # spin on the monitor function here -- if the resource does not
    # start up within the defined timeout, the cluster manager will
    # consider the start action failed
    while ! foobar_monitor; do
        ocf_log debug "Resource has not started yet, waiting"
        sleep 1
    done

    # only return $OCF_SUCCESS if _everything_ succeeded as expected
    return $OCF_SUCCESS
}