Move install/* to .
[debian6500.git] / cluster / master / etc / init.d / etherwake
diff --git a/cluster/master/etc/init.d/etherwake b/cluster/master/etc/init.d/etherwake
new file mode 100755 (executable)
index 0000000..4c10152
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/sh
+VER=1.3
+# ============================================================================
+#
+# Copyright (C) THALES. All rights reserved
+# Author: Jean-Noel Raguenes
+# Date : 07/12/2009
+# - V1.1: Herve Petit 10/03/2010
+#   reprise de la commande recuperation des @mac pour prendre
+#   en compte le fait que l'interface eth1 a ete configuree
+# - V1.2: Herve Petit 04/06/2010
+#   etude probleme non demarrage lames esclave par tuning temps total et
+#   temps entre 2 wake
+# - V1.3: Laurent Mazet 02/05/2013
+#   Daemonisation
+# ============================================================================
+
+### BEGIN INIT INFO
+# Provides:          etherwake
+# Required-Start:    $network
+# Required-Stop:
+# Should-Start:
+# Default-Start:     S
+# Default-Stop:
+# Short-Description: EW cluster blades
+# Description:       Boot all cluster blades by EtherWake protocol
+### END INIT INFO
+
+DHCPCONF=/etc/dhcp/dhcpd.conf
+GROUP_SIZE=5
+NB_TRY=1
+ENABLE="yes"
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+[ -f /etc/default/etherwake ] && . /etc/default/etherwake
+[ "$ENABLE" = "yes" ] || exit 0
+
+. /lib/lsb/init-functions
+
+do_start () {
+
+    log_action_msg "Activate EtherWake"
+
+    n=0
+    while [ $NB_TRY -gt 0 ]; do
+
+        for mac in $(awk '{sub(/#.*/, "")} /trc[0-9]/ && /-rf/ {gsub(/;/, " "); print $6}' $DHCPCONF); do
+            host=$(awk '{sub(/#.*/, "")} /'$mac'/ {print $2}' $DHCPCONF)
+
+            log_action_msg "Wake-up $host ($mac)"
+            etherwake $mac
+
+           n=$(expr $n + 1)
+           [ $(expr $n % $GROUP_SIZE) -eq 0 ] && sleep 1
+
+        done
+
+       NB_TRY=$(expr $NB_TRY - 1)
+    done
+}
+
+case "$1" in
+    -v)
+        echo "$(basename $0), version $VER"
+        ;;
+    start)
+        do_start
+        ;;
+    restart|reload|force-reload)
+        echo "Error: argument '$1' not supported" >&2
+        exit 3
+        ;;
+    stop)
+        # No-op
+        ;;
+    *)
+        echo "Usage: $0 start|stop" >&2
+        exit 3
+        ;;
+esac
+
+# vim:set tabstop=4 expandtab shiftwidth=4: