Import from Clearcase LIV_TRC6500_V2.2.3
[debian6500.git] / install / cluster / master / etc / init.d / wakeonlan
1 #!/bin/sh
2 VER=1.3
3 # ============================================================================
4 #
5 # Copyright (C) THALES. All rights reserved
6 # Author: Jean-Noel Raguenes
7 # Date : 07/12/2009
8 # - V1.1: Herve Petit 10/03/2010
9 # reprise de la commande recuperation des @mac et @broadcast pour prendre
10 # en compte le fait que l'interface eth1 a ete configuree
11 # - V1.2: Thomas Perennou 25/03/2013
12 # Adaptation Wheezy et simplification des recuperation des adresses mac
13 # et de broadcast
14 # - V1.4: Laurent Mazet 09/05/2014
15 # Daemonisation
16 # ============================================================================
17
18 ### BEGIN INIT INFO
19 # Provides: wakeonlan
20 # Required-Start: $network
21 # Required-Stop:
22 # Should-Start:
23 # Default-Start: S
24 # Default-Stop:
25 # Short-Description: WOL cluster blades
26 # Description: Boot all cluster blades by WakeOnLan protocol
27 ### END INIT INFO
28
29 DHCPCONF=/etc/dhcp/dhcpd.conf
30 ENABLE="yes"
31
32 PATH=/sbin:/usr/sbin:/bin:/usr/bin
33 [ -f /etc/default/wakeonlan ] && . /etc/default/wakeonlan
34 [ "$ENABLE" = "yes" ] || exit 0
35
36 . /lib/lsb/init-functions
37
38 do_start () {
39
40 log_action_msg "Activate Wake On Lan"
41
42 mac=$(awk '{ sub(/#.*/, "") } /trc[0-9]/ && ! /-rf/ { gsub(/;/, " "); print $6}' $DHCPCONF)
43 broadcast=$(ip add show dev eth1 |awk '$1=="inet" {sub(/\/.*/, ""); sub(/\.[0-9]*$/, ".255", $2); print $2; exit}')
44
45 for m in $mac; do
46 log_action_msg "Wake-up $broadcast ($m)"
47 wakeonlan -p 7 -i $broadcast $m
48 done
49 }
50
51 case "$1" in
52 -v)
53 echo "$(basename $0), version $VER"
54 ;;
55 start)
56 do_start
57 ;;
58 restart|reload|force-reload)
59 echo "Error: argument '$1' not supported" >&2
60 exit 3
61 ;;
62 stop)
63 # No-op
64 ;;
65 *)
66 echo "Usage: $0 start|stop" >&2
67 exit 3
68 ;;
69 esac
70
71 # vim:set tabstop=4 expandtab shiftwidth=4: