From 813b51e929051de8095572ac8cdb629fd441cddd Mon Sep 17 00:00:00 2001 From: Paul Caskey Date: Thu, 29 Jun 2017 10:17:41 -0500 Subject: [PATCH 1/2] add script to sync swarm files --- setNewSealerKey.sh => bin/setNewSealerKey.sh | 0 bin/syncFilesToAllSwarmNodes.sh | 86 ++++++++++++++++++++ 2 files changed, 86 insertions(+) rename setNewSealerKey.sh => bin/setNewSealerKey.sh (100%) mode change 100755 => 100644 create mode 100644 bin/syncFilesToAllSwarmNodes.sh diff --git a/setNewSealerKey.sh b/bin/setNewSealerKey.sh old mode 100755 new mode 100644 similarity index 100% rename from setNewSealerKey.sh rename to bin/setNewSealerKey.sh diff --git a/bin/syncFilesToAllSwarmNodes.sh b/bin/syncFilesToAllSwarmNodes.sh new file mode 100644 index 0000000..89df4eb --- /dev/null +++ b/bin/syncFilesToAllSwarmNodes.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +#ensure realpath is avail +command -v realpath >/dev/null 2>&1 || { echo >&2 "ERROR: realpath is required, but doesn't appear to be installed. Aborting..."; exit 1; } + + +IDfile=`realpath $4` + + +DisplayUsage() +{ + echo "Usage:" + echo "syncFilesToAllNodes | --help" >&2 + echo "" +} + +#ensure docker is avail +command -v docker >/dev/null 2>&1 || { echo >&2 "ERROR: docker is required, but doesn't appear to be installed. Aborting..."; exit 1; } + + +#check if running on a manager node +docker node ls > /dev/null 2>&1 +if [ $? = 1 ]; then + echo "This script must be run from a manager node. You do not appear to be on a manager node. Terminating." + exit 1 +fi + + +if [ $1 = '--help' ]; then + DisplayUsage + exit 1 +fi + + +#sanity checks +if [[ $# -ne 4 ]]; then + DisplayUsage + exit 1 +fi + +#more checks +if ! [ -e "$1" ]; then + echo "ERROR: $1 not found, terminating." >&2 + echo "" + exit 1 +fi +if ! [ -d "$1" ]; then + echo "ERROR: $1 is not a directory, terminating." >&2 + echo "" + exit 1 +fi +if ! [ -e "$4" ]; then + echo "ERROR: $4 not found, terminating." >&2 + echo "" + exit 1 +fi + + +#cd to specified dir (so that scp -r works as intended) +pushd $1 > /dev/null + + +#check if specified config dir contains (some of) the needed sub-directories +if ! [ -d "$PWD/config/shib-idp/conf" ]; then + echo "ERROR: the specified directory does not appear to contain a valid IdP config structure, terminating." + exit 1 +fi +if ! [ -d "$PWD/config/tomcat" ]; then + echo "ERROR: the specified directory does not appear to contain a valid Tomcat config, terminating." + exit 1 +fi + + +# transfer files +# +# get list of other nodes in the swarm + for n in `docker node ls | sed -n '1!p' | cut -f 1 -d ' '`; do + #echo $n + s=$(docker node inspect --pretty $n | grep Address | cut -f 2 -d ':' | sed -n '2!p') + thisNode=${s//[[:blank:]]/} + echo "Connecting to ${thisNode} (`dig +noall +answer -x ${thisNode} | awk '{ print $(NF) }'`)....`scp -q -i ${IDfile} -r . $3@${thisNode}:/home/$3/$2 > /dev/null 2>&1`OK" + done + + +#return to previous directory +popd > /dev/null From e0603e158fda230f4e9c07d0ccd41188d342d81d Mon Sep 17 00:00:00 2001 From: Paul Caskey Date: Thu, 29 Jun 2017 10:21:34 -0500 Subject: [PATCH 2/2] add a few extra checks to sync script --- bin/syncFilesToAllSwarmNodes.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/syncFilesToAllSwarmNodes.sh b/bin/syncFilesToAllSwarmNodes.sh index 89df4eb..5c88fab 100644 --- a/bin/syncFilesToAllSwarmNodes.sh +++ b/bin/syncFilesToAllSwarmNodes.sh @@ -1,9 +1,20 @@ #!/bin/bash +#ensure dig is avail +command -v dig >/dev/null 2>&1 || { echo >&2 "ERROR: dig is required, but doesn't appear to be installed. Aborting..."; exit 1; } + +#ensure sed is avail +command -v sed >/dev/null 2>&1 || { echo >&2 "ERROR: sed is required, but doesn't appear to be installed. Aborting..."; exit 1; } + +#ensure awk is avail +command -v awk >/dev/null 2>&1 || { echo >&2 "ERROR: awk is required, but doesn't appear to be installed. Aborting..."; exit 1; } + +#ensure scp is avail +command -v scp >/dev/null 2>&1 || { echo >&2 "ERROR: scp is required, but doesn't appear to be installed. Aborting..."; exit 1; } + #ensure realpath is avail command -v realpath >/dev/null 2>&1 || { echo >&2 "ERROR: realpath is required, but doesn't appear to be installed. Aborting..."; exit 1; } - IDfile=`realpath $4`