summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rwxr-xr-xshare/hydra/mass30
1 files changed, 26 insertions, 4 deletions
diff --git a/share/hydra/mass b/share/hydra/mass
index ba5bddd..871468c 100755
--- a/share/hydra/mass
+++ b/share/hydra/mass
@@ -43,11 +43,23 @@ function mass_mussh {
}
# Set nodes
-function set_nodes {
+function mass_set_nodes {
hydra_set_tmpfile nodes
hydra $HYDRA nodes $1 > $TMPWORK
}
+# Execute command on localhost
+function mass_exec_localhost {
+ if grep -q -e "^$LOCAL$" $TMPWORK; then
+ # Remove localhost from node list
+ grep -v -e "^$LOCAL$" $TMPWORK > $TMPWORK.tmp
+ mv $TMPWORK.tmp $TMPWORK
+
+ echo "Issuing command on localhost..."
+ $SUDO $COMMAND
+ fi
+}
+
# Load
source $APP_BASE/lib/hydra/functions || exit 1
hydra_config_load
@@ -58,16 +70,26 @@ COMMAND="$*"
# Initial node list
BASEDIR="/tmp"
-set_nodes
+LOCAL="`facter fqdn`"
+mass_set_nodes
+
+# Set sudo config
+if [ "$WHOAMI" != 'root' ]; then
+ sudo="sudo"
+else
+ echo "Sorry, cannot run as root"
+ exit 1
+fi
# Validation
if [ "$BASENAME" == "mass-upgrade" ]; then
COMMAND="DEBIAN_FRONTEND=noninteractive hydractl upgrade clean"
elif [ "$BASENAME" == "mass-web" ]; then
- set_nodes web
+ mass_set_nodes web
fi
# Execute commands in hosts
echo "Issuing $COMMAND on multiple nodes..."
-mass_pssh $COMMAND
+mass_exec_localhost
+mass_pssh
hydra_unset_tmpfile $TMPWORK