#!/bin/sh # # External STONITH module for HP Ilo boards via ssh. # # Copyright (c) 2004 SUSE LINUX AG - Lars Marowsky-Bree # # 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. # #SSH_COMMAND "ssh -q -x -o PasswordAuthentication=no StrictHostKeyChecking=no" SSH_COMMAND="ssh -q -x -n -l stonith" #REBOOT_COMMAND="echo 'sleep 2; /sbin/reboot -nf' | SHELL=/bin/sh at now >/dev/null 2>&1" REBOOT_COMMAND="power reset" # Warning: If you select this poweroff command, it'll physically # power-off the machine, and quite a number of systems won't be remotely # revivable. # TODO: Probably should touch a file on the server instead to just # prevent heartbeat et al from being started after the reboot. # POWEROFF_COMMAND="echo 'sleep 2; /sbin/poweroff -nf' | SHELL=/bin/sh at now >/dev/null 2>&1" POWEROFF_COMMAND="power off" POWERON_COMMAND="power on" # Rewrite the hostlist to accept "," as a delimeter for hostnames too. hostlist=`echo $hostlist | tr ',' ' '` CheckIfDead() { for j in 1 2 3 do if ping -w1 -c1 "$1" >/dev/null 2>&1 then return 1 fi done return 0 } case $1 in gethosts) for h in $hostlist ; do echo $h done exit 0 ;; on) CNT=0 for h in $hostlist; do if [ "$h" != "$2" ]; then CNT=$(( $CNT +1 )) continue fi CNT2=0 for i in $ilolist; do if [ "$CNT2" != "$CNT" ]; then CNT2=$(( $CNT2 + 1 )) continue fi # connect to the ILO board $SSH_COMMAND "$i" "$POWERON_COMMAND" # Good thing this is only for testing... if [ $? == 0 ];then exit 0 else exit 1 fi done done ;; off) CNT=0 for h in $hostlist; do if [ "$h" != "$2" ]; then CNT=$(( $CNT +1 )) continue fi CNT2=0 for i in $ilolist; do if [ "$CNT2" != "$CNT" ]; then CNT2=$(( $CNT2 + 1 )) continue fi # connect to the ILO board $SSH_COMMAND "$i" "$REBOOT_COMMAND" $SSH_COMMAND "$i" "$POWEROFF_COMMAND" # Good thing this is only for testing... for j in 1 2 3 4 5 do if CheckIfDead "$2" then exit 0 fi sleep 1 done done done exit 1 ;; reset) CNT=0 for h in $hostlist; do if [ "$h" != "$2" ]; then CNT=$(( $CNT +1 )) continue fi CNT2=0 for i in $ilolist; do if [ "$CNT2" != "$CNT" ]; then CNT2=$(( $CNT2 + 1 )) continue fi # connect to the ILO board $SSH_COMMAND "$i" "$REBOOT_COMMAND" # Good thing this is only for testing... for j in 1 2 3 4 5 do if CheckIfDead "$2" then exit 0 fi sleep 1 done done done exit 1 ;; status) if [ -z "$hostlist" ] then exit 1 fi for h in $hostlist do if ping -w1 -c1 "$h" 2>&1 | grep "unknown host" then exit 1 fi done exit 0 ;; getconfignames) echo "hostlist" echo "ilolist" exit 0 ;; getinfo-devid) echo "ssh STONITH ILO device" exit 0 ;; getinfo-devname) echo "ssh STONITH ILO external device" exit 0 ;; getinfo-devdescr) echo "ssh-based Linux ILO power management" echo "Fine for testing, but not suitable for production!" exit 0 ;; getinfo-devurl) echo "http://openssh.org" exit 0 ;; getinfo-xml) cat << SSHXML Hostlist The list of hosts that the STONITH device controls List of addresses of the ILO boards of the hosts This list contains the hostnames or IP Addresses of the ILO boards of the nodes. The order has to be the same as for the hosts in the hostlist. SSHXML exit 0 ;; *) exit 1 ;; esac