4
# Description: Manages nfs server as OCF resource
6
# License: GNU General Public License v2 (GPLv2) and later
8
if [ -n "$OCF_DEBUG_LIBRARY" ]; then
11
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
12
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
15
DEFAULT_INIT_SCRIPT="/etc/init.d/nfsserver"
16
DEFAULT_NOTIFY_CMD="/sbin/sm-notify"
18
nfsserver_meta_data() {
21
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
22
<resource-agent name="nfsserver">
23
<version>1.0</version>
26
Nfsserver helps to manage the Linux nfs server as a failover-able resource in Linux-HA.
27
It depends on Linux specific NFS implementation details, so is considered not portable to other platforms yet.
30
<shortdesc lang="en">Manages an NFS server</shortdesc>
34
<parameter name="nfs_init_script" unique="0" required="0">
36
The default init script shipped with the Linux distro.
37
The nfsserver resource agent offloads the start/stop/monitor work to the init script because the procedure to start/stop/monitor nfsserver varies on different Linux distro.
40
Init script for nfsserver
42
<content type="string" default="$DEFAULT_INIT_SCRIPT" />
45
<parameter name="nfs_notify_cmd" unique="0" required="0">
47
The tool to send out NSM reboot notification.
48
Failover of nfsserver can be considered as rebooting to different machines.
49
The nfsserver resource agent use this command to notify all clients about the happening of failover.
52
The tool to send out notification.
54
<content type="string" default="$DEFAULT_NOTIFY_CMD" />
57
<parameter name="nfs_shared_infodir" unique="0" required="1">
59
The nfsserver resource agent will save nfs related information in this specific directory.
60
And this directory must be able to fail-over before nfsserver itself.
63
Directory to store nfs server related information.
65
<content type="string" default="" />
68
<parameter name="nfs_ip" unique="0" required="1">
70
The floating IP address used to access the nfs service
75
<content type="string"/>
81
<action name="start" timeout="40" />
82
<action name="stop" timeout="20s" />
83
<action name="monitor" depth="0" timeout="20s" interval="10" />
84
<action name="meta-data" timeout="5" />
85
<action name="validate-all" timeout="30" />
95
usage: $0 {start|stop|monitor|status|validate-all|meta-data}
104
case $__OCF_ACTION in
105
meta-data) nfsserver_meta_data
108
usage|help) nfsserver_usage
115
fp="$OCF_RESKEY_nfs_shared_infodir"
116
: ${OCF_RESKEY_nfs_init_script="$DEFAULT_INIT_SCRIPT"}
117
: ${OCF_RESKEY_nfs_notify_cmd="$DEFAULT_NOTIFY_CMD"}
122
${OCF_RESKEY_nfs_init_script} status > $fn 2>&1
124
ocf_log debug `cat $fn`
127
#Adapte LSB status code to OCF return code
128
if [ $rc -eq 0 ]; then
130
elif [ $rc -eq 3 ]; then
131
return $OCF_NOT_RUNNING
133
return $OCF_ERR_GENERIC
139
[ -d "$fp" ] || mkdir -p $fp
140
[ -d "$fp/rpc_pipefs" ] || mkdir -p $fp/rpc_pipefs
141
[ -d "$fp/sm" ] || mkdir -p $fp/sm
142
[ -d "$fp/sm.ha" ] || mkdir -p $fp/sm.ha
143
[ -d "$fp/sm.bak" ] || mkdir -p $fp/sm.bak
144
[ -d "$fp/v4recovery" ] || mkdir -p $fp/v4recovery
149
mount | grep -q "$1 on $2 type none (.*bind)"
155
if is_bound $fp /var/lib/nfs; then
156
ocf_log debug "$fp is already bound to /var/lib/nfs"
159
mount --bind $fp /var/lib/nfs
164
if `mount | grep -q "rpc_pipefs on /var/lib/nfs/rpc_pipefs"`; then
165
umount /var/lib/nfs/rpc_pipefs
167
if is_bound $fp /var/lib/nfs; then
177
rm -f /var/lib/nfs/sm.ha/* > /dev/null 2>&1
178
cp -f /var/lib/nfs/sm/* /var/lib/nfs/sm.ha > /dev/null 2>&1
180
ocf_log info "Starting NFS server ..."
183
${OCF_RESKEY_nfs_init_script} start > $fn 2>&1
185
ocf_log debug `cat $fn`
188
if [ $rc -ne 0 ]; then
189
ocf_log err "Failed to start NFS server"
193
#Notify the nfs server has been moved or rebooted
194
#The init script do that already, but with the hostname, which may be ignored by client
195
#we have to do it again with the nfs_ip
197
echo $OCF_RESKEY_nfs_notify_cmd | grep -qws rpc.statd &&
199
${OCF_RESKEY_nfs_notify_cmd} $opts $OCF_RESKEY_nfs_ip -P /var/lib/nfs/sm.ha
201
ocf_log info "NFS server started"
207
ocf_log info "Stopping NFS server ..."
210
${OCF_RESKEY_nfs_init_script} stop > $fn 2>&1
212
ocf_log debug `cat $fn`
215
if [ $rc -eq 0 ]; then
217
ocf_log info "NFS server stopped"
220
ocf_log err "Failed to stop NFS server"
224
nfsserver_validate ()
226
check_binary ${OCF_RESKEY_nfs_init_script}
227
check_binary ${OCF_RESKEY_nfs_notify_cmd}
229
if [ -z ${OCF_RESKEY_nfs_ip} ]; then
230
ocf_log err "nfs_ip not set"
231
exit $OCF_ERR_CONFIGURED
234
if [ x = "x$OCF_RESKEY_nfs_shared_infodir" ]; then
235
ocf_log err "nfs_shared_infodir not set"
236
exit $OCF_ERR_CONFIGURED
242
if [ -n "$OCF_RESKEY_CRM_meta_clone" ]; then
243
ocf_log err "THIS RA DO NOT SUPPORT CLONE MODE!"
244
exit $OCF_ERR_CONFIGURED
249
case $__OCF_ACTION in
250
start) nfsserver_start
254
monitor) nfsserver_monitor
256
validate-all) nfsserver_validate
259
exit $OCF_ERR_UNIMPLEMENTED