401992e9c37564c16bdf113271e9eba2a61b6636
[debian6500.git] / master / etc / init.d / etherwake
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 pour prendre
10 # en compte le fait que l'interface eth1 a ete configuree
11 # - V1.2: Herve Petit 04/06/2010
12 # etude probleme non demarrage lames esclave par tuning temps total et
13 # temps entre 2 wake
14 # - V1.3: Laurent Mazet 02/05/2013
15 # Daemonisation
16 # ============================================================================
17
18 ### BEGIN INIT INFO
19 # Provides: etherwake
20 # Required-Start: $network
21 # Required-Stop:
22 # Should-Start:
23 # Default-Start: S
24 # Default-Stop:
25 # Short-Description: EW cluster blades
26 # Description: Boot all cluster blades by EtherWake protocol
27 ### END INIT INFO
28
29 DHCPCONF=/etc/dhcp/dhcpd.conf
30 GROUP_SIZE=5
31 NB_TRY=2
32 ENABLE="yes"
33
34 PATH=/sbin:/usr/sbin:/bin:/usr/bin
35 [ -f /etc/default/etherwake ] && . /etc/default/etherwake
36 [ "$ENABLE" = "yes" ] || exit 0
37
38 . /lib/lsb/init-functions
39
40 do_start () {
41
42 log_action_msg "Activate EtherWake"
43
44 sleep 1
45 n=0
46 while [ $NB_TRY -gt 0 ]; do
47
48 for mac in $(awk '{sub(/#.*/, "")} /trc[0-9]/ {gsub(/;/, " "); print $6}' $DHCPCONF); do
49 host=$(awk '{sub(/#.*/, "")} /'$mac'/ {print $2}' $DHCPCONF)
50
51 log_action_msg "Wake-up $host ($mac)"
52 etherwake $mac
53
54 n=$(expr $n + 1)
55 [ $(expr $n % $GROUP_SIZE) -eq 0 ] && sleep 1
56
57 done
58
59 NB_TRY=$(expr $NB_TRY - 1)
60 done
61 }
62
63 case "$1" in
64 -v)
65 echo "$(basename $0), version $VER"
66 ;;
67 start)
68 do_start
69 ;;
70 restart|reload|force-reload)
71 echo "Error: argument '$1' not supported" >&2
72 exit 3
73 ;;
74 stop)
75 # No-op
76 ;;
77 *)
78 echo "Usage: $0 start|stop" >&2
79 exit 3
80 ;;
81 esac
82
83 # vim:set tabstop=4 expandtab shiftwidth=4: