almost every thing is ready
[debian6500.git] / master / etc / init.d / shutdownallblades
diff --git a/master/etc/init.d/shutdownallblades b/master/etc/init.d/shutdownallblades
new file mode 100755 (executable)
index 0000000..29cfd31
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/bash -e
+VER=1.3
+# ============================================================================
+# 
+# Copyright (C) THALES. All rights reserved
+# Author: Jean-Noel Raguenes
+# Date : 07/12/2009
+# - V1.1: Herve Petit 10/03/2010
+#   - Raffinage du calcul du nb de lames pour prendre en compte
+#   que les interfaces eth1 sont aussi declarees dans /etc/hosts 
+#   - Ajout appel a reboot_fe306.sh
+# - V1.2: Herve Petit 02/06/2010
+#   - Ajout sleep 1 entre chaque appel reboot_fe306.sh car sinon seule la
+#     derniere fe306 etait rebootee 
+# - V1.3: Laurent Mazet 17/05/2013
+# ============================================================================
+
+### BEGIN INIT INFO
+# Provides:   shutdownallblades       
+# Required-Start:
+# Required-Stop: nfs-kernel-server
+# Default-Start:     
+# Default-Stop:        0 1 6
+# Short-Description: Shutdown all blades
+# Description:
+### END INIT INFO
+
+REBOOT="no"
+TIMEOUT=15
+ENABLE="yes"
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+[ -f /etc/default/shutdownallblades ] && . /etc/default/shutdownallblades
+[ "$ENABLE" = "yes" ] || exit 0
+
+. /lib/lsb/init-functions
+
+do_stop () {
+
+    # command
+    cmd="halt"
+    [ "$REBOOT" = "yes" -a ! "$(runlevel | cut -d' ' -f2)" = "0" ] && cmd="reboot"
+
+    # stop lg6500core
+    lg6500core=/opt/trc6500/script/stop_trc6500.sh
+    if [ -x $lg6500core ]; then
+       log_action_msg "stoping lg6500core"
+        $lg6500core
+    fi
+
+    # fe306 reboot
+    fe306=/opt/trc6500/script/reboot_fe306.sh
+    if [ -x $fe306 ]; then
+        for id in $(seq 1 6); do
+            host=fe306-$id
+            grep $host /etc/hosts >&/dev/null || continue
+            ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning $host"; $fe306 -i $host >&/dev/null; } ) &
+        done
+    fi
+
+    # shutdown all blades
+    for host in $(awk '{sub(/#.*/, "")} /trc[0-9][0-9]/ && ! /-rf/ {print $2}' /etc/dhcp/dhcpd.conf); do
+       grep $host /etc/hosts >&/dev/null || continue
+       ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning ${host/_1}"; ssh root@$host service $cmd stop; } ) &
+    done
+
+    trap "echo 'timeout expired ($TIMEOUT)'; exit 0;" SIGVTALRM
+    ( sleep $TIMEOUT; kill -SIGVTALRM $$ ) &
+
+    wait
+}
+
+case "$1" in
+    -v)
+        echo "$(basename $0), version $VER"
+       ;;
+    start)
+        # No-op
+        ;;
+    restart|reload|force-reload)
+        echo "Error: argument '$1' not supported" >&2
+        exit 3
+        ;;
+    stop)
+        do_stop
+        ;;
+    *)
+        echo "Usage: $0 start|stop" >&2
+        exit 3
+        ;;
+esac