aboutsummaryrefslogtreecommitdiff
path: root/share/hydra/mass
blob: 981f31fc16d408b9369cc2fad6a69e943f477ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# Execute commands on multiple nodes.
#

# Issue commands with pssh
# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549117
function mass_pssh {
  hydra_set_tmpfile nodes
  hydra $HYDRA nodes > $TMPWORK
  parallel-ssh -h $TMPWORK -p 4 $COMMAND
  hydra_unset_tmpfile $TMPWORK
}

# Issue commands with a for loop
function mass_loop {
  for node in $NODES; do
    echo "Issuing $COMMAND on multiple nodes..."
    echo "Connecting to $node..."
    $HYDRA_CONNECT $node sudo $COMMAND
  done
}

# Load
source $APP_BASE/lib/hydra/functions || exit 1
hydra_config_load

# Command line arguments
BASENAME="`basename $0`"
COMMAND="$*"

# Initial node list
NODES="`hydra $HYDRA nodes`"

# Validation
if [ "$BASENAME" == "mass-update" ]; then
  COMMAND="aptitude update"
elif [ "$BASENAME" == "mass-update" ]; then
  COMMAND="aptitude safe-upgrade"
elif [ "$BASENAME" == "mass-web" ]; then
  NODES="`hydra $HYDRA nodes web`"
fi

# Execute commands in hosts
mass_loop $COMMAND