aboutsummaryrefslogtreecommitdiff
path: root/share/hydra/mass
blob: 142c6878dd4e29c3fa9e1d576b3907d032e5f2a2 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
# Execute commands on multiple nodes.
#

# Issue commands with pssh
function mass_pssh {
  echo "Issuing $COMMAND on multiple nodes..."
  hydra_set_tmpfile nodes
  hydra $HYDRA nodes > $TMPWORK
  parallel-ssh -t 40 -P -h $TMPWORK sudo $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
}

# Issue commands with dish
function mass_dish {
  echo "Issuing $COMMAND on multiple nodes..."
  hydra_set_tmpfile nodes
  hydra $HYDRA nodes > $TMPWORK
  dish -f -p /dev/null -e "sudo $COMMAND" -g $TMPWORK
  hydra_unset_tmpfile $TMPWORK
}

# Issue commands with mussh
function mass_mussh {
  echo "Issuing $COMMAND on multiple nodes..."
  hydra_set_tmpfile nodes
  hydra $HYDRA nodes > $TMPWORK
  mussh -H $TMPWORK -c "sudo $COMMAND"
  hydra_unset_tmpfile $TMPWORK
}

# 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-upgrade" ]; then
  COMMAND="aptitude safe-upgrade -y"
elif [ "$BASENAME" == "mass-web" ]; then
  NODES="`hydra $HYDRA nodes web`"
fi

# Execute commands in hosts
BASEDIR="/tmp"
mass_pssh $COMMAND