#!/bin/sh # # # NeutronAgentMon OCF RA. # Starts crm_mon in background which logs cluster status as # html to the specified file. # # Copyright 2014 Canonical Ltd. # # Authors: Hui Xiang # Edward Hope-Morley # # OCF instance parameters: # OCF_RESKEY_file ####################################################################### # Initialization: : ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs} . ${OCF_FUNCTIONS} : ${__OCF_ACTION=$1} ####################################################################### meta_data() { cat < 1.0 This is a NeutronAgentMon Resource Agent. It monitors the 'neutron-ha-monitor daemon' status. Monitor '/usr/local/bin/neutron-ha-monitor.py' in the background. The file we want to run as a daemon. The file we want to run as a daemon. END } ####################################################################### NeutronAgentMon_usage() { cat <> /dev/null 2>&1 & echo $! sleep 5 else ocf_log warn "[NeutronAgentMon_start] Monitor daemon already running." fi NeutronAgentMon_exit $? } NeutronAgentMon_stop() { pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'` if [ ! -z $pid ]; then sudo kill -s 9 $pid ocf_log info "[NeutronAgentMon_stop] Pid $pid is killed." else ocf_log warn "[NeutronAgentMon_stop] Monitor daemon already stopped." fi NeutronAgentMon_exit 0 } NeutronAgentMon_monitor() { pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'` if [ ! -z $pid ]; then ocf_log info "[NeutronAgentMon_monitor] success." exit $OCF_SUCCESS fi exit $OCF_NOT_RUNNING } NeutronAgentMon_validate() { # Existence of the user if [ -f $OCF_RESKEY_file ]; then echo "Validate OK" return $OCF_SUCCESS else ocf_log err "The file $OCF_RESKEY_file does not exist!" exit $OCF_ERR_ARGS fi } if [ $# -ne 1 ]; then NeutronAgentMon_usage exit $OCF_ERR_ARGS fi : ${OCF_RESKEY_update:="15000"} : ${OCF_RESKEY_pidfile:="/tmp/NeutronAgentMon_${OCF_RESOURCE_INSTANCE}.pid"} : ${OCF_RESKEY_htmlfile:="/tmp/NeutronAgentMon_${OCF_RESOURCE_INSTANCE}.html"} OCF_RESKEY_update=`expr $OCF_RESKEY_update / 1000` case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) NeutronAgentMon_start ;; stop) NeutronAgentMon_stop ;; monitor) NeutronAgentMon_monitor ;; validate-all) NeutronAgentMon_validate ;; usage|help) NeutronAgentMon_usage exit $OCF_SUCCESS ;; *) NeutronAgentMon_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $?