#!/bin/sh # # External STONITH module for fence-virt. # # Copyright (c) 2010 NIPPON TELEGRAPH AND TELEPHONE CORPORATION # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # check_delimeter() { : ${delimeter:=:} if [ "$delimeter" = " " ]; then ha_log.sh err "Invalid delimeter [$delimeter]." exit 6 #ERR_CONFIGURED fi } ha_log.sh debug "\$*: [$*]" >/dev/null 2>&1 case $1 in gethosts) check_delimeter for h in $hostlist; do echo $h | awk -F $delimeter '{print $1}' done exit 0 ;; on|off|reset|status) if [ "x$hostlist" = "x" ]; then ha_log.sh err "hostlist isn't set." exit 6 #ERR_CONFIGURED fi check_delimeter if [ "x$fencing_agent" = "x" ]; then ha_log.sh err "fencing_agent isn't set." exit 6 #ERR_CONFIGURED fi fencing_agent=`echo "$fencing_agent -t 3600"` op=`echo $1 | sed "s/reset/reboot/"` target=`echo $2 | tr A-Z a-z` for h in $hostlist; do host=`echo $h | awk -F $delimeter '{print $1}' | tr A-Z a-z` rsc=`echo $h | awk -F $delimeter '{print $2}'` if [ "$op" != "status" -a "$target" != "$host" ]; then continue fi while true; do ha_log.sh info "Request: target=$host($rsc), op=$1($op)" ha_log.sh debug "$fencing_agent -o $op -H $rsc" $fencing_agent -o $op -H $rsc 2>/dev/null rc=$? ha_log.sh info "Result: $rc" if [ $rc -eq 0 -o $rc -eq 2 ]; then if [ "$op" = "status" ]; then break else exit 0 fi elif [ $rc -eq 1 -o $rc -eq 3 ]; then ha_log.sh err "request failed." exit 1 else ha_log.sh info "request failed." sleep 3 continue fi done done if [ "$op" = "status" ]; then exit 0 else exit 1 fi ;; getconfignames) echo "hostlist delimeter" exit 0 ;; getinfo-devid) echo "vm-stonith STONITH device" exit 0 ;; getinfo-devname) echo "vm-stonith STONITH external device" exit 0 ;; getinfo-devdescr) echo "Allows STONITH to control guests managed by a CRM/Pacemaker host." echo "Requires VM + CRM/Pacemaker at both layers." exit 0 ;; getinfo-devurl) echo "fence-virt -> http://sourceforge.net/projects/fence-virt/" exit 0 ;; getinfo-xml) cat < Host Map A mapping of hostname and resource ID supported by this device. For example: "guest-a1:rscid guest-a2:rscid" * rscid : resource ID of the virtual machine managed by the cluster of host. Delimeter of hostname and resource ID The delimiter of the hostname and resource ID in hostlist parameter. (The space character cannot be specified.) Fencing agent command Specify the fencing agent command (fence_virt or fence_xvm) with parameters. The following options need not be specified. -o : Fencing action. -H : Virtual machine to fence. -t : Fencing timeout. For example: "fence_virt -D /dev/ttyS1" VMSTONITHXML exit 0 ;; *) exit 1 ;; esac