VirtualBox fencing and Red Hat Enterprise Linux Cluster Suite

I know there is already a perl script to fence VirtualBox machines, but since I am not very familiar with Perl, a shell scripts seemed easier.

So; when you run VirtualBox and would like (virtual) cluster nodes to be able to fence, you may use this shell script on the virtual machines:

#!/bin/sh -x

# Script to stop and start a virtual machine.
# The only required argument is machinename.

eval $(cat -)

# I use Apple Mac OS X, but any OS may be used.
vboxmanage="/Applications/VirtualBox.app/Contents/MacOS/VBoxManage"

usage () {
/bin/echo "Usage: $0 -a NAME [-o ACTION]"
/bin/echo
/bin/echo " -a NAME"
/bin/echo "   The name of the virtual machine to be fenced."
/bin/echo "   In case it contains spaces, use double quotes."
/bin/echo " -o ACTION"
/bin/echo "   What to do; start|stop|reboot(default)."
/bin/echo
exit 1
}

while [ "$#" -gt 0 ] ; do
case "$1" in
  -a)
   if [ "$2" ] ; then
    vm="$2"
    shift ; shift
   else
    /bin/echo "Missing value for $1."
    /bin/echo
    usage
    shift
   fi
  ;;
  -o)
   if [ "$2" ] ; then
    action="$2"
    shift ; shift
   else
    /bin/echo "Missing value for $1."
    /bin/echo
    usage
    shift
   fi
  ;;
  *)
   /bin/echo "Not a know option, $1."
   usage
   shift
  ;;
esac
done

if [ ! "${action}" ] ; then
action=reboot
fi

if [ ! "${vm}" ] ; then
/bin/echo "Error, please specify a name."
usage
fi

check() {
ssh $host "$vboxmanage showvminfo ${vm}" > /dev/null 2>&1
if [ ${?} != 0 ] ; then
  /bin/echo "Error, VM ${vm} not found, choose one of these:"
  ssh $host "$vboxmanage list vms | sed 's/" .*/"/'"
  exit 1
fi
}


stop() {
ssh $host "$vboxmanage controlvm ${vm} poweroff > /dev/null 2>&1"
}

start() {
ssh $host "$vboxmanage startvm ${vm} > /dev/null 2>&1"
}

reboot() {
stop
sleep 3
start
}

case $action in
start)
  check
  start
;;
stop)
  check
  stop
;;
reboot)
  check
  reboot
;;
*)
  /bin/echo "Unknown action: $action"
  /bin/echo
  usage
;;
esac

To use this script, add this block to every "clusternode" in /etc/cluster/cluster.conf:

    <fence>
        <method name="1">
            <device host="[email protected]" name="vbox" vm="ClusterMember2"/>
        </method>
    </fence>

And create a shared fence device in /etc/cluster/cluster.conf:

    <fencedevices>
        <fencedevice agent="fence_vbox" name="vbox"/>
    </fencedevices>

The important variables are "host" and "vm". "host" is used to connect to the physical box running VirtualBox, "vm" is the actual name of the virtual machine, as displayed by VirtualBox.

Comments

Microot Microwave specializes

Microot Microwave specializes in the design and manufacture of broadband RF Microwave components since 2003. Our extensive product line includes power divider, directional coupler, Hybrid coupler, Low Noise Amplifier, Frequency Source and more.

How to use this fencing

How to use this fencing script for the Red Hat Enterprise Linux 7
High Availability Add-On.

Since "Red Hat Enterprise Linux 7 High Availability Add-On
Overview.pdf " doc says that:

Configuration Files — Previously, cluster configuration was found in the
/etc/cluster/cluster.conf file, while cluster configuration in release 7 is in
/etc/corosync/corosync.conf for membership and quorum configuration and
/var/lib/heartbeat/crm /cib.xm l for cluster node and resource configuration.

It means we are not using the /etc/cluster/cluster.conf file for Red Hat Enterprise Linux 7 High Availability.

My Question is how to create stonith resource using below cmd with the above shell script. Please.:
#pcs stonith create myfence fence_vmbox params node="z2"

I have installed the Oracle VMBox (CentOS 7) 2 nodes(z1 and z2) setup (on one laptop running windows xp) works fine:
# pcs status
Cluster name: my_cluster
Last updated: Tue Dec 9 07:29:34 2014
Last change: Tue Dec 9 05:48:32 2014 via cibadmin on z1
Stack: corosync
Current DC: z2 (2) - partition with quorum
Version: 1.1.10-32.el7_0.1-368c726
2 Nodes configured
5 Resources configured
Online: [ z1 z2 ]
Full list of resources:
ClusterIP (ocf::heartbeat:IPaddr2): Started z2
httpd_res (ocf::heartbeat:apache): Started z2
fence_new_pcmk (stonith:fence_pcmk): Started z2
PCSD Status:
z1: Online
z2: Online
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled

Hi, I Download the script and

Hi,

I Download the script and put in both nodes of my cluster, but doesn't work the fence_vbox. SSh works fine (without password), and returns all status of my VMs, but when I run "fence_node node" return failed.

Versions

RHEL 6.2 e Vbox 4.18

Thanks

ps. sorry, about my english

I am trying to create a

I am trying to create a fence_ws for use with VMware Workstation 8. I do not see the variables being passed to the fence_XXX script from cluster.conf when you use fence_node, etc. The only other option would be to give unique names to the fence device, e.g., fence_xx_nodename where the name of the script could be used to determine which vm is too be manipulated. Any other ideas?

Hi, Please clarify how

Hi,

Please clarify how exactly you provide script with correct $host value?

ssh $host "$vboxmanage controlvm ${vm} poweroff > /dev/null 2>&1"

and one more question:
how will cluster use that command. I receive the following error:
Apr 24 14:39:16 cl01 fenced[4026]: fencing node "cl02.jk.com"
Apr 24 14:39:16 cl01 fenced[4026]: agent "fence_vbox" reports: Error, please specify a name. Usage: /sbin/fence_psbm -a NAME [-o ACTION] -a NAME The name of the virtual machine to be fenced. In case it contains spaces, use double quotes. -o ACTION What to do; start|stop|reboot(default).
Apr 24 14:39:16 cl01 fenced[4026]: fence "cl02.jk.com" failed

Sorry, for spam. :) Issue was

Sorry, for spam. :) Issue was related with that I comment
eval $(cat -)
string.

I am cannot understand why that string is necessary. I did not understand your description below, May you provide me with more details?

What is the script name? As I

What is the script name? As I understood that script should be on the each cluster VM.

After that I add corect variables vm and host into cluster configuration file.

But still not clear how cluster should understand how to execute that script.

Cars and houses are expensive

Cars and houses are expensive and not everyone is able to buy it. But, loans was created to aid people in such hard situations.

Where do you store the

Where do you store the script? (directory/filename)

That's in /sbin You'll find

That's in /sbin

You'll find all kinds of fence_ scripts there. Regards, Robert.

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]