Whamcloud - gitweb
07e0bad09954d8f2c1a983fba89dec60da1300a4
[fs/lustre-release.git] / contrib / scripts / pacemaker / healthLUSTRE
1 #!/bin/sh
2 #
3 #
4 #       HealthLUSTRE OCF RA
5 #
6
7 # License:      GNU General Public License (GPL)v2
8 # Description:  Manages ZFS and Lustre on a shared storage
9 # Written by:   Gabriele Paciucci
10 # Release Date: 01 November 2016
11 # Release Version: 0.99.3
12 # Copyright (c) 2009 Andrew Beekhof
13 # Copyright (c) 2016, Intel Corporation
14
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of version 2 of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful, but
21 # WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 #
24 # Further, this software is distributed without any warranty that it is
25 # free of the rightful claim of any third person regarding infringement
26 # or the like.  Any license provided herein, whether implied or
27 # otherwise, applies only to this software file.  Patent licenses, if
28 # any, provided herein do not apply to combinations of this program with
29 # other software, or any other product whatsoever.
30 #
31 # You should have received a copy of the GNU General Public License
32 # along with this program.
33 # If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
34 #
35
36 #######################################################################
37 # Initialization:
38
39 : ${OCF_FUNCTIONS=${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs}
40 . ${OCF_FUNCTIONS}
41 : ${__OCF_ACTION=$1}
42
43 #######################################################################
44
45 meta_data() {
46         cat <<END
47 <?xml version="1.0"?>
48 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
49 <resource-agent name="healthLUSTRE">
50 <version>0.99.3</version>
51
52 <longdesc lang="en">
53 Every time the monitor action is run, this resource agent
54 records (in the CIB) the current number of healthy lustre server
55 </longdesc>
56 <shortdesc lang="en">lustre servers healthy</shortdesc>
57
58 <parameters>
59
60 <parameter name="pidfile" unique="0">
61 <longdesc lang="en">PID file</longdesc>
62 <shortdesc lang="en">PID file</shortdesc>
63 <content type="string" default="$HA_VARRUN/healthLUSTRE-${OCF_RESOURCE_INSTANCE}" />
64 </parameter>
65
66 <parameter name="dampen" unique="0">
67 <longdesc lang="en">
68 The time to wait (dampening) further changes occur
69 </longdesc>
70 <shortdesc lang="en">Dampening interval</shortdesc>
71 <content type="integer" default="5s"/>
72 </parameter>
73
74
75 <parameter name="name" unique="0">
76 <longdesc lang="en">
77 The name of the attributes to set.
78 This is the name to be used in the constraints.
79 </longdesc>
80 <shortdesc lang="en">Attribute name</shortdesc>
81 <content type="string" default="lustred"/>
82 </parameter>
83
84
85
86 <parameter name="debug" unique="0">
87 <longdesc lang="en">
88 Enables to use default attrd_updater verbose logging on every call.
89 </longdesc>
90 <shortdesc lang="en">Verbose logging</shortdesc>
91 <content type="string" default="false"/>
92 </parameter>
93
94 </parameters>
95
96 <actions>
97 <action name="start"   timeout="60" />
98 <action name="stop"    timeout="20" />
99 <action name="reload"  timeout="100" />
100 <action name="monitor" depth="0"  timeout="60" interval="10"/>
101 <action name="meta-data"  timeout="5" />
102 <action name="validate-all"  timeout="30" />
103 </actions>
104 </resource-agent>
105 END
106 }
107
108 #######################################################################
109
110 lustre_conditional_log() {
111         level=$1; shift
112         if [ ${OCF_RESKEY_debug} = "true" ]; then
113                 ocf_log $level "$*"
114         fi
115 }
116
117 lustre_usage() {
118         cat <<END
119 usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data}
120
121 Expects to have a fully populated OCF RA-compliant environment set.
122 END
123 }
124
125 lustre_start() {
126         lustre_monitor
127         if [ $? =  $OCF_SUCCESS ]; then
128                 return $OCF_SUCCESS
129         fi
130         touch ${OCF_RESKEY_pidfile}
131         lustre_update
132 }
133
134 lustre_stop() {
135         rm -f ${OCF_RESKEY_pidfile}
136         attrd_updater -D -n $OCF_RESKEY_name -d $OCF_RESKEY_dampen $attrd_options
137         return $OCF_SUCCESS
138 }
139
140 lustre_monitor() {
141         if [ -f ${OCF_RESKEY_pidfile} ]; then
142                 lustre_update
143                 if [ $? -eq 0 ]; then
144                     return $OCF_SUCCESS
145                 fi
146                 return $OCF_ERR_GENERIC
147         fi
148         return $OCF_NOT_RUNNING
149 }
150
151
152 lustre_check() {
153         active=0
154
155         # added head -1 due the LU-7486
156         l_out=`cat /proc/fs/lustre/health_check | head -1 |grep -w healthy 2>&1`; rc=$?
157
158         case $rc in
159             0) active=`expr $active + 1`;;
160             1) lustre_conditional_log warn "Lustre is not healthy: $l_out";;
161             *) ocf_log err "Unexpected result for '/proc/fs/lustre/health_check' $rc: $l_out";;
162         esac
163         return $active
164 }
165
166 lustre_update() {
167         lustre_check
168         active=$?
169
170         attrd_updater -n $OCF_RESKEY_name -v $active -d $OCF_RESKEY_dampen $attrd_options
171         rc=$?
172         case $rc in
173                 0) lustre_conditional_log debug "Updated $OCF_RESKEY_name = $active" ;;
174                 *) ocf_log warn "Could not update $OCF_RESKEY_name = $active: rc=$rc";;
175         esac
176         if [ $rc -ne 0 ]; then
177                 return $rc
178         fi
179         return 0
180 }
181
182
183 if [ ! -f /proc/fs/lustre/health_check ]; then
184         ocf_log warn "Attention Health_Check file doesn't exist. Lustre will be loaded"
185         modprobe lustre
186 fi
187
188
189 if [ ${OCF_RESKEY_CRM_meta_globally_unique} = "false" ]; then
190         : ${OCF_RESKEY_pidfile:="$HA_VARRUN/healthLUSTRE-${OCF_RESKEY_name}"}
191 else
192         : ${OCF_RESKEY_pidfile:="$HA_VARRUN/healthLUSTRE-${OCF_RESOURCE_INSTANCE}"}
193 fi
194
195 attrd_options='-q'
196 if ocf_is_true ${OCF_RESKEY_debug} ; then
197     attrd_options=''
198 fi
199
200 : ${OCF_RESKEY_name:="lustred"}
201 : ${OCF_RESKEY_debug:="false"}
202
203 case $__OCF_ACTION in
204 meta-data)      meta_data
205                 exit $OCF_SUCCESS
206                 ;;
207 start)          lustre_start;;
208 stop)           lustre_stop;;
209 monitor)        lustre_monitor;;
210 reload)         lustre_start;;
211 validate-all)   lustre_usage
212                 exit $OCF_SUCCESS
213                 ;;
214 usage|help)     lustre_usage
215                 exit $OCF_SUCCESS
216                 ;;
217 *)              lustre_usage
218                 exit $OCF_ERR_UNIMPLEMENTED
219                 ;;
220 esac