~1chb1n/charms/trusty/quantum-gateway/next-amulet-tk2

« back to all changes in this revision

Viewing changes to files/NeutronAgentMon

  • Committer: Liam Young
  • Date: 2015-01-23 14:48:02 UTC
  • mfrom: (76.2.89 neutron-ha-scale)
  • Revision ID: liam.young@canonical.com-20150123144802-63k91ec17k30p5ng
[xianghui, r=gnuoy] To support quantum-gateway HA in Icehouse before Juno native HA deployed.
It works by using pacemaker to monitor a daemon, which will detect neutron agents status and cleanup local resource when failover etc.

BP:
https://blueprints.launchpad.net/cts-engineering/+spec/neutron-gateway-services-need-ha-support

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#
 
4
#       NeutronAgentMon OCF RA.
 
5
#       Starts crm_mon in background which logs cluster status as
 
6
#       html to the specified file.
 
7
#
 
8
#       Copyright 2014 Canonical Ltd.
 
9
#
 
10
#       Authors: Hui Xiang <hui.xiang@canonical.com>
 
11
#                Edward Hope-Morley <edward.hope-morley@canonical.com>
 
12
#
 
13
# OCF instance parameters:
 
14
#       OCF_RESKEY_file
 
15
 
 
16
#######################################################################
 
17
# Initialization:
 
18
: ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
 
19
. ${OCF_FUNCTIONS}
 
20
: ${__OCF_ACTION=$1}
 
21
 
 
22
#######################################################################
 
23
 
 
24
meta_data() {
 
25
        cat <<END
 
26
<?xml version="1.0"?>
 
27
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
28
<resource-agent name="NeutronAgentMon">
 
29
<version>1.0</version>
 
30
 
 
31
<longdesc lang="en">
 
32
This is a NeutronAgentMon Resource Agent.
 
33
It monitors the 'neutron-ha-monitor daemon' status.
 
34
</longdesc>
 
35
<shortdesc lang="en">Monitor '/usr/local/bin/neutron-ha-monitor.py' in the background.</shortdesc>
 
36
 
 
37
<parameters>
 
38
 
 
39
<parameter name="file" unique="0">
 
40
<longdesc lang="en">
 
41
The file we want to run as a daemon.
 
42
</longdesc>
 
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" />
 
45
</parameter>
 
46
 
 
47
</parameters>
 
48
 
 
49
<actions>
 
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" />
 
55
</actions>
 
56
</resource-agent>
 
57
END
 
58
}
 
59
 
 
60
#######################################################################
 
61
 
 
62
NeutronAgentMon_usage() {
 
63
        cat <<END
 
64
usage: $0 {start|stop|monitor|validate-all|meta-data}
 
65
 
 
66
Expects to have a fully populated OCF RA-compliant environment set.
 
67
END
 
68
}
 
69
 
 
70
NeutronAgentMon_exit() {
 
71
    if [ $1 != 0 ]; then
 
72
        exit $OCF_ERR_GENERIC
 
73
    else
 
74
        exit $OCF_SUCCESS
 
75
    fi
 
76
}
 
77
 
 
78
NeutronAgentMon_start() {
 
79
    pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'`
 
80
    if [ -z $pid ]; then
 
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 $!
 
86
        sleep 5
 
87
    else
 
88
        ocf_log warn "[NeutronAgentMon_start] Monitor daemon already running."
 
89
    fi
 
90
    NeutronAgentMon_exit $?
 
91
}
 
92
 
 
93
NeutronAgentMon_stop() {
 
94
    pid=`sudo ps -aux | grep neutron-ha-m\[o\]nitor.py | awk -F' ' '{print $2}'`
 
95
    if [ ! -z $pid ]; then
 
96
        sudo kill -s 9 $pid
 
97
        ocf_log info "[NeutronAgentMon_stop] Pid $pid is killed."
 
98
    else
 
99
        ocf_log warn "[NeutronAgentMon_stop] Monitor daemon already stopped."
 
100
    fi
 
101
    NeutronAgentMon_exit 0
 
102
}
 
103
 
 
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."
 
108
        exit $OCF_SUCCESS
 
109
    fi
 
110
    exit $OCF_NOT_RUNNING
 
111
}
 
112
 
 
113
NeutronAgentMon_validate() {
 
114
# Existence of the user
 
115
    if [ -f $OCF_RESKEY_file ]; then
 
116
        echo "Validate OK"
 
117
        return $OCF_SUCCESS
 
118
    else
 
119
        ocf_log err "The file $OCF_RESKEY_file does not exist!"
 
120
        exit $OCF_ERR_ARGS
 
121
    fi
 
122
}
 
123
 
 
124
if [ $# -ne 1 ]; then
 
125
    NeutronAgentMon_usage
 
126
    exit $OCF_ERR_ARGS
 
127
fi
 
128
 
 
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"}
 
132
 
 
133
OCF_RESKEY_update=`expr $OCF_RESKEY_update / 1000`
 
134
 
 
135
case $__OCF_ACTION in
 
136
meta-data)      meta_data
 
137
                exit $OCF_SUCCESS
 
138
                ;;
 
139
start)          NeutronAgentMon_start
 
140
                ;;
 
141
stop)           NeutronAgentMon_stop
 
142
                ;;
 
143
monitor)        NeutronAgentMon_monitor
 
144
                ;;
 
145
validate-all)   NeutronAgentMon_validate
 
146
                ;;
 
147
usage|help)     NeutronAgentMon_usage
 
148
                exit $OCF_SUCCESS
 
149
                ;;
 
150
*)              NeutronAgentMon_usage
 
151
                exit $OCF_ERR_UNIMPLEMENTED
 
152
                ;;
 
153
esac
 
154
 
 
155
exit $?