correct service
[debian6500.git] / master / etc / init.d / wakeonlan
1 #!/bin/sh
2 VER=1.5
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 # - V1.5: Laurent Mazet & Thomas Perennou 03/12/2014
17 # Legers correctifs
18 # ============================================================================
19
20 ### BEGIN INIT INFO
21 # Provides: wakeonlan
22 # Required-Start: $network waitswitches
23 # Required-Stop:
24 # Should-Start:
25 # Default-Start: S
26 # Default-Stop:
27 # Short-Description: WOL cluster blades
28 # Description: Boot all cluster blades by WakeOnLan protocol
29 ### END INIT INFO
30
31 DHCPCONF=/etc/dhcp/dhcpd.conf
32 ENABLE="yes"
33
34 PATH=/sbin:/usr/sbin:/bin:/usr/bin
35 [ -f /etc/default/wakeonlan ] && . /etc/default/wakeonlan
36 [ "$ENABLE" = "yes" ] || exit 0
37
38 . /lib/lsb/init-functions
39
40 do_start () {
41
42 log_action_msg "Activate Wake On Lan"
43
44 for mac in $(awk '{sub(/#.*/, "")} /host\s+trc[0-9]/ { gsub(/[;{}]/, " "); print $5}' $DHCPCONF); do
45 broadcast=$(awk '{sub(/#.*/, "")} /'$mac'/ {print}' $DHCPCONF | sed 's/.* \([0-9.]*\)\..*/\1.255/')
46 host=$(awk '{sub(/#.*/, "")} /'$mac'/ {gsub(/[{}]/, " "); print $2}' $DHCPCONF)
47 log_action_msg "Wake-up $host (WOL $mac $broadcast)"
48 wakeonlan -p 7 -i $broadcast $mac
49 done
50 }
51
52 case "$1" in
53 -v)
54 echo "$(basename $0), version $VER"
55 ;;
56 start)
57 do_start
58 ;;
59 restart|reload|force-reload)
60 echo "Error: argument '$1' not supported" >&2
61 exit 3
62 ;;
63 stop)
64 # No-op
65 ;;
66 *)
67 echo "Usage: $0 start|stop" >&2
68 exit 3
69 ;;
70 esac
71
72 # vim:set tabstop=4 expandtab shiftwidth=4: