Getting High With Lenny - Page 5

Want to support HowtoForge? Become a subscriber!
 
Submitted by randall (Contact Author) (Forums) on Tue, 2009-02-17 11:45. ::

After above 2 files are set, the haresources is where we want to be to control Heartbeat's behaviour. This is an example for 1 Vserver that we will set up later on.

nano /etc/ha.d/haresources

node1 drbddisk::r1 LVM::drbdvg1 Filesystem::/dev/drbdvg1/web::/VSERVERS/web::ext3 vserver-web SendArp::123.123.123.125/eth0

The above will default the Vserver named web to node1 and specify the mount points, the vserver-web script will heartbeat start and stop it, the sendarp is for notifying the network that this IP can be found somewhere else than before. (Have added the SendArp an extra time below for better result.)

The vserver-web script is basically a demolished version of the original R2 style agent by Martin Fick from here: http://www.theficks.name/bin/lib/ocf/VServer. What I did is remove the sensible top part and replace "$OCF_RESKEY_vserver" with the specific Vserver name, also added an extra /etc/ha.d/resource.d/SendArp 123.123.123.126/eth0 start to the start part because I had various results when done by Heartbeat.

nano /etc/ha.d/resource.d/Vserver-web

#!/bin/sh
#
# License: GNU General Public License (GPL)
# Author:  Martin Fick <mogulguy@yahoo.com>
# Date:    04/19/07
# Version: 1.1
#
#    This script manages a VServer instance
#
#    It can start or stop a VServer
#
#    usage: $0 {start|stop|status|monitor|meta-data}
#
#
#       OCF parameters are as below
#       OCF_RESKEY_vserver
#
#######################################################################
# Initialization:
#
#. /usr/lib/heartbeat/ocf-shellfuncs
#
#USAGE="usage: $0 {start|stop|status|monitor|meta-data}";
#
#######################################################################
#
#
#meta_data() {
#        cat &lt;<end #="">
#
#<resource-agent name="VServer">
# <version>1.0</version>
# <longdesc lang="en">
#This script manages a VServer instance.
#It can start or stop a VServer.
# </longdesc>
# <shortdesc lang="en">OCF Resource Agent compliant VServer script.</shortdesc>
#
#
<parameters>
#
#
<parameter name="vserver" unique="1" required="1">
#   <longdesc lang="en">
#The vserver name is the name as found under /etc/vservers
#   </longdesc>
#   <shortdesc lang="en">VServer Name</shortdesc>
#    <content type="string" default="">
#   </content>
#
# </parameter>
#
# <actions>
#  <action name="start" timeout="2m">
#  <action name="stop" timeout="1m">
#  <action name="monitor" depth="0" timeout="1m" interval="5s" start-delay="2m">
#  <action name="status" depth="0" timeout="1m" interval="5s" start-delay="2m">
#  <action name="meta-data" timeout="1m">
# </action>
#</action>
#END
#}
vserver_reload() {
    vserver_stop || return
    vserver_start
}
vserver_stop() {
  #
  #    Is the VServer already stopped?
  #
    vserver_status
    [ $? -ne 0 ] &amp;&amp; return 0
    /usr/sbin/vserver "web" "stop"
    vserver_status
    [ $? -ne 0 ] &amp;&amp; return 0
    return 1
}
vserver_start() {
    vserver_status
    [ $? -eq 0 ] &amp;&amp; return 0
    /usr/sbin/vserver "web" "start"
    vserver_status
    /etc/ha.d/resource.d/SendArp 123.123.123.125/eth0 start
}
vserver_status() {
    /usr/sbin/vserver "web" "status"
    rc=$?
    if [ $rc -eq 0 ]; then
    echo "running"
        return 0
    elif [ $rc -eq 3 ]; then
    echo "stopped"
    else
    echo "unknown"
    fi
    return 7
}
vserver_monitor() {
  vserver_status
}
vserver_usage() {
  echo $USAGE &gt;&amp;2
}
vserver_info() {
cat - &lt;<!--INFO
    Abstract=VServer Instance takeover
    Argument=VServer Name
    Description:
    A Vserver is a simulated server which is fairly hardware independent
        so it can be easily setup to run on several machines.
    Please rerun with the meta-data command for a list of \\
    valid arguments and their defaults.
!INFO
}
#
#    Start or Stop the given VServer...
#
if [ $# -ne 1 ] ; then
  vserver_usage
  exit 2
fi
  case "$1" in
    start|stop|status|monitor|reload|info|usage)    vserver_$1 ;;
    meta-data)   meta_data ;;
    validate-all|notify|promote|demote)  exit 3 ;;
    *)  vserver_usage ; exit 2 ;;
  esac

And make it executable.

chmod a+x /etc/ha.d/resource.d/Vserver-web


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.