Commit | Line | Data |
---|---|---|
480e6d02 LM |
1 | #!/bin/bash |
2 | VER=1.0 | |
3 | # ============================================================================ | |
4 | # | |
5 | # Copyright (C) THALES. All rights reserved | |
6 | # Author: Laurent Mazet | |
7 | # Date : 12/12/2014 | |
8 | # ============================================================================ | |
9 | ||
10 | ### BEGIN INIT INFO | |
11 | # Provides: ammwake | |
12 | # Required-Start: $network waitswitches | |
13 | # Required-Stop: | |
14 | # Should-Start: | |
15 | # Default-Start: S | |
16 | # Default-Stop: | |
17 | # Short-Description: Wake cluster blades (AMM command) | |
18 | # Description: Boot all cluster blades by AMM power command | |
19 | ### END INIT INFO | |
20 | ||
21 | HOSTS="/etc/hosts" | |
22 | ENABLE="yes" | |
7cf8d4b7 LM |
23 | SCRIPTS=/opt/script/set_blade_power.tcl /opt/trc6500/script/set_blade_power.tcl |
24 | SCRIPT= | |
480e6d02 LM |
25 | |
26 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
27 | ||
28 | [ -f /etc/default/ammwake ] && . /etc/default/ammwake | |
7cf8d4b7 LM |
29 | for s in $SCRIPTS; do [ -x $s ] && SCRIPT=$s; done |
30 | [ -x "$SCRIPT" ] || exit 1 | |
480e6d02 LM |
31 | [ "$ENABLE" = "yes" ] || exit 0 |
32 | ||
33 | . /lib/lsb/init-functions | |
34 | ||
35 | do_action () { | |
36 | ACTION=$1 | |
37 | ||
38 | log_action_msg "Send AMM power $ACTION command" | |
39 | ||
40 | for amm in $(awk '{ sub(/#.*/, "") } /amm[0-9]/ { print $2}' $HOSTS); do | |
41 | ping -c 1 $amm >&/dev/null || continue | |
42 | for id in $(seq 1 14); do | |
43 | [ $id -eq 1 -a "$amm" = amm00 ] && continue | |
44 | ||
45 | log_action_msg "Wake-up blade-$id (AMM $amm $id $ACTION)" | |
46 | $SCRIPT $amm -b $id -$ACTION >&/dev/null || log_failure_msg "Can't power $ACTION blade $id on $amm" | |
47 | done | |
48 | done | |
49 | } | |
50 | ||
51 | case "$1" in | |
52 | -v) | |
53 | echo "$(basename $0), version $VER" | |
54 | ;; | |
55 | start) | |
56 | do_action on | |
57 | ;; | |
58 | restart|reload|force-reload) | |
59 | echo "Error: argument '$1' not supported" >&2 | |
60 | exit 3 | |
61 | ;; | |
62 | stop) | |
63 | do_action off | |
64 | ;; | |
65 | *) | |
66 | echo "Usage: $0 start|stop" >&2 | |
67 | exit 3 | |
68 | ;; | |
69 | esac | |
70 | ||
71 | # vim:set tabstop=4 expandtab shiftwidth=4: |