home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / examples / heartbeat / PVFS2 < prev    next >
Text File  |  2008-11-20  |  7KB  |  340 lines

  1. #!/bin/sh
  2. #
  3. #    High-Availability PVFS2 control script
  4. #
  5. # Based on Apache OCF script included in heartbeat package, authored by Alan
  6. # Robertson and Sun Jiang Dong.
  7. #
  8. # License:      GNU General Public License (GPL)
  9. #
  10. # PVFS2
  11. #
  12. # Description:    starts/stops PVFS2 servers.
  13. #
  14. # OCF parameters (required in cib):
  15. #  OCF_RESKEY_fsconfig
  16. #  OCF_RESKEY_port
  17. #  OCF_RESKEY_pidfile
  18. #  OCF_RESKEY_ip
  19. #  OCF_RESKEY_alias
  20.  
  21. # example values:
  22. #OCF_RESKEY_fsconfig=/root/simple.conf
  23. #OCF_RESKEY_port=3334
  24. #OCF_RESKEY_pidfile=/tmp/pvfs2-server.pid
  25. #OCF_RESKEY_ip=virtual1
  26. #OCF_RESKEY_alias=virtual1
  27.  
  28. VARRUN=/var/run
  29.  
  30. # newer versions of heartbeat have moved the ocf-shellfuncs  file
  31. if [ -f /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs ] ; then
  32. . /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
  33. else
  34. . /usr/lib/heartbeat/ocf-shellfuncs
  35. fi
  36.  
  37. #######################################################################
  38. #
  39. #    Configuration options - usually you don't need to change these
  40. #
  41. #######################################################################
  42. #
  43. PVFS2D=/usr/local/sbin/pvfs2-server
  44. PVFS2CHECK=/usr/local/bin/pvfs2-check-server
  45.  
  46.  
  47. #    End of Configuration options
  48. #######################################################################
  49.  
  50. CMD=`basename $0`
  51.  
  52. #    The config-file-pathname is the pathname to the configuration
  53. #    file for this web server.  Various appropriate defaults are
  54. #    assumed if no config file is specified.  If this command is
  55. #    invoked as *IBM*, then the default config file name is
  56. #    $DEFAULT_IBMCONFIG, otherwise the default config file
  57. #    will be $DEFAULT_NORMCONFIG.
  58. usage() {
  59.   cat <<-!
  60. usage: $0 action
  61.  
  62. action:
  63.     start    start the PVFS2 server
  64.  
  65.     stop    stop the PVFS2 server
  66.  
  67.     status    return the status of PVFS2 server, run or down
  68.  
  69.     monitor  return TRUE if the server appears to be working.
  70.  
  71.     meta-data    show meta data message
  72.  
  73.     validate-all    validate the instance parameters
  74.     !
  75.   exit $OCF_ERR_ARGS
  76. }
  77.  
  78. #
  79. #    Check if the port is valid
  80. #
  81. CheckPort() {
  82.   ocf_is_decimal "$1" && [ $1 -gt 0 ]
  83. }
  84.  
  85. #
  86. # return TRUE if a process with given PID is running
  87. #
  88. ProcessRunning() {
  89.     PVFS2PID=$1
  90.     # Use /proc if it looks like it's here...
  91.     if
  92.       [ -d /proc -a -d /proc/1 ]
  93.     then
  94.        [ -d /proc/$PVFS2PID ]
  95.     else
  96.       #  This assumes we're running as root...
  97.       kill -0 "$PVFS2PID" >/dev/null 2>&1
  98.     fi
  99. }
  100.  
  101.  
  102. silent_status() {
  103.   if
  104.     [ -f $OCF_RESKEY_pidfile  ] 
  105.   then
  106.     ProcessRunning `cat $OCF_RESKEY_pidfile`
  107.   else
  108.     : No pid file
  109.     false
  110.   fi
  111. }
  112.  
  113. start_pvfs2() {
  114.    if validate_all_pvfs2; then
  115.       : OK
  116.    else
  117.       ocf_log err "Error parsing PVFS2 resource parameters"
  118.       exit $OCF_ERR_ARGS
  119.    fi
  120.  
  121.   if
  122.     silent_status
  123.   then
  124.     ocf_log info "$CMD already running (pid $PVFS2PID)"
  125.     return $OCF_SUCCESS
  126.   fi
  127.  
  128.   # set ulimit values
  129.   ulimit -n 100000 && ulimit -c unlimited
  130.  
  131.   # try to create storage space (ok if it fails)
  132.   $PVFS2D $OCF_RESKEY_fsconfig -a $OCF_RESKEY_alias -f
  133.  
  134.   # launch daemon
  135.   ocf_run $PVFS2D -p $OCF_RESKEY_pidfile -a $OCF_RESKEY_alias $OCF_RESKEY_fsconfig 
  136.   if
  137.     [ $? -ne 0 ]
  138.   then
  139.     ocf_log warn "pvfs2-server failed to start."
  140.     return $?
  141.   fi
  142.  
  143.   # wait a little bit
  144.   sleep 8
  145.  
  146.   # does the pidfile still exist (indicating that the server is still running?)
  147.   if
  148.     [ -a $OCF_RESKEY_pidfile ]
  149.   then
  150.     return $OCF_SUCCESS
  151.   else
  152.     ocf_log warn "pvfs2-server died after starting."
  153.     return $OCF_ERR_GENERIC
  154.   fi
  155. }
  156.  
  157. stop_pvfs2() {
  158.   if
  159.     silent_status
  160.   then
  161.     if
  162.       kill $PVFS2PID
  163.     then
  164.       tries=0
  165.       while
  166.         ProcessRunning $PVFS2PID &&
  167.         [ $tries -lt 10 ]
  168.       do
  169.         sleep 1
  170.         kill $PVFS2PID >/dev/null 2>&1
  171.         ocf_log info "Killing pvfs2-server PID $PVFS2PID"
  172.         tries=`expr $tries + 1`
  173.       done
  174.     else
  175.       ocf_log warn "Killing pvfs2-server PID $PVFS2PID FAILED."
  176.     fi
  177.     if
  178.       ProcessRunning $PVFS2PID
  179.     then
  180.       sleep 1
  181.       kill -9 $PVFS2PID >/dev/null 2>&1
  182.       ocf_log warn "Killing (-9) pvfs2-server PID $PVFS2PID"
  183.       sleep 5
  184.       if
  185.         ProcessRunning $PVFS2PID
  186.       then
  187.         ocf_log info "$CMD still running ($PVFS2PID)."
  188.         false
  189.       else
  190.         ocf_log info "$CMD stopped."
  191.       fi
  192.     else
  193.       ocf_log info "$CMD stopped."
  194.     fi
  195.   else
  196.     ocf_log info "$CMD is not running."
  197.   fi
  198. }
  199.  
  200. status_pvfs2() {
  201.   silent_status
  202.   rc=$?
  203.   if
  204.     [ $rc -eq 0 ]
  205.   then
  206.     ocf_log info "$CMD is running (pid $PVFS2PID)."
  207.     return $OCF_SUCCESS
  208.   else
  209.     ocf_log info "$CMD is stopped."
  210.     return $OCF_NOT_RUNNING
  211.   fi
  212. }
  213.  
  214.  
  215. monitor_pvfs2() {
  216.   if
  217.     silent_status
  218.   then
  219.     ocf_run $PVFS2CHECK -h $OCF_RESKEY_ip -f pvfs2-fs -n tcp -p $OCF_RESKEY_port
  220.   else
  221.     ocf_log info "$CMD not running"
  222.     return $OCF_NOT_RUNNING
  223.   fi
  224. }
  225.  
  226. metadata_pvfs2(){
  227.     cat <<END
  228. <?xml version="1.0"?>
  229. <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
  230. <resource-agent name="PVFS2">
  231. <version>1.0</version>
  232.  
  233. <longdesc lang="en">
  234. starts/stops PVFS2 servers.
  235. </longdesc>
  236. <shortdesc lang="en">starts/stops PVFS2 servers.</shortdesc>
  237.  
  238. <parameters>
  239. <parameter name="fsconfig" required="1">
  240. <longdesc lang="en">
  241. The full path name of file system config file.
  242. </longdesc>
  243. <shortdesc lang="en">fs config file path</shortdesc>
  244. </parameter>
  245.  
  246. <parameter name="port" required="1">
  247. <longdesc lang="en">
  248. Port number that server will listen on.
  249. </longdesc>
  250. <shortdesc lang="en">server port number</shortdesc>
  251. </parameter>
  252.  
  253. <parameter name="pidfile" required="1">
  254. <longdesc lang="en">
  255. The full path name of the server pid file.
  256. </longdesc>
  257. <shortdesc lang="en">server pid file</shortdesc>
  258. </parameter>
  259.  
  260. <parameter name="ip" required="1">
  261. <longdesc lang="en">
  262. Virtual ip address that the server will run on.
  263. </longdesc>
  264. <shortdesc lang="en">virtual IP address</shortdesc>
  265. </parameter>
  266.  
  267. <parameter name="alias" required="1">
  268. <longdesc lang="en">
  269. PVFS server alias to be passed to -a argument.
  270. </longdesc>
  271. <shortdesc lang="en">PVFS server alias</shortdesc>
  272. </parameter>
  273.  
  274. </parameters>
  275.  
  276. <actions>
  277. <action name="start"   timeout="90" />
  278. <action name="stop"    timeout="100" />
  279. <action name="status"  timeout="30" />
  280. <action name="monitor" depth="0"  timeout="20" interval="10" start-delay="1m" />
  281. <action name="meta-data"  timeout="5" />
  282. <action name="validate-all"  timeout="5" />
  283. </actions>
  284. </resource-agent>
  285. END
  286.  
  287.     exit $OCF_SUCCESS
  288. }
  289.  
  290. validate_all_pvfs2() {
  291.  
  292. # pidfile: make sure it is an absolute path
  293.    case $OCF_RESKEY_pidfile in
  294.       /*) ;;
  295.       *) ocf_log err "pidfile [$OCF_RESKEY_pidfile] should be an absolute path!" 
  296.          exit $OCF_ERR_ARGS
  297.          ;;
  298.    esac
  299.  
  300. # port: just make sure it is a decimal
  301.   if CheckPort $OCF_RESKEY_port; then
  302.     : OK
  303.   else
  304.     ocf_log err "Port number $OCF_RESKEY_port is invalid!"
  305.     exit $OCF_ERR_ARGS
  306.   fi
  307.  
  308. # fsconfig: make sure the file exists
  309. if [ ! -f $OCF_RESKEY_fsconfig ]; then
  310.    ocf_log err "Configuration file $OCF_RESKEY_fsconfig not found!"
  311.    exit $OCF_ERR_CONFIGURED
  312. fi
  313.  
  314. # make sure we can execute server daemon
  315. if [ ! -x $PVFS2D ]; then
  316.    ocf_log err "PVFS2 daemon $PVFS2D not found or is not an executable!"
  317.    exit $OCF_ERR_ARGS
  318. fi
  319.  
  320.   return $OCF_SUCCESS
  321. }
  322.  
  323. if
  324.   [ $# -eq 1 ]
  325. then
  326.   COMMAND=$1
  327. else
  328.   usage
  329. fi
  330.  
  331. case $COMMAND in
  332.   start)    start_pvfs2;;
  333.   stop)        stop_pvfs2;;
  334.   status)    status_pvfs2;;
  335.   monitor)    monitor_pvfs2;;
  336.   meta-data)    metadata_pvfs2;;
  337.   validate-all)    validate_all_pvfs2;;
  338.   *)        usage;;
  339. esac
  340.