4
# NeutronAgentMon OCF RA.
5
# Starts crm_mon in background which logs cluster status as
6
# html to the specified file.
8
# Copyright 2014 Canonical Ltd.
10
# Authors: Hui Xiang <hui.xiang@canonical.com>
11
# Edward Hope-Morley <edward.hope-morley@canonical.com>
13
# OCF instance parameters:
16
#######################################################################
18
: ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
22
#######################################################################
27
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
28
<resource-agent name="NeutronAgentMon">
29
<version>1.0</version>
32
This is a NeutronAgentMon Resource Agent.
33
It monitors the 'neutron-ha-monitor daemon' status.
35
<shortdesc lang="en">Monitor '/usr/local/bin/neutron-ha-monitor.py' in the background.</shortdesc>
39
<parameter name="file" unique="0">
41
The file we want to run as a daemon.
43
<shortdesc lang="en">The file we want to run as a daemon.</shortdesc>
44
<content type="string" default="/usr/local/bin/neutron-ha-monitor.py" />
50
<action name="start" timeout="20" />
51
<action name="stop" timeout="20" />
52
<action name="monitor" depth="0" timeout="20" interval="60" />
53
<action name="meta-data" timeout="5" />
54
<action name="validate-all" timeout="30" />
60
#######################################################################
62
NeutronAgentMon_usage() {
64
usage: $0 {start|stop|monitor|validate-all|meta-data}
66
Expects to have a fully populated OCF RA-compliant environment set.
70
NeutronAgentMon_exit() {
78
NeutronAgentMon_start() {
79
pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'`
81
ocf_log info "[NeutronAgentMon_start] Start Monitor daemon."
82
sudo mkdir -p /var/log/neutron-ha
83
sudo python /usr/local/bin/neutron-ha-monitor.py \
84
--config-file /var/lib/juju-neutron-ha/neutron-ha-monitor.conf \
85
--log-file /var/log/neutron-ha/monitor.log >> /dev/null 2>&1 & echo $!
88
ocf_log warn "[NeutronAgentMon_start] Monitor daemon already running."
90
NeutronAgentMon_exit $?
93
NeutronAgentMon_stop() {
94
pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'`
95
if [ ! -z $pid ]; then
97
ocf_log info "[NeutronAgentMon_stop] Pid $pid is killed."
99
ocf_log warn "[NeutronAgentMon_stop] Monitor daemon already stopped."
101
NeutronAgentMon_exit 0
104
NeutronAgentMon_monitor() {
105
pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'`
106
if [ ! -z $pid ]; then
107
ocf_log info "[NeutronAgentMon_monitor] success."
110
exit $OCF_NOT_RUNNING
113
NeutronAgentMon_validate() {
114
# Existence of the user
115
if [ -f $OCF_RESKEY_file ]; then
119
ocf_log err "The file $OCF_RESKEY_file does not exist!"
124
if [ $# -ne 1 ]; then
125
NeutronAgentMon_usage
129
: ${OCF_RESKEY_update:="15000"}
130
: ${OCF_RESKEY_pidfile:="/tmp/NeutronAgentMon_${OCF_RESOURCE_INSTANCE}.pid"}
131
: ${OCF_RESKEY_htmlfile:="/tmp/NeutronAgentMon_${OCF_RESOURCE_INSTANCE}.html"}
133
OCF_RESKEY_update=`expr $OCF_RESKEY_update / 1000`
135
case $__OCF_ACTION in
139
start) NeutronAgentMon_start
141
stop) NeutronAgentMon_stop
143
monitor) NeutronAgentMon_monitor
145
validate-all) NeutronAgentMon_validate
147
usage|help) NeutronAgentMon_usage
150
*) NeutronAgentMon_usage
151
exit $OCF_ERR_UNIMPLEMENTED