aboutsummaryrefslogtreecommitdiff
path: root/share/hydra/mass
blob: 3b1ed2de350f0454e530e5edb4af12e26d7ab000 (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
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# Execute commands on multiple nodes.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.

# Issue commands with pssh
function mass_pssh {
  hydra_check_command parallel-ssh
  parallel-ssh -P -p 4 -t 0 -h $TMPWORK sudo $COMMAND
}

# Issue commands with a for loop
function mass_loop {
  for node in `cat $TMPWORK`; do
    echo "Connecting to $node..."
    $HYDRA_CONNECT $node sudo $COMMAND
  done
}

# Issue commands with dish
function mass_dish {
  hydra_check_command dish
  dish -f -p /dev/null -e "sudo $COMMAND" -g $TMPWORK
}

# Issue commands with mussh
function mass_mussh {
  hydra_check_command mussh
  mussh -H $TMPWORK -c "sudo $COMMAND"
}

# Set nodes
function set_nodes {
  hydra_set_tmpfile nodes
  hydra $HYDRA nodes $1 > $TMPWORK
}

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

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

# Initial node list
BASEDIR="/tmp"
set_nodes

# Validation
if [ "$BASENAME" == "mass-update" ]; then
  COMMAND="aptitude update"
elif [ "$BASENAME" == "mass-upgrade" ]; then
  COMMAND="DEBIAN_FRONTEND=noninteractive hydractl upgrade clean"
elif [ "$BASENAME" == "mass-web" ]; then
  set_nodes web
fi

# Execute commands in hosts
echo "Issuing $COMMAND on multiple nodes..."
mass_pssh $COMMAND
hydra_unset_tmpfile $TMPWORK