| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (c) 2014 Anand Subramanian [email protected] |
| 4 |
# Copyright (c) 2015 Red Hat Inc. |
| 5 |
# All Rights Reserved. |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of version 2 of the GNU General Public License as |
| 9 |
# published by the Free Software Foundation. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it would be useful, but |
| 12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 |
# |
| 15 |
# Further, this software is distributed without any warranty that it is |
| 16 |
# free of the rightful claim of any third person regarding infringement |
| 17 |
# or the like. Any license provided herein, whether implied or |
| 18 |
# otherwise, applies only to this software file. Patent licenses, if |
| 19 |
# any, provided herein do not apply to combinations of this program with |
| 20 |
# other software, or any other product whatsoever. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU General Public License |
| 23 |
# along with this program; if not, write the Free Software Foundation, |
| 24 |
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 25 |
# |
| 26 |
# |
| 27 |
|
| 28 |
# Initialization: |
| 29 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} |
| 30 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs |
| 31 |
|
| 32 |
if [ -n "$OCF_DEBUG_LIBRARY" ]; then |
| 33 |
. $OCF_DEBUG_LIBRARY |
| 34 |
else |
| 35 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} |
| 36 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs |
| 37 |
fi |
| 38 |
|
| 39 |
OCF_RESKEY_grace_active_default="grace-active" |
| 40 |
: ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}} |
| 41 |
|
| 42 |
ganesha_meta_data() { |
| 43 |
cat <<END |
| 44 |
<?xml version="1.0"?> |
| 45 |
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> |
| 46 |
<resource-agent name="ganesha_grace"> |
| 47 |
<version>1.0</version> |
| 48 |
|
| 49 |
<longdesc lang="en"> |
| 50 |
This Linux-specific resource agent acts as a dummy |
| 51 |
resource agent for nfs-ganesha. |
| 52 |
</longdesc> |
| 53 |
|
| 54 |
<shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc> |
| 55 |
|
| 56 |
<parameters> |
| 57 |
<parameter name="grace_active"> |
| 58 |
<longdesc lang="en">NFS-Ganesha grace active attribute</longdesc> |
| 59 |
<shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc> |
| 60 |
<content type="string" default="grace-active" /> |
| 61 |
</parameter> |
| 62 |
</parameters> |
| 63 |
|
| 64 |
<actions> |
| 65 |
<action name="start" timeout="40s" /> |
| 66 |
<action name="stop" timeout="40s" /> |
| 67 |
<action name="status" timeout="20s" interval="60s" /> |
| 68 |
<action name="monitor" depth="0" timeout="10s" interval="5s" /> |
| 69 |
<action name="notify" timeout="10s" /> |
| 70 |
<action name="meta-data" timeout="20s" /> |
| 71 |
</actions> |
| 72 |
</resource-agent> |
| 73 |
END |
| 74 |
|
| 75 |
return ${OCF_SUCCESS} |
| 76 |
} |
| 77 |
|
| 78 |
ganesha_grace_usage() { |
| 79 |
echo "ganesha.nfsd USAGE" |
| 80 |
} |
| 81 |
|
| 82 |
# Make sure meta-data and usage always succeed |
| 83 |
case $__OCF_ACTION in |
| 84 |
meta-data) ganesha_meta_data |
| 85 |
exit ${OCF_SUCCESS} |
| 86 |
;; |
| 87 |
usage|help) ganesha_usage |
| 88 |
exit ${OCF_SUCCESS} |
| 89 |
;; |
| 90 |
*) |
| 91 |
;; |
| 92 |
esac |
| 93 |
|
| 94 |
ganesha_grace_start() |
| 95 |
{ |
| 96 |
local rc=${OCF_ERR_GENERIC} |
| 97 |
local host=$(ocf_local_nodename) |
| 98 |
|
| 99 |
ocf_log debug "ganesha_grace_start ${host}" |
| 100 |
# give ganesha_mon RA a chance to set the attr first |
| 101 |
# I mislike the sleep, but it's not clear that looping |
| 102 |
# with a small sleep is necessarily better |
| 103 |
# start has a 40sec timeout, so a 5sec sleep here is okay |
| 104 |
sleep 5 |
| 105 |
attr=$(attrd_updater --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null) |
| 106 |
if [ $? -ne 0 ]; then |
| 107 |
ocf_log info "grace start: attrd_updater --query --node=${host} --name=${OCF_RESKEY_grace_active} failed" |
| 108 |
fi |
| 109 |
|
| 110 |
# Three possibilities: |
| 111 |
# 1. There is no attribute at all and attrd_updater returns |
| 112 |
# a zero length string. This happens when |
| 113 |
# ganesha_mon::monitor hasn't run at least once to set |
| 114 |
# the attribute. The assumption here is that the system |
| 115 |
# is coming up. We pretend, for now, that the node is |
| 116 |
# healthy, to allow the system to continue coming up. |
| 117 |
# It will cure itself in a few seconds |
| 118 |
# 2. There is an attribute, and it has the value "1"; this |
| 119 |
# node is healthy. |
| 120 |
# 3. There is an attribute, but it has no value or the value |
| 121 |
# "0"; this node is not healthy. |
| 122 |
|
| 123 |
# case 1 |
| 124 |
if [[ -z "${attr}" ]]; then |
| 125 |
ocf_log debug "grace start: returning success case 1" |
| 126 |
return ${OCF_SUCCESS} |
| 127 |
fi |
| 128 |
|
| 129 |
# case 2 |
| 130 |
if [[ "${attr}" = *"host=\"${host}\" value=\"1\"" ]]; then |
| 131 |
ocf_log debug "grace start: returning success case 2" |
| 132 |
return ${OCF_SUCCESS} |
| 133 |
fi |
| 134 |
|
| 135 |
# case 3 |
| 136 |
ocf_log info "grace start returning: not running case 3 (${attr})" |
| 137 |
return ${OCF_NOT_RUNNING} |
| 138 |
} |
| 139 |
|
| 140 |
ganesha_grace_stop() |
| 141 |
{ |
| 142 |
|
| 143 |
ocf_log debug "ganesha_grace_stop()" |
| 144 |
return ${OCF_SUCCESS} |
| 145 |
} |
| 146 |
|
| 147 |
ganesha_grace_notify() |
| 148 |
{ |
| 149 |
# since this is a clone RA we should only ever see pre-start |
| 150 |
# or post-stop |
| 151 |
mode="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}" |
| 152 |
case "${mode}" in |
| 153 |
pre-start | post-stop) |
| 154 |
dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname} |
| 155 |
if [ $? -ne 0 ]; then |
| 156 |
ocf_log info "dbus-send --print-reply --system --dest=org.ganesha.nfsd /org/ganesha/nfsd/admin org.ganesha.nfsd.admin.grace string:${OCF_RESKEY_CRM_meta_notify_stop_uname} failed" |
| 157 |
fi |
| 158 |
;; |
| 159 |
esac |
| 160 |
|
| 161 |
return ${OCF_SUCCESS} |
| 162 |
} |
| 163 |
|
| 164 |
ganesha_grace_monitor() |
| 165 |
{ |
| 166 |
local host=$(ocf_local_nodename) |
| 167 |
|
| 168 |
ocf_log debug "ganesha_grace_monitor ${host}" |
| 169 |
|
| 170 |
attr=$(attrd_updater --query --node=${host} --name=${OCF_RESKEY_grace_active} 2> /dev/null) |
| 171 |
if [ $? -ne 0 ]; then |
| 172 |
ocf_log info "attrd_updater --query --node=${host} --name=${OCF_RESKEY_grace_active} failed" |
| 173 |
fi |
| 174 |
|
| 175 |
# if there is no attribute (yet), maybe it's because |
| 176 |
# this RA started before ganesha_mon (nfs-mon) has had |
| 177 |
# chance to create it. In which case we'll pretend |
| 178 |
# everything is okay this time around |
| 179 |
if [[ -z "${attr}" ]]; then |
| 180 |
ocf_log debug "grace monitor: returning success case 1" |
| 181 |
return ${OCF_SUCCESS} |
| 182 |
fi |
| 183 |
|
| 184 |
if [[ "${attr}" = *"host=\"${host}\" value=\"1\"" ]]; then |
| 185 |
ocf_log debug "grace monitor: returning success case 2" |
| 186 |
return ${OCF_SUCCESS} |
| 187 |
fi |
| 188 |
|
| 189 |
ocf_log info "grace monitor: returning not running case 3 (${attr})" |
| 190 |
return ${OCF_NOT_RUNNING} |
| 191 |
} |
| 192 |
|
| 193 |
ganesha_grace_validate() |
| 194 |
{ |
| 195 |
return ${OCF_SUCCESS} |
| 196 |
} |
| 197 |
|
| 198 |
ganesha_grace_validate |
| 199 |
|
| 200 |
# Translate each action into the appropriate function call |
| 201 |
case $__OCF_ACTION in |
| 202 |
start) ganesha_grace_start |
| 203 |
;; |
| 204 |
stop) ganesha_grace_stop |
| 205 |
;; |
| 206 |
status|monitor) ganesha_grace_monitor |
| 207 |
;; |
| 208 |
notify) ganesha_grace_notify |
| 209 |
;; |
| 210 |
*) ganesha_grace_usage |
| 211 |
exit ${OCF_ERR_UNIMPLEMENTED} |
| 212 |
;; |
| 213 |
esac |
| 214 |
|
| 215 |
rc=$? |
| 216 |
|
| 217 |
# The resource agent may optionally log a debug message |
| 218 |
ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc" |
| 219 |
exit $rc |