#!/bin/bash # 'pingAllAddr' doesn't shoot its targets, this plugin only confirms death of # the targets. 'pingAllAddr' pings the IP addresses of the targets specified # in cib.xml. If any of the IP addresses don't respond, 'pingAllAddr' # exits with a successful status, otherwise it exits with an error status. savelog() { echo $(date '+%Y%m%d-%H%M%S') ${0##*/} "$@" >> /var/log/stonith.log; } EXIT() { savelog EXIT $subcmd "$@"; exit "$@";} are_all_addrs_dead() { savelog ENTER are_all_addrs_dead declare local host=$1 for name in ${!addrlist*}; do savelog ADDR $name eval set -- \$$name if [[ "$1" = "$host" ]]; then shift for addr in "$@"; do savelog ping $addr if ping -w1 -c1 "$addr" >/dev/null 2>&1; then savelog PING OK $addr return 1 fi savelog PING NG $addr done return 0 fi done return 1 } hostlist=`echo $hostlist | tr ',' ' '` savelog "ARGS" "$@" = "$hostlist" subcmd=$1 case $1 in gethosts) for h in $hostlist ; do echo $h done EXIT 0 ;; on) EXIT 1 ;; off) EXIT 1 ;; reset) sleep ${initial_wait:0} for h in $hostlist; do if [ "$h" != "$2" ]; then continue fi savelog CALL are_all_addrs_dead if are_all_addrs_dead $h; then EXIT 0 fi EXIT 1 done ;; status) if [ -z "$hostlist" ]; then EXIT 1 fi EXIT 0 ;; getconfignames) echo "hostlist" EXIT 0 ;; getinfo-devid) echo "isNodeAlive" EXIT 0 ;; getinfo-devname) echo "isNodeAlive device" EXIT 0 ;; getinfo-devdescr) echo "isNodeAlive" EXIT 0 ;; getinfo-devurl) echo "http://127.0.0.1" EXIT 0 ;; getinfo-xml) cat << EOX Hostlist The list of hosts that the STONITH device controls EOX EXIT 0 ;; *) EXIT 1 ;; esac