Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / conf / resource / 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         modprobe lustre
127         rc=$?
128         if [ $rc -ne 0 ]; then
129                 return $OCF_ERR_INSTALLED
130         fi
131         lustre_monitor
132         if [ $? =  $OCF_SUCCESS ]; then
133                 return $OCF_SUCCESS
134         fi
135         touch ${OCF_RESKEY_pidfile}
136         lustre_update
137 }
138
139 lustre_stop() {
140         rm -f ${OCF_RESKEY_pidfile}
141         attrd_updater -D -n $OCF_RESKEY_name -d $OCF_RESKEY_dampen $attrd_options
142         return $OCF_SUCCESS
143 }
144
145 lustre_monitor() {
146         if [ -f ${OCF_RESKEY_pidfile} ]; then
147                 lustre_update
148                 if [ $? -eq 0 ]; then
149                     return $OCF_SUCCESS
150                 fi
151                 return $OCF_ERR_GENERIC
152         fi
153         return $OCF_NOT_RUNNING
154 }
155
156
157 lustre_check() {
158         active=0
159
160         # added head -1 due the LU-7486
161         l_out=`lctl get_param -n health_check | head -1 |grep -w healthy 2>&1`; rc=$?
162
163         case $rc in
164             0) active=`expr $active + 1`;;
165             1) lustre_conditional_log warn "Lustre is not healthy: $l_out";;
166             *) ocf_log err "Unexpected result for 'lctl get_param health_check' $rc: $l_out";;
167         esac
168         return $active
169 }
170
171 lustre_update() {
172         lustre_check
173         active=$?
174
175         attrd_updater -n $OCF_RESKEY_name -v $active -d $OCF_RESKEY_dampen $attrd_options
176         rc=$?
177         case $rc in
178                 0) lustre_conditional_log debug "Updated $OCF_RESKEY_name = $active" ;;
179                 *) ocf_log warn "Could not update $OCF_RESKEY_name = $active: rc=$rc";;
180         esac
181         if [ $rc -ne 0 ]; then
182                 return $rc
183         fi
184         return 0
185 }
186
187 if [ ${OCF_RESKEY_CRM_meta_globally_unique} = "false" ]; then
188         : ${OCF_RESKEY_pidfile:="$HA_VARRUN/healthLUSTRE-${OCF_RESKEY_name}"}
189 else
190         : ${OCF_RESKEY_pidfile:="$HA_VARRUN/healthLUSTRE-${OCF_RESOURCE_INSTANCE}"}
191 fi
192
193 attrd_options='-q'
194 if ocf_is_true ${OCF_RESKEY_debug} ; then
195     attrd_options=''
196 fi
197
198 : ${OCF_RESKEY_name:="lustred"}
199 : ${OCF_RESKEY_debug:="false"}
200
201 case $__OCF_ACTION in
202 meta-data)      meta_data
203                 exit $OCF_SUCCESS
204                 ;;
205 start)          lustre_start;;
206 stop)           lustre_stop;;
207 monitor)        lustre_monitor;;
208 reload)         lustre_start;;
209 validate-all)   lustre_usage
210                 exit $OCF_SUCCESS
211                 ;;
212 usage|help)     lustre_usage
213                 exit $OCF_SUCCESS
214                 ;;
215 *)              lustre_usage
216                 exit $OCF_ERR_UNIMPLEMENTED
217                 ;;
218 esac