Hi all,

  I send an implementation of nfsserver to the user list a while ago.
As there's no interests show around, I resend it here as a patch.

  Please consider it for upstream. Thanks.
# HG changeset patch
# User [EMAIL PROTECTED]
# Date 1222583225 -28800
# Node ID e6f8dd8207e33bedc0d8e382be518613c01a939f
# Parent  3127c6aa43a22db99d6ad2da9667c303613f55d9
Add resource agent for nfs server

diff -r 3127c6aa43a2 -r e6f8dd8207e3 resources/OCF/Makefile.am
--- a/resources/OCF/Makefile.am	Fri Sep 26 16:45:51 2008 +0200
+++ b/resources/OCF/Makefile.am	Sun Sep 28 14:27:05 2008 +0800
@@ -66,6 +66,7 @@
 			ManageRAID	\
 			ManageVE	\
 			mysql		\
+			nfsserver	\
 			o2cb		\
 			oracle		\
 			oralsnr		\
diff -r 3127c6aa43a2 -r e6f8dd8207e3 resources/OCF/nfsserver
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/OCF/nfsserver	Sun Sep 28 14:27:05 2008 +0800
@@ -0,0 +1,224 @@
+#!/bin/sh
+# nfsserver
+# Description: Manages nfs server as OCF resource
+# by [EMAIL PROTECTED]
+# License: GNU General Public License 2 (GPL2)
+
+#set -x
+
+if [ -n "$OCF_DEBUG_LIBRARY" ]; then
+    . $OCF_DEBUG_LIBRARY
+else
+    . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
+fi
+
+nfsserver_meta_data() {
+	cat <<END
+<?xml version="1.0"?>
+<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
+<resource-agent name="nfsserver">
+<version>1.0</version>
+
+<longdesc lang="en">
+Nfsserver represent the nfsserver in the system.
+</longdesc>
+
+<shortdesc lang="en">
+Nfsserver represent the nfsserver in the system.
+</shortdesc>
+
+<parameters>
+
+<parameter name="nfs_shared_path" unique="0" required="1">
+<longdesc lang="en">
+The directory which physically shared among all servers. Typically, it's a filesystem on a shared storage.
+</longdesc>
+<shortdesc lang="en">
+Path shared among servers.
+</shortdesc>
+<content type="string" default="" />
+</parameter>
+
+<parameter name="nfs_info_path" unique="0" required="1">
+<longdesc lang="en">
+The relative directory where to store nfs related information. It defaults to .nfsserver.
+</longdesc>
+<shortdesc lang="en">
+The directory to store nfs information.
+</shortdesc>
+<content type="string" default=".nfsserver" />
+</parameter>
+
+<parameter name="sharedip" unique="0" required="1">
+<longdesc lang="en">
+The IP address to access the nfs service
+</longdesc>
+<shortdesc lang="en">
+IP address.
+</shortdesc>
+<content type="string" default="*" />
+</parameter>
+
+</parameters>
+
+<actions>
+<action name="start"   timeout="40" />
+<action name="stop"    timeout="10" />
+<action name="status"   timeout="90" />
+<action name="monitor" depth="0"  timeout="20" interval="10" start-delay="1m"/>
+<action name="meta-data"  timeout="5" />
+<action name="validate-all"  timeout="30" />
+</actions>
+</resource-agent>
+END
+
+return $OCF_SUCCESS
+}
+
+nfsserver_usage() {
+	cat <<END
+		usage: $0 {start|stop|monitor|status|validate-all|meta-data}
+END
+}
+
+
+if [ $# -ne 1 ]; then
+	nfsserver_usage
+	exit $OCF_ERR_ARGS
+fi
+
+case $__OCF_ACTION in
+	meta-data)  nfsserver_meta_data
+		exit $OCF_SUCCESS
+		;;
+	usage|help) nfsserver_usage
+		exit $OCF_SUCCESS
+		;;
+	*)
+		;;	
+esac
+
+nfsserver_monitor ()
+{
+	/etc/init.d/nfsserver status
+	rc=$?
+	if [ $rc == 0 ]; then
+		return $OCF_SUCCESS
+	fi
+	return $OCF_NOT_RUNNING	
+}
+
+nfsserver_daemon_start ()
+{
+	ocf_log info "Starting NFS Server via init script"
+	/etc/init.d/nfsserver start
+	if [ $? -ne 0 ]; then
+		ocf_log err "Failed to start NFS Server via init script"
+		return 1
+	fi
+	ocf_log info "NFS Server started via init script"
+	return 0
+}
+
+nfsserver_daemon_stop ()
+{
+	ocf_log info "Stopping NFS Server via init script"
+	/etc/init.d/nfsserver stop
+	if [ $? -ne 0 ]; then
+		ocf_log err "Failed to stop NFS Server via init script"
+		return 1
+	fi
+	ocf_log info "NFS Server stopped via init script"
+	return 0
+}
+
+prepare_directory ()
+{
+	declare fp="$OCF_RESKEY_nfs_shared_path/$OCF_RESKEY_nfs_info_path"
+
+	[ -d "$fp" ] || mkdir -p fp
+	[ -d "$fp/rpc_pipefs" ] || mkdir -p $fp/rpc_pipefs
+	[ -d "$fp/sm" ] || mkdir -p $fp/sm
+	[ -d "$fp/sm.ha" ] || mkdir -p $fp/sm.ha
+	[ -d "$fp/sm.bak" ] || mkdir -p $fp/sm.bak
+	[ -d "$fp/v4recovery" ] || mkdir -p $fp/v4recovery
+}
+
+is_bound ()
+{
+	mount | grep -q "$1 on $2 type none (.*bind)"
+	return $?
+}
+
+prepare_tree ()
+{
+	declare fp="$OCF_RESKEY_nfs_shared_path/$OCF_RESKEY_nfs_info_path"
+	if is_bound $fp /var/lib/nfs; then
+		ocf_log debug "$fp is already bound to /var/lib/nfs"
+		return 0
+	fi
+	mount --bind $fp /var/lib/nfs
+}
+
+unprepare_tree ()
+{
+	declare fp="$OCF_RESKEY_nfs_shared_path/$OCF_RESKEY_nfs_info_path"
+	if is_bound $fp /var/lib/nfs; then
+		umount /var/lib/nfs
+	fi
+}
+
+nfsserver_start ()
+{
+	prepare_direcotry
+	prepare_tree
+
+	cp -f /var/lib/nfs/sm/* /var/lib/nfs/sm.ha 2> /dev/null
+	nfsserver_daemon_start						
+	rc=$?
+
+	#Notify the nfs server has been moved or rebooted
+	#The init script do that once, and we do it again with the sharedip anyway
+	sm-notify -v $OCF_RESKEY_sharedip -P /var/lib/nfs/sm.ha
+	rm -f /var/lib/nfs/sm.ha/* 2> /dev/null
+
+	if [ $rc == 0 ]; then
+		return $OCF_SUCCESS
+	fi
+	return $OCF_ERR_GENERIC
+}
+
+nfsserver_stop ()
+{
+	nfsserver_daemon_stop
+	rc=$?
+	if [ $rc == 0 ]; then
+		unprepare_tree 
+		return $OCF_SUCCESS
+	fi
+	return $OCF_ERR_GENERIC
+}
+
+nfsserver_validate ()
+{
+	if [ -x /etc/init.d/nfsserver && -x /usr/sbin/sm-notify ]; then
+		return $OCF_SUCCESS
+	else
+		return $OCF_ERR_INSTALLED
+	fi
+}
+
+case $__OCF_ACTION in
+	start)      nfsserver_start
+		;;
+	stop)       nfsserver_stop
+		;;
+	monitor)    nfsserver_monitor
+		;;
+	validate-all)   nfsserver_validate
+		;;
+	*)      nfsserver_usage
+	exit $OCF_ERR_UNIMPLEMENTED
+	;;
+esac
+
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to