#!/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 # . # 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