Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.
Storage & Clustering Community Blog

Easy IMF plugin to make a VCS agent IMF-enabled

Created: 15 Mar 2012 • Updated: 11 Jun 2014
Bhavin Thaker's picture
+2 2 Votes
Login to vote

Easy IMF plugin to make a VCS agent IMF-enabled
================================================

1) Stop the VCS cluster
   # hastop -all

Note: The steps here are meant for education purposes only and
hence shutdown VCS. You can perform these steps by keeping
VCS online as well. Refer to the VCS Admin guide and
Agent Developer's guide for further details.

2) Let's write a quick VCS agent that starts the script myimf.sh
 
   # mkdir /opt/VRTSvcs/bin/ezimf
   # cd /opt/VRTSvcs/bin/ezimf

   # vi myimf.sh   (enter the following text)
---------------------------------------------------------------------------
#!/bin/sh

while [ 1 ]
do
        sleep 60
        /usr/bin/logger -p kern.alert "hello world from myimf.sh"
done
---------------------------------------------------------------------------

   # vi online
---------------------------------------------------------------------------
#!/bin/sh

/opt/VRTSvcs/bin/ezimf/myimf.sh &

exit 0
---------------------------------------------------------------------------

   # vi offline
---------------------------------------------------------------------------
#!/bin/sh

/usr/bin/pkill -TERM myimf.sh

exit 0
---------------------------------------------------------------------------
   (pkill works on Solaris, change this appropriately for your OS)

   # vi clean
---------------------------------------------------------------------------
#!/bin/sh

/usr/bin/pkill -KILL myimf.sh

exit 0
---------------------------------------------------------------------------
   (pkill works on Solaris, change this appropriately for your OS)

   # vi monitor
---------------------------------------------------------------------------
#!/bin/sh

/usr/bin/pgrep myimf.sh >/dev/null 2>&1
ret=$?
export ret

if [ $ret -eq 0 ]
then
        exit 110  # online
else
        exit 100  # offline
fi
---------------------------------------------------------------------------

   # chmod +x myimf.sh online offline clean monitor

   # ln -s /opt/VRTSvcs/bin/Script51Agent ezimfAgent

3) Our agent is ready. Let's add the agent to the VCS configuration.
   Here we add the Resource (for which we wrote an agent) to a group
   called amf_group. You can add it to any existing group too.
   thor246 and thor247 are the machines/nodes in the VCS cluster.

   # vi /etc/VRTSvcs/conf/config/main.cf
---------------------------------------------------------------------------
#include "types.cf"
...
...
...
group amf_group (
        SystemList = { thor246 = 0, thor247 = 1 }
        AutoStartList = { thor246 }
        )

ezimf myimf (
            )
---------------------------------------------------------------------------

   # vi /etc/VRTSvcs/conf/config/types.cf
---------------------------------------------------------------------------
...
...
...
type ezimf (
)
---------------------------------------------------------------------------

4) Repeat the above steps for all nodes in the VCS cluster.

5) Ok, now that we have an agent ready. Let's IMF-enable it via the
   "Easy IMF Plugin to make a VCS agent IMF-enabled".
   The real action starts now!

   Configure IMF plugin in the VCS configuration file:

   # vi /etc/VRTSvcs/conf/config/types.cf
     Note the 2 new lines added below containing the keyword IMF.
---------------------------------------------------------------------------
...
...
...
type ezimf (
        static int IMF{} = { Mode=3, MonitorFreq=10, RegisterRetryLimit=3 }
        static str IMFRegList[] = {  }
)
---------------------------------------------------------------------------
   Mode = 3 means that we want IMF to do both online and offline monitoring
   MonitorFreq = 10 means that we want regular monitoring at a period of
          (MonitorFreq * MonitorInterval) = (10 * 60) = 10 minutes
          just as a safety check.
          You can turn off regular monitoring completely via MonitorFreq=0
          That's perfectly OK. No worries.
   RegisterRetryLimit = 3 means that we want IMF to try register a resource
          with IMF 3 times and then stop trying if the registration fails.
          This is a corner case setting and so don't worry about it too much.
          In case you are wondering when can this happen -- one possibility
          if the kernel module for this functionality (called AMF) has been
          turned OFF explicitly for some reason.
         
6) Create the amfregister.xml file specifying what to monitor via IMF.

   # cd /opt/VRTSvcs/bin/ezimf/
   # vi amfregister.xml           
---------------------------------------------------------------------------
<xml>
        <Register>
                <RegType>PRON</RegType>
                <PronOptions>IGNORE_ARGS IGNORE_PATH</PronOptions>
                <ProcPattern>myimf.sh</ProcPattern>
        </Register>

        <Register>
                <RegType>PROFF</RegType>
                <Owner>root</Owner>
                <Path>/bin</Path>
                <arg0>sh</arg0>
                <args>/opt/VRTSvcs/bin/ezimf/myimf.sh</args>
        </Register>
</xml>
---------------------------------------------------------------------------
    The first section of this XML file specifies the process pattern
    to be monitored for ONLINE monitoring. The options IGNORE_ARGS and
    IGNORE_PATHS are self-explanatory, meaning we want IMF to ignore
    arguments to the process and the path used for the process binary.

    The second section of this XML file specifies the process pattern
    to be monitored for OFFLINE monitoring.

7) Create required symbolic or hard links as mentioned below:
    
   # cd /opt/VRTSvcs/bin/ezimf/
   # ln -s /opt/VRTSamf/imf/imf_getnotification .
   # ln -s /opt/VRTSamf/imf/imf_init .
   # ln -s /opt/VRTSamf/imf/imf_register .

   Again, ensure that you repeat the above steps for
   all nodes in the VCS cluster, including "chmod +x"
   for the scripts in the ezimf directory.

8) That's it! You are ready to try out the IMF-enabled agent ezimf now.

   # hastart  (on all cluster nodes)
 
   Let's assume that the ezimf group comes online on the node thor246.
   You can verify this via the command:
   # hastatus

   Check that you see ezimf agent registered in the amfstat output.
   # amfstat
---------------------------------------------------------------------------
Registered Reapers (3):
=======================
 RID     PID             MONITOR         TRIGG   REAPER
...
 143     2378            1               0       ezimf
---------------------------------------------------------------------------

   Now let's kill the ezimf.sh application that IMF is monitoring:
   # pkill -KILL myimf.sh

   Watch how IMF is able to detect this event in around 1-2 seconds.
   This is actually noticed instantaneously by IMF, but it takes 1-2 seconds,
   since IMF runs the regular monitoring checks to double-check that the
   resource is actually offline before causing a failover -- a safety-check
   is always good, especially since failover is a critical action.

   See, wasn't this easy?
   It took us only 3 steps (Steps 5 to 7) to make an agent IMF-enabled! :-)