"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/ganesha/ocf/ganesha_mon" (16 Sep 2020, 6893 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #
    3 # Copyright (c) 2014 Anand Subramanian anands@redhat.com
    4 # Copyright (c) 2015 Red Hat Inc.
    5 #                    All Rights Reserved.
    6 #
    7 # This program is free software; you can redistribute it and/or modify
    8 # it under the terms of version 2 of the GNU General Public License as
    9 # published by the Free Software Foundation.
   10 #
   11 # This program is distributed in the hope that it would be useful, but
   12 # WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   14 #
   15 # Further, this software is distributed without any warranty that it is
   16 # free of the rightful claim of any third person regarding infringement
   17 # or the like.  Any license provided herein, whether implied or
   18 # otherwise, applies only to this software file.  Patent licenses, if
   19 # any, provided herein do not apply to combinations of this program with
   20 # other software, or any other product whatsoever.
   21 #
   22 # You should have received a copy of the GNU General Public License
   23 # along with this program; if not, write the Free Software Foundation,
   24 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
   25 #
   26 #
   27 
   28 # Initialization:
   29 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
   30 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
   31 
   32 if [ -n "${OCF_DEBUG_LIBRARY}" ]; then
   33     . ${OCF_DEBUG_LIBRARY}
   34 else
   35     : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
   36     . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
   37 fi
   38 
   39 # Defaults
   40 OCF_RESKEY_ganesha_active_default="ganesha-active"
   41 OCF_RESKEY_grace_active_default="grace-active"
   42 OCF_RESKEY_grace_delay_default="5"
   43 
   44 : ${OCF_RESKEY_ganesha_active=${OCF_RESKEY_ganesha_active_default}}
   45 : ${OCF_RESKEY_grace_active=${OCF_RESKEY_grace_active_default}}
   46 : ${OCF_RESKEY_grace_delay=${OCF_RESKEY_grace_delay_default}}
   47 
   48 ganesha_meta_data() {
   49     cat <<END
   50 <?xml version="1.0"?>
   51 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
   52 <resource-agent name="ganesha_mon">
   53 <version>1.0</version>
   54 
   55 <longdesc lang="en">
   56 This Linux-specific resource agent acts as a dummy
   57 resource agent for nfs-ganesha.
   58 </longdesc>
   59 
   60 <shortdesc lang="en">Manages the user-space nfs-ganesha NFS server</shortdesc>
   61 
   62 <parameters>
   63 <parameter name="ganesha_active">
   64 <longdesc lang="en">NFS-Ganesha daemon active attribute</longdesc>
   65 <shortdesc lang="en">NFS-Ganesha daemon active attribute</shortdesc>
   66 <content type="string" default="ganesha-active" />
   67 </parameter>
   68 <parameter name="grace_active">
   69 <longdesc lang="en">NFS-Ganesha grace active attribute</longdesc>
   70 <shortdesc lang="en">NFS-Ganesha grace active attribute</shortdesc>
   71 <content type="string" default="grace-active" />
   72 </parameter>
   73 <parameter name="grace_delay">
   74 <longdesc lang="en">
   75 NFS-Ganesha grace delay.
   76 When changing this, adjust the ganesha_grace RA's monitor interval to match.
   77 </longdesc>
   78 <shortdesc lang="en">NFS-Ganesha grace delay</shortdesc>
   79 <content type="string" default="5" />
   80 </parameter>
   81 </parameters>
   82 
   83 <actions>
   84 <action name="start"   timeout="40s" />
   85 <action name="stop"    timeout="40s" />
   86 <action name="status"  timeout="20s" interval="60s" />
   87 <action name="monitor" depth="0"  timeout="10s" interval="10s" />
   88 <action name="meta-data"  timeout="20s" />
   89 </actions>
   90 </resource-agent>
   91 END
   92 
   93 return ${OCF_SUCCESS}
   94 }
   95 
   96 ganesha_mon_usage() {
   97     echo "ganesha.nfsd USAGE"
   98 }
   99 
  100 # Make sure meta-data and usage always succeed
  101 case ${__OCF_ACTION} in
  102     meta-data)  ganesha_meta_data
  103             exit ${OCF_SUCCESS}
  104             ;;
  105     usage|help) ganesha_usage
  106             exit ${OCF_SUCCESS}
  107             ;;
  108     *)
  109             ;;
  110 esac
  111 
  112 ganesha_mon_start()
  113 {
  114     ocf_log debug "ganesha_mon_start"
  115     ganesha_mon_monitor
  116     return $OCF_SUCCESS
  117 }
  118 
  119 ganesha_mon_stop()
  120 {
  121     ocf_log debug "ganesha_mon_stop"
  122     return $OCF_SUCCESS
  123 }
  124 
  125 ganesha_mon_monitor()
  126 {
  127     local host=$(hostname -s)
  128     local pid_file="/var/run/ganesha.pid"
  129     local rhel6_pid_file="/var/run/ganesha.nfsd.pid"
  130     local proc_pid="/proc/"
  131 
  132     # RHEL6 /etc/init.d/nfs-ganesha adds -p /var/run/ganesha.nfsd.pid
  133     # RHEL7 systemd does not. Would be nice if all distros used the
  134     # same pid file.
  135     if [ -e ${rhel6_pid_file} ]; then
  136         pid_file=${rhel6_pid_file}
  137     fi
  138     if [ -e ${pid_file} ]; then
  139         proc_pid="${proc_pid}$(cat ${pid_file})"
  140     fi
  141 
  142     if [ "x${proc_pid}" != "x/proc/" -a -d ${proc_pid} ]; then
  143 
  144         attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1
  145         if [ $? -ne 0 ]; then
  146             ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_ganesha_active} -v 1 failed"
  147         fi
  148 
  149         # ganesha_grace (nfs-grace) RA follows grace-active attr
  150         # w/ constraint location
  151         attrd_updater -n ${OCF_RESKEY_grace_active} -v 1
  152         if [ $? -ne 0 ]; then
  153             ocf_log info "warning: attrd_updater -n ${OCF_RESKEY_grace_active} -v 1 failed"
  154         fi
  155 
  156         # ganesha_mon (nfs-mon) and ganesha_grace (nfs-grace)
  157         # track grace-active crm_attr (attr != crm_attr)
  158         # we can't just use the attr as there's no way to query
  159         # its value in RHEL6 pacemaker
  160 
  161         crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
  162         if [ $? -ne 0 ]; then
  163             host=$(hostname)
  164             crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 2> /dev/null
  165             if [ $? -ne 0 ]; then
  166                 ocf_log info "mon monitor warning: crm_attribute --node=${host} --lifetime=forever --name=${OCF_RESKEY_grace_active} --update=1 failed"
  167             fi
  168         fi
  169 
  170         return ${OCF_SUCCESS}
  171     fi
  172 
  173     # VIP fail-over is triggered by clearing the
  174     # ganesha-active node attribute on this node.
  175     #
  176     # Meanwhile the ganesha_grace notify() runs when its
  177     # nfs-grace resource is disabled on a node; which
  178     # is triggered by clearing the grace-active attribute
  179     # on this node.
  180     #
  181     # We need to allow time for it to run and put
  182     # the remaining ganesha.nfsds into grace before
  183     # initiating the VIP fail-over.
  184 
  185     attrd_updater -D -n ${OCF_RESKEY_grace_active}
  186     if [ $? -ne 0 ]; then
  187         ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_grace_active} failed"
  188     fi
  189 
  190     host=$(hostname -s)
  191     crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
  192     if [ $? -ne 0 ]; then
  193         host=$(hostname)
  194         crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 2> /dev/null
  195         if [ $? -ne 0 ]; then
  196             ocf_log info "mon monitor warning: crm_attribute --node=${host} --name=${OCF_RESKEY_grace_active} --update=0 failed"
  197         fi
  198     fi
  199 
  200     sleep ${OCF_RESKEY_grace_delay}
  201 
  202     attrd_updater -D -n ${OCF_RESKEY_ganesha_active}
  203     if [ $? -ne 0 ]; then
  204         ocf_log info "warning: attrd_updater -D -n ${OCF_RESKEY_ganesha_active} failed"
  205     fi
  206 
  207     return ${OCF_SUCCESS}
  208 }
  209 
  210 ganesha_mon_validate()
  211 {
  212     return ${OCF_SUCCESS}
  213 }
  214 
  215 ganesha_mon_validate
  216 
  217 # Translate each action into the appropriate function call
  218 case ${__OCF_ACTION} in
  219 start)          ganesha_mon_start
  220         ;;
  221 stop)           ganesha_mon_stop
  222         ;;
  223 status|monitor) ganesha_mon_monitor
  224         ;;
  225 *)              ganesha_mon_usage
  226         exit ${OCF_ERR_UNIMPLEMENTED}
  227         ;;
  228 esac
  229 
  230 rc=$?
  231 
  232 # The resource agent may optionally log a debug message
  233 ocf_log debug "${OCF_RESOURCE_INSTANCE} ${__OCF_ACTION} returned $rc"
  234 exit $rc