aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/todo.rst1
-rwxr-xr-xshare/hydra/mass30
2 files changed, 26 insertions, 5 deletions
diff --git a/doc/todo.rst b/doc/todo.rst
index e064e46..28fed93 100644
--- a/doc/todo.rst
+++ b/doc/todo.rst
@@ -1,7 +1,6 @@
TODO
====
-- mass: check if current host is localhost.
- mount-media: lvm support.
- import-certs:
- concat.pem.
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