| 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_ha_vol_mnt_default="/run/gluster/shared_storage" |
| 40 |
: ${OCF_RESKEY_ha_vol_mnt=${OCF_RESKEY_ha_vol_mnt_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_nfsd"> |
| 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="ha_vol_mnt"> |
| 58 |
<longdesc lang="en">HA State Volume Mount Point</longdesc> |
| 59 |
<shortdesc lang="en">HA_State Volume Mount Point</shortdesc> |
| 60 |
<content type="string" default="" /> |
| 61 |
</parameter> |
| 62 |
</parameters> |
| 63 |
|
| 64 |
<actions> |
| 65 |
<action name="start" timeout="5s" /> |
| 66 |
<action name="stop" timeout="5s" /> |
| 67 |
<action name="status" depth="0" timeout="5s" interval="0" /> |
| 68 |
<action name="monitor" depth="0" timeout="5s" interval="0" /> |
| 69 |
<action name="meta-data" timeout="20s" /> |
| 70 |
</actions> |
| 71 |
</resource-agent> |
| 72 |
END |
| 73 |
|
| 74 |
return ${OCF_SUCCESS} |
| 75 |
} |
| 76 |
|
| 77 |
ganesha_nfsd_usage() { |
| 78 |
echo "ganesha.nfsd USAGE" |
| 79 |
} |
| 80 |
|
| 81 |
# Make sure meta-data and usage always succeed |
| 82 |
case $__OCF_ACTION in |
| 83 |
meta-data) ganesha_meta_data |
| 84 |
exit ${OCF_SUCCESS} |
| 85 |
;; |
| 86 |
usage|help) ganesha_usage |
| 87 |
exit ${OCF_SUCCESS} |
| 88 |
;; |
| 89 |
*) |
| 90 |
;; |
| 91 |
esac |
| 92 |
|
| 93 |
ganesha_nfsd_start() |
| 94 |
{ |
| 95 |
local long_host=$(hostname) |
| 96 |
|
| 97 |
if [[ -d /var/lib/nfs ]]; then |
| 98 |
mv /var/lib/nfs /var/lib/nfs.backup |
| 99 |
if [ $? -ne 0 ]; then |
| 100 |
ocf_log notice "mv /var/lib/nfs /var/lib/nfs.backup failed" |
| 101 |
fi |
| 102 |
ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs |
| 103 |
if [ $? -ne 0 ]; then |
| 104 |
ocf_log notice "ln -s ${OCF_RESKEY_ha_vol_mnt}/nfs-ganesha/${long_host}/nfs /var/lib/nfs failed" |
| 105 |
fi |
| 106 |
fi |
| 107 |
|
| 108 |
return ${OCF_SUCCESS} |
| 109 |
} |
| 110 |
|
| 111 |
ganesha_nfsd_stop() |
| 112 |
{ |
| 113 |
|
| 114 |
if [ -L /var/lib/nfs -a -d /var/lib/nfs.backup ]; then |
| 115 |
rm -f /var/lib/nfs |
| 116 |
if [ $? -ne 0 ]; then |
| 117 |
ocf_log notice "rm -f /var/lib/nfs failed" |
| 118 |
fi |
| 119 |
mv /var/lib/nfs.backup /var/lib/nfs |
| 120 |
if [ $? -ne 0 ]; then |
| 121 |
ocf_log notice "mv /var/lib/nfs.backup /var/lib/nfs failed" |
| 122 |
fi |
| 123 |
fi |
| 124 |
|
| 125 |
return ${OCF_SUCCESS} |
| 126 |
} |
| 127 |
|
| 128 |
ganesha_nfsd_monitor() |
| 129 |
{ |
| 130 |
# pacemaker checks to see if RA is already running before starting it. |
| 131 |
# if we return success, then it's presumed it's already running and |
| 132 |
# doesn't need to be started, i.e. invoke the start action. |
| 133 |
# return something other than success to make pacemaker invoke the |
| 134 |
# start action |
| 135 |
if [[ -L /var/lib/nfs ]]; then |
| 136 |
return ${OCF_SUCCESS} |
| 137 |
fi |
| 138 |
return ${OCF_NOT_RUNNING} |
| 139 |
} |
| 140 |
|
| 141 |
ganesha_nfsd_validate() |
| 142 |
{ |
| 143 |
return ${OCF_SUCCESS} |
| 144 |
} |
| 145 |
|
| 146 |
ganesha_nfsd_validate |
| 147 |
|
| 148 |
# ocf_log notice "ganesha_nfsd ${OCF_RESOURCE_INSTANCE} $__OCF_ACTION" |
| 149 |
|
| 150 |
# Translate each action into the appropriate function call |
| 151 |
case $__OCF_ACTION in |
| 152 |
start) ganesha_nfsd_start |
| 153 |
;; |
| 154 |
stop) ganesha_nfsd_stop |
| 155 |
;; |
| 156 |
status|monitor) ganesha_nfsd_monitor |
| 157 |
;; |
| 158 |
*) ganesha_nfsd_usage |
| 159 |
exit ${OCF_ERR_UNIMPLEMENTED} |
| 160 |
;; |
| 161 |
esac |
| 162 |
|
| 163 |
rc=$? |
| 164 |
|
| 165 |
# The resource agent may optionally log a debug message |
| 166 |
ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc" |
| 167 |
exit $rc |