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 / hardware-specific / PVFS2-notify < prev    next >
Text File  |  2008-04-24  |  6KB  |  261 lines

  1. #!/bin/sh
  2. #
  3. # Resource script for PVFS2_notify
  4. #
  5. # Provides a generic hook for sending notifications if a PVFS2 resource is
  6. # failed over to another node.
  7. #
  8. # Based on MailTo script by Alan Robertson <alanr@unix.sh>
  9. #
  10. # Description: Logs a message whenever a resource group starts or stops.
  11. #
  12. #      OCF parameters are as below:
  13. #               OCF_RESKEY_conf_dir
  14. #               OCF_RESKEY_title
  15. #               OCF_RESKEY_firsthost
  16. #
  17. # License:  GNU General Public License (GPL)
  18.  
  19. VARRUN=/var/run
  20. MAILTOFILE=$VARRUN/PVFS2_notify
  21. #######################################################################
  22. # Initialization:
  23.  
  24. # newer versions of heartbeat have moved the ocf-shellfuncs  file
  25. if [ -f /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs ] ; then
  26. . /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
  27. else
  28. . /usr/lib/heartbeat/ocf-shellfuncs
  29. fi
  30.  
  31. #######################################################################
  32.  
  33. ARGS="$0 $*"
  34.  
  35. us=`uname -n`
  36.  
  37. usage() {
  38.   echo "Usage: $0 {start|stop|status|monitor|meta-data|validate-all}"
  39. }
  40.  
  41. meta_data() {
  42.     cat <<END
  43. <?xml version="1.0"?>
  44. <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
  45. <resource-agent name="PVFS2_notify">
  46. <version>1.0</version>
  47.  
  48. <longdesc lang="en">
  49. This is a resource agent for PVFS2_notify. It logs or performs notification when a takeover occurs.
  50. </longdesc>
  51. <shortdesc lang="en">PVFS2_notify resource agent</shortdesc>
  52.  
  53. <parameters>
  54. <parameter name="firsthost" unique="0">
  55. <longdesc lang="en">
  56. Original host for this resource
  57. </longdesc>
  58. <shortdesc lang="en">Original host for this resource</shortdesc>
  59. <content type="string" default="" />
  60. </parameter>
  61.  
  62. <parameter name="title" unique="0">
  63. <longdesc lang="en">
  64. Title/identifier for the notification.
  65. </longdesc>
  66. <shortdesc lang="en">Subject</shortdesc>
  67. <content type="string" default="" />
  68. </parameter>
  69.  
  70. <parameter name="conf_dir" unique="0">
  71. <longdesc lang="en">
  72. Configuration directory for file system (PVFS2)
  73. </longdesc>
  74. <shortdesc lang="en">Configuration Directory</shortdesc>
  75. <content type="string" default="" />
  76. </parameter>
  77.  
  78. <parameter name="fsname" unique="0">
  79. <longdesc lang="en">
  80. Name of file system (PVFS2)
  81. </longdesc>
  82. <shortdesc lang="en">Name of file system</shortdesc>
  83. <content type="string" default="" />
  84. </parameter>
  85.  
  86. </parameters>
  87.  
  88. <actions>
  89. <action name="start" timeout="10" />
  90. <action name="stop" timeout="10" />
  91. <action name="status" depth="0" timeout="10" interval="10" start-delay="10" />
  92. <action name="monitor" depth="0" timeout="10" interval="10" start-delay="10" />
  93. <action name="meta-data" timeout="5" />
  94. <action name="validate-all" timeout="5" />
  95. </actions>
  96. </resource-agent>
  97. END
  98. }
  99.  
  100. MailProgram() {
  101.     mail -s "$1" "$email"  <<EOF
  102.         $Subject
  103.  
  104.         Command line was:
  105.         $ARGS
  106. EOF
  107.     return $?
  108. }
  109.  
  110. SubjectLine() {
  111.   case $1 in
  112.     ??*)    echo $1;;
  113.     *)        echo "Resource Group";;
  114.   esac
  115. }
  116.  
  117.  
  118. PVFS2_notifyStart() {
  119.     if [ -f ${conf_dir}/pvfs2-notify-quiet.flag ]
  120.     then
  121.         rm ${conf_dir}/pvfs2-notify-quiet.flag
  122.         touch $MAILTOFILE
  123.         return 0
  124.     fi
  125.  
  126.     if [ "$us" == "$firsthost" ]
  127.     then 
  128.         Subject="`SubjectLine $title` starting at `date` on its normal compute element $us"
  129.     else
  130.         Subject="`SubjectLine $title` starting at `date` on failover compute element $us (resource normally runs on $firsthost)"
  131.         `/usr/bin/fs-instance-alarm.pl --fs-name $fsname --ce $firsthost --type PVFS2_HA --msg "$title from $firsthost is starting on failover ce $us"`
  132.     fi
  133.  
  134.     #MailProgram "$Subject" $1
  135.     logger -t PVFS2 "$Subject"
  136.     
  137.     touch $MAILTOFILE
  138.     return $?
  139. }
  140.  
  141. PVFS2_notifyStop () {
  142.     if [ -f ${conf_dir}/pvfs2-notify-quiet.flag ]
  143.     then
  144.         rm ${conf_dir}/pvfs2-notify-quiet.flag
  145.         rm -f $MAILTOFILE
  146.         return 0
  147.     fi
  148.  
  149.     Subject="`SubjectLine $title` stopping at `date` on $us"
  150.  
  151.     #MailProgram "$Subject" $1
  152.     logger -t PVFS2 "$Subject"
  153.     rm -f $MAILTOFILE
  154.     return $?
  155. }
  156.  
  157. PVFS2_notifyStatus () {
  158.     ocf_log warn "Don't stat/monitor me! PVFS2_notify is a pseudo resource agent, so the status reported may be incorrect"
  159.  
  160.     if [ -f $MAILTOFILE ]; then
  161.         echo "running"
  162.         return $OCF_SUCCESS
  163.     else
  164.         echo "stopped"
  165.         return $OCF_NOT_RUNNING
  166.     fi
  167. }
  168.  
  169. PVFS2_notifyValidateAll () {
  170.  
  171. # $email may be a list of mail addresses separated by "," and " " and "\t"
  172. # normalize it for ease of parse
  173. #    local local_email=`echo $email | tr ",\t" " " | tr -s " "`
  174.  
  175. #    ocf_log info "[$local_email]"
  176. #    for item in "$local_email"
  177. #    do
  178. #        case $item in
  179. #        *?@?*)
  180. #        ;; #possible valid email address
  181. #        *)
  182. #        getent passwd $item >/dev/null
  183. #        if [ $? -eq 0 ]; then
  184. #        : OK, mail to $item@localhost.localdomain
  185. #        else
  186. #            ocf_log err "Invalid email address [$email]"
  187. #            exit $OCF_ERR_ARGS
  188. #        fi
  189. #        ;;
  190. #        esac
  191. #    done
  192.  
  193. # Any title is OK
  194.  
  195.     return $OCF_SUCCESS
  196. }
  197.  
  198. # See how we were called.
  199. #
  200. #    The order in which heartbeat provides arguments to resource
  201. #    scripts is broken.  It should be fixed.
  202. #
  203.  
  204. if
  205.   ( [ $# -ne 1 ] )
  206. then
  207.   usage
  208.   exit $OCF_ERR_GENERIC
  209. fi
  210.  
  211. case $1 in
  212.   meta-data)        meta_data
  213.             exit $OCF_SUCCESS
  214.             ;;
  215.     #    Not quite sure what to do with this one...
  216.     #    We aren't a continuously running service - so it's not clear
  217.     #
  218.   status|monitor)    PVFS2_notifyStatus
  219.             exit $?
  220.             ;;
  221.   usage)        usage
  222.             exit $OCF_SUCCESS
  223.             ;;
  224.   *)            ;;
  225. esac
  226.  
  227. if 
  228.   [ -z "$OCF_RESKEY_conf_dir" ]
  229. then
  230.   ocf_log err "PVFS2-notify must specify conf_dir!"
  231. #  usage
  232.   exit $OCF_ERR_GENERIC
  233. fi
  234.  
  235. if 
  236.   [ -z "$OCF_RESKEY_fsname" ]
  237. then
  238.   ocf_log err "PVFS2-notify must specify fsname!"
  239. #  usage
  240.   exit $OCF_ERR_GENERIC
  241. fi
  242.  
  243. conf_dir=$OCF_RESKEY_conf_dir
  244. fsname=$OCF_RESKEY_fsname
  245. title=$OCF_RESKEY_title
  246. firsthost=$OCF_RESKEY_firsthost
  247.  
  248. case $1 in
  249.   start)        PVFS2_notifyStart
  250.             ;;
  251.   stop)            PVFS2_notifyStop
  252.             ;;
  253.   validate-all)        PVFS2_notifyValidateAll
  254.             ;;
  255.   *)            usage
  256.             exit $OCF_ERR_UNIMPLEMENTED
  257.             ;;
  258. esac
  259. exit $?
  260.