diff --git a/heartbeat/vdo-vol b/heartbeat/vdo-vol index 94822cb82..29bd7b8fd 100755 --- a/heartbeat/vdo-vol +++ b/heartbeat/vdo-vol @@ -1,234 +1,240 @@ #!/bin/sh # # License: GNU General Public License (GPL) # (c) 2018 O. Albrigtsen # and Linux-HA contributors # # ----------------------------------------------------------------------------- # O C F R E S O U R C E S C R I P T S P E C I F I C A T I O N # ----------------------------------------------------------------------------- # # NAME # vdo-vol : OCF resource agent script for VDO (Virtual Data Optimizer) # # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # Defaults OCF_RESKEY_volume_default="" : ${OCF_RESKEY_volume=${OCF_RESKEY_volume_default}} vdo_usage() { cat < 1.0 OCF Resource script for VDO (Virtual Data Optimizer) volume(s). It manages VDO volume(s) as a HA resource. The configuration file needs to be synced to all nodes, and the systemd vdo service must be disabled when using this agent. VDO resource agent Configuration file Config file VDO Volume (leave empty for all) Volume (empty for all) END } rebuild() { ocf_log warn "${OCF_RESKEY_volume} is in $MODE mode, starting in rebuild mode" vdo stop $OPTIONS while vdo_monitor skiprocheck; do sleep 1 done vdo start $OPTIONS --forceRebuild while ! vdo_monitor; do sleep 1 done return $? } vdo_start() { # if resource is already running,no need to continue code after this. if vdo_monitor; then ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} is already active" return $OCF_SUCCESS fi vdo activate $OPTIONS vdo start $OPTIONS while ! vdo_monitor skiprocheck; do sleep 1 done MODE=$(vdostats --verbose ${OCF_RESKEY_volume} | grep "operating mode" | awk '{print $NF}') if [ $(echo "$MODE" | grep -v "normal" | wc -l) -gt 0 ]; then rebuild fi if [ $? -eq $OCF_SUCCESS ]; then ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} activated" return ${OCF_SUCCESS} fi return $? } vdo_stop() { vdo_monitor skiprocheck if [ $? -ne $OCF_SUCCESS ]; then # Currently not running. Nothing to do. ocf_log info "VDO volume(s): ${OCF_RESKEY_volume} already deactivated" return $OCF_SUCCESS fi vdo stop $OPTIONS vdo deactivate $OPTIONS # Wait for process to stop while vdo_monitor skiprocheck; do sleep 1 done return $OCF_SUCCESS } vdo_monitor(){ status=$(vdo status $OPTIONS 2>&1) MODE=$(vdostats --verbose ${OCF_RESKEY_volume} | grep "operating mode" | awk '{print $NF}') case "$status" in + *"ERROR - vdodumpconfig: Failed to make FileLayer from"*) + if ocf_is_probe; then + return $OCF_NOT_RUNNING + fi + return $OCF_ERR_GENERIC + ;; *"Device mapper status: not available"*) return $OCF_NOT_RUNNING ;; *"Device mapper status: "*online*) if [ "$MODE" = "read-only" ] && [ "$1" != "skiprocheck" ]; then ocf_log err "VDO volume(s): ${OCF_RESKEY_volume} is in $MODE mode." return $OCF_ERR_GENERIC else return $OCF_SUCCESS fi ;; *) ocf_log err "VDO volume(s): ${OCF_RESKEY_volume} failed\n$status" return $OCF_ERR_GENERIC;; esac } vdo_validate_all(){ check_binary "vdo" if systemctl is-enabled vdo > /dev/null 2>&1; then ocf_exit_reason "systemd service vdo needs to be disabled" exit $OCF_ERR_CONFIGURED fi if [ -n "${OCF_RESKEY_config}" ] && [ ! -f "${OCF_RESKEY_config}" ]; then ocf_exit_reason "Configuration file: ${OCF_RESKEY_config} not found" exit $OCF_ERR_CONFIGURED fi return $OCF_SUCCESS } # **************************** MAIN SCRIPT ************************************ # Make sure meta-data and usage always succeed case $__OCF_ACTION in meta-data) vdo_meta_data exit $OCF_SUCCESS ;; usage|help) vdo_usage exit $OCF_SUCCESS ;; esac # This OCF agent script need to be run as root user. if ! ocf_is_root; then echo "$0 agent script need to be run as root user." ocf_log debug "$0 agent script need to be run as root user." exit $OCF_ERR_GENERIC fi if [ -z "${OCF_RESKEY_volume}" ]; then OPTIONS="-a" else OPTIONS="-n ${OCF_RESKEY_volume}" fi if [ -n "${OCF_RESKEY_config}" ]; then OPTIONS="$OPTIONS -f ${OCF_RESKEY_config}" fi # Translate each action into the appropriate function call case $__OCF_ACTION in start) vdo_validate_all vdo_start;; stop) vdo_stop;; status|monitor) vdo_monitor;; validate-all) ;; *) vdo_usage exit $OCF_ERR_UNIMPLEMENTED;; esac exit $? # End of this script