4e802319 |
1 | #!/bin/bash -e |
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 | # - Raffinage du calcul du nb de lames pour prendre en compte |
10 | # que les interfaces eth1 sont aussi declarees dans /etc/hosts |
11 | # - Ajout appel a reboot_fe306.sh |
12 | # - V1.2: Herve Petit 02/06/2010 |
13 | # - Ajout sleep 1 entre chaque appel reboot_fe306.sh car sinon seule la |
14 | # derniere fe306 etait rebootee |
15 | # - V1.3: Laurent Mazet 17/05/2013 |
16 | # ============================================================================ |
17 | |
18 | ### BEGIN INIT INFO |
19 | # Provides: shutdownallblades |
20 | # Required-Start: |
21 | # Required-Stop: nfs-kernel-server |
22 | # Default-Start: |
23 | # Default-Stop: 0 1 6 |
24 | # Short-Description: Shutdown all blades |
25 | # Description: |
26 | ### END INIT INFO |
27 | |
28 | REBOOT="no" |
29 | TIMEOUT=15 |
30 | ENABLE="yes" |
31 | |
32 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
33 | [ -f /etc/default/shutdownallblades ] && . /etc/default/shutdownallblades |
34 | [ "$ENABLE" = "yes" ] || exit 0 |
35 | |
36 | . /lib/lsb/init-functions |
37 | |
38 | do_stop () { |
39 | |
40 | # command |
41 | cmd="halt" |
42 | [ "$REBOOT" = "yes" -a ! "$(runlevel | cut -d' ' -f2)" = "0" ] && cmd="reboot" |
43 | |
44 | # stop lg6500core |
45 | lg6500core=/opt/trc6500/script/stop_trc6500.sh |
46 | if [ -x $lg6500core ]; then |
47 | log_action_msg "stoping lg6500core" |
48 | $lg6500core |
49 | fi |
50 | |
51 | # fe306 reboot |
52 | fe306=/opt/trc6500/script/reboot_fe306.sh |
53 | if [ -x $fe306 ]; then |
54 | for id in $(seq 1 6); do |
55 | host=fe306-$id |
56 | grep $host /etc/hosts >&/dev/null || continue |
57 | ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning $host"; $fe306 -i $host >&/dev/null; } ) & |
58 | done |
59 | fi |
60 | |
61 | # shutdown all blades |
62 | for host in $(awk '{sub(/#.*/, "")} /trc[0-9][0-9]/ && ! /-rf/ {print $2}' /etc/dhcp/dhcpd.conf); do |
63 | grep $host /etc/hosts >&/dev/null || continue |
64 | ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning ${host/_1}"; ssh root@$host service $cmd stop; } ) & |
65 | done |
66 | |
67 | trap "echo 'timeout expired ($TIMEOUT)'; exit 0;" SIGVTALRM |
68 | ( sleep $TIMEOUT; kill -SIGVTALRM $$ ) & |
69 | |
70 | wait |
71 | } |
72 | |
73 | case "$1" in |
74 | -v) |
75 | echo "$(basename $0), version $VER" |
76 | ;; |
77 | start) |
78 | # No-op |
79 | ;; |
80 | restart|reload|force-reload) |
81 | echo "Error: argument '$1' not supported" >&2 |
82 | exit 3 |
83 | ;; |
84 | stop) |
85 | do_stop |
86 | ;; |
87 | *) |
88 | echo "Usage: $0 start|stop" >&2 |
89 | exit 3 |
90 | ;; |
91 | esac |