#!/bin/sh VER=1.0 # ============================================================================ # # Copyright (C) THALES. All rights reserved # Author: Laurent Mazet & Thomas Perennou # Date : 03/12/2014 # ============================================================================ ### BEGIN INIT INFO # Provides: ipmiwake # Required-Start: $network waitswitches # Required-Stop: # Should-Start: # Default-Start: S # Default-Stop: # Short-Description: IPMI wake cluster blades # Description: Boot all cluster blades by IPMI boot command ### END INIT INFO DHCPCONF=/etc/dhcp/dhcpd.conf ENABLE="yes" TIMEOUT=10000 PATH=/sbin:/usr/sbin:/bin:/usr/bin [ -f /etc/default/ipmiwake ] && . /etc/default/ipmiwake [ "$ENABLE" = "yes" ] || exit 0 . /lib/lsb/init-functions do_action () { ACTION=$1 log_action_msg "Send IPMI boot $ACTION command" ip addr add 10.133.25.1/24 dev eth0 for mac in $(awk '{sub(/#.*/, "")} /host\s+trc[0-9]/ && ! /-rf/ { gsub(/[;{}]/, " "); print $5}' $DHCPCONF); do ipmi=$(awk '{sub(/#.*/, "")} /'$mac'/ {print}' $DHCPCONF | sed 's/.* [0-9.]*\.\([0-9][0-9]*\)[^0-9].*/10.133.25.\1/') host=$(awk '{sub(/#.*/, "")} /'$mac'/ {gsub(/[{}]/, " "); print $2}' $DHCPCONF) log_action_msg "Wake-up $host (IPMI boot $ACTION $ipmi)" ipmipower --session-timeout=$TIMEOUT -h $ipmi -u ADMIN -p ADMIN --$ACTION & done wait ip addr del 10.133.25.1/24 dev eth0 } case "$1" in -v) echo "$(basename $0), version $VER" ;; start) do_action on ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) do_action off ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac # vim:set tabstop=4 expandtab shiftwidth=4: