/rgmanager/src/resources/nfsexport.sh

https://github.com/beekhof/cluster · Shell · 238 lines · 182 code · 44 blank · 12 comment · 19 complexity · 00aecbec2a36af6bcd3e073a865f5642 MD5 · raw file

  1. #!/bin/bash
  2. #
  3. # NFS Export Script. Handles starting/stopping clurmtabd and doing
  4. # the strange NFS stuff to get it to fail over properly.
  5. #
  6. LC_ALL=C
  7. LANG=C
  8. PATH=/bin:/sbin:/usr/bin:/usr/sbin
  9. export LC_ALL LANG PATH
  10. . $(dirname $0)/ocf-shellfuncs
  11. rmtabpid=""
  12. nfsop_arg=""
  13. rv=0
  14. meta_data()
  15. {
  16. cat <<EOT
  17. <?xml version="1.0" ?>
  18. <resource-agent name="nfsexport" version="rgmanager 2.0">
  19. <version>1.0</version>
  20. <longdesc lang="en">
  21. This defines an NFS export path. Generally, these are
  22. defined inline and implicitly; you should not have to
  23. configure one of these. All of the relevant information
  24. is inherited from the parent.
  25. </longdesc>
  26. <shortdesc lang="en">
  27. This defines an NFS export.
  28. </shortdesc>
  29. <parameters>
  30. <parameter name="name" primary="1">
  31. <longdesc lang="en">
  32. Descriptive name for this export. Generally, only
  33. one export is ever defined, and it's called "generic
  34. nfs export".
  35. </longdesc>
  36. <shortdesc lang="en">
  37. Name
  38. </shortdesc>
  39. <content type="string"/>
  40. </parameter>
  41. <parameter name="device" inherit="device">
  42. <longdesc lang="en">
  43. If you can see this, your GUI is broken.
  44. </longdesc>
  45. <shortdesc lang="en">
  46. If you can see this, your GUI is broken.
  47. </shortdesc>
  48. <content type="string"/>
  49. </parameter>
  50. <parameter name="path" inherit="mountpoint">
  51. <longdesc lang="en">
  52. If you can see this, your GUI is broken.
  53. </longdesc>
  54. <shortdesc lang="en">
  55. If you can see this, your GUI is broken.
  56. </shortdesc>
  57. <content type="string"/>
  58. </parameter>
  59. <parameter name="fsid" inherit="fsid">
  60. <longdesc lang="en">
  61. If you can see this, your GUI is broken.
  62. </longdesc>
  63. <shortdesc lang="en">
  64. If you can see this, your GUI is broken.
  65. </shortdesc>
  66. <content type="string"/>
  67. </parameter>
  68. </parameters>
  69. <actions>
  70. <action name="start" timeout="5"/>
  71. <action name="stop" timeout="5"/>
  72. <action name="recover" timeout="5"/>
  73. <!-- NFS Exports really don't do anything except provide a path
  74. for nfs clients. So, status and monitor are no-ops -->
  75. <action name="status" timeout="5" interval="1h"/>
  76. <action name="monitor" timeout="5" interval="1h"/>
  77. <action name="meta-data" timeout="5"/>
  78. <action name="validate-all" timeout="30"/>
  79. </actions>
  80. <special tag="rgmanager">
  81. <child type="nfsexport" forbid="1"/>
  82. <child type="nfsclient"/>
  83. </special>
  84. </resource-agent>
  85. EOT
  86. }
  87. verify_device()
  88. {
  89. if [ -z "$OCF_RESKEY_device" ]; then
  90. ocf_log err "No device or label specified."
  91. return $OCF_ERR_ARGS
  92. fi
  93. [ -b "$OCF_RESKEY_device" ] && return 0
  94. [ -b "`findfs $OCF_RESKEY_device`" ] && return 0
  95. ocf_log err "Device or label \"$OCF_RESKEY_device\" not valid"
  96. return $OCF_ERR_ARGS
  97. }
  98. verify_path()
  99. {
  100. if [ -z "$OCF_RESKEY_path" ]; then
  101. ocf_log err "No export path specified."
  102. return $OCF_ERR_ARGS
  103. fi
  104. [ -d "$OCF_RESKEY_path" ] && return 0
  105. ocf_log err "$OCF_RESKEY_path is not a directory"
  106. return $OCF_ERR_ARGS
  107. }
  108. verify_all()
  109. {
  110. declare -i ret=0
  111. verify_device || ret=$OCF_ERR_ARGS
  112. verify_path || ret=$OCF_ERR_ARGS
  113. return $ret
  114. }
  115. #
  116. # Check if the NFS daemons are running.
  117. #
  118. nfs_daemons_running()
  119. {
  120. declare NFS_DAEMONS="nfsd rpc.mountd rpc.statd"
  121. for daemon in $NFS_DAEMONS; do
  122. ps -ef | grep "$daemon" | grep -v grep >/dev/null 2>&1
  123. if [ $? -ne 0 ]; then
  124. ocf_log err \
  125. "NFS daemon $daemon is not running."
  126. ocf_log err \
  127. "Verify that the NFS service run level script is enabled."
  128. return 1
  129. fi
  130. done
  131. return 0
  132. }
  133. nfs_check()
  134. {
  135. declare junk
  136. if nfs_daemons_running; then
  137. return 0
  138. fi
  139. #
  140. # Don't restart daemons during status check.
  141. #
  142. if [ "$1" = "status" ]; then
  143. return 1;
  144. fi
  145. ocf_log err "Restarting NFS daemons"
  146. # Note restart does less than stop/start
  147. junk=$(/sbin/service nfslock stop)
  148. junk=$(/sbin/service nfslock start)
  149. junk=$(/sbin/service nfs stop)
  150. junk=$(/sbin/service nfs start)
  151. sleep 2
  152. if ! nfs_daemons_running; then
  153. ocf_log err "Failed restarting NFS daemons"
  154. return 1
  155. fi
  156. ocf_log notice "Successfully restarted NFS daemons"
  157. }
  158. case $1 in
  159. start)
  160. nfs_check start || exit 1
  161. rv=0
  162. ;;
  163. status|monitor)
  164. nfs_check status || exit 1
  165. rv=0
  166. ;;
  167. stop)
  168. nfs_check restart || exit 1
  169. rv=0
  170. ;;
  171. recover|restart)
  172. $0 stop || exit $OCF_ERR_GENERIC
  173. $0 start || exit $OCF_ERR_GENERIC
  174. rv=0
  175. ;;
  176. meta-data)
  177. meta_data
  178. rv=0
  179. ;;
  180. validate-all)
  181. verify_all
  182. rv=$?
  183. ;;
  184. *)
  185. echo "usage: $0 {start|status|monitor|stop|recover|restart|meta-data|validate-all}"
  186. exit $OCF_ERR_UNIMPLEMENTED
  187. ;;
  188. esac
  189. exit $rv