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 | |
aa1a77f3 |
28 | DHCPCONF=/etc/dhcp/dhcpd.conf |
4e802319 |
29 | REBOOT="no" |
30 | TIMEOUT=15 |
31 | ENABLE="yes" |
32 | |
33 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
34 | [ -f /etc/default/shutdownallblades ] && . /etc/default/shutdownallblades |
35 | [ "$ENABLE" = "yes" ] || exit 0 |
36 | |
37 | . /lib/lsb/init-functions |
38 | |
39 | do_stop () { |
40 | |
41 | # command |
42 | cmd="halt" |
43 | [ "$REBOOT" = "yes" -a ! "$(runlevel | cut -d' ' -f2)" = "0" ] && cmd="reboot" |
44 | |
45 | # stop lg6500core |
46 | lg6500core=/opt/trc6500/script/stop_trc6500.sh |
47 | if [ -x $lg6500core ]; then |
48 | log_action_msg "stoping lg6500core" |
49 | $lg6500core |
50 | fi |
51 | |
52 | # fe306 reboot |
53 | fe306=/opt/trc6500/script/reboot_fe306.sh |
54 | if [ -x $fe306 ]; then |
55 | for id in $(seq 1 6); do |
56 | host=fe306-$id |
57 | grep $host /etc/hosts >&/dev/null || continue |
58 | ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning $host"; $fe306 -i $host >&/dev/null; } ) & |
59 | done |
60 | fi |
61 | |
62 | # shutdown all blades |
aa1a77f3 |
63 | for host in $(awk '{sub(/#.*/, "")} /host\s+trc[0-9][0-9]/ && ! /-rf/ {print $2}' $DHCPCONF); do |
4e802319 |
64 | grep $host /etc/hosts >&/dev/null || continue |
65 | ( ping -c 1 $host >&/dev/null && { log_action_msg "shutdowning ${host/_1}"; ssh root@$host service $cmd stop; } ) & |
66 | done |
67 | |
68 | trap "echo 'timeout expired ($TIMEOUT)'; exit 0;" SIGVTALRM |
69 | ( sleep $TIMEOUT; kill -SIGVTALRM $$ ) & |
70 | |
71 | wait |
72 | } |
73 | |
74 | case "$1" in |
75 | -v) |
76 | echo "$(basename $0), version $VER" |
77 | ;; |
78 | start) |
79 | # No-op |
80 | ;; |
81 | restart|reload|force-reload) |
82 | echo "Error: argument '$1' not supported" >&2 |
83 | exit 3 |
84 | ;; |
85 | stop) |
86 | do_stop |
87 | ;; |
88 | *) |
89 | echo "Usage: $0 start|stop" >&2 |
90 | exit 3 |
91 | ;; |
92 | esac |