change version
[debian6500.git] / master / etc / init.d / ipmiwake
1 #!/bin/sh
2 VER=1.0
3 # ============================================================================
4 #
5 # Copyright (C) THALES. All rights reserved
6 # Author: Laurent Mazet & Thomas Perennou
7 # Date : 03/12/2014
8 # ============================================================================
9
10 ### BEGIN INIT INFO
11 # Provides: ipmiwake
12 # Required-Start: $network waitswitches
13 # Required-Stop:
14 # Should-Start:
15 # Default-Start: S
16 # Default-Stop:
17 # Short-Description: IPMI wake cluster blades
18 # Description: Boot all cluster blades by IPMI boot command
19 ### END INIT INFO
20
21 DHCPCONF=/etc/dhcp/dhcpd.conf
22 ENABLE="yes"
23 TIMEOUT=10000
24
25 PATH=/sbin:/usr/sbin:/bin:/usr/bin
26 [ -f /etc/default/ipmiwake ] && . /etc/default/ipmiwake
27 [ "$ENABLE" = "yes" ] || exit 0
28
29 . /lib/lsb/init-functions
30
31 do_action () {
32 ACTION=$1
33
34 log_action_msg "Send IPMI boot $ACTION command"
35
36 ip addr add 10.133.29.1/24 dev eth0
37
38 for mac in $(awk '{sub(/#.*/, "")} /host\s+trc[0-9]/ && ! /-rf/ { gsub(/[;{}]/, " "); print $5}' $DHCPCONF); do
39 ipmi=$(awk '{sub(/#.*/, "")} /'$mac'/ {print}' $DHCPCONF | sed 's/.* [0-9.]*\.\([0-9][0-9]*\)[^0-9].*/10.133.29.\1/')
40 host=$(awk '{sub(/#.*/, "")} /'$mac'/ {gsub(/[{}]/, " "); print $2}' $DHCPCONF)
41 log_action_msg "Wake-up $host (IPMI boot $ACTION $ipmi)"
42 ipmipower --session-timeout=$TIMEOUT -h $ipmi -u ADMIN -p ADMIN --$ACTION &
43 done
44
45 wait
46
47 ip addr del 10.133.29.1/24 dev eth0
48 }
49
50 case "$1" in
51 -v)
52 echo "$(basename $0), version $VER"
53 ;;
54 start)
55 do_action on
56 ;;
57 restart|reload|force-reload)
58 echo "Error: argument '$1' not supported" >&2
59 exit 3
60 ;;
61 stop)
62 do_action off
63 ;;
64 *)
65 echo "Usage: $0 start|stop" >&2
66 exit 3
67 ;;
68 esac
69
70 # vim:set tabstop=4 expandtab shiftwidth=4: