123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #!/bin/bash
- ################################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ################################################################################
- #
- # Uusage: hpcc-push.sh -s <source> -t <target> -n <number_concurrent> -x
- #
- # This is acomplished with a standard scp command with the use of the
- # runtime users id_rsa file.
- ###<REPLACE>###
- source ${INSTALL_DIR}/etc/init.d/hpcc_common
- source ${INSTALL_DIR}/etc/init.d/init-functions
- source ${INSTALL_DIR}/etc/init.d/export-path
- usage() {
- echo ""
- echo "usage: hpcc-push.sh -s <source> -t <target> -n <concurrent> -x"
- echo " -n: when specified, denotes the number of concurrent executions threads."
- echo " The default is 5."
- echo " -s: source file or directory."
- echo " -t: target file or directory."
- echo " -x: when specified, this option excludes execution on the current host."
- echo ""
- exit 1
- }
- createScriptFile() {
- cat > $SCRIPT_FILE <<SCRIPTFILE
- #~/bin/bash
- IP=\$1
- if ping -c 1 -w 5 -n \$IP > /dev/null 2>&1; then
- echo "\$IP: Host is alive."
- CAN_SSH="\`ssh -i $home/$user/.ssh/id_rsa -o BatchMode=yes -o LogLevel=QUIET -o StrictHostKeyChecking=no $user@\$IP exit > /dev/null 2>&1; echo \$?\`"
- if [ "\$CAN_SSH" -eq 255 ]; then
- echo "\$IP: Cannot SSH to host.";
- else
- echo "\$IP: Copying $source to $target on \$IP";
- SCP=\$(scp -r -i $home/$user/.ssh/id_rsa $source $user@\$IP:$target; echo \$?)
- if [ "\$SCP" -eq 0 ]; then
- echo "\$IP: Success";
- else
- echo "\$IP: Failure";
- exit 1
- fi
- fi
- else
- echo "\$IP: Cannot Ping host? (Host Alive?)"
- exit 1
- fi
- SCRIPTFILE
- chmod +x ${SCRIPT_FILE}
- }
- ############################################
- #
- # MAIN
- #
- ############################################
- cluster_tools_init
- if [ "$(whoami)" != "root" ] && [ "$(whoami)" != "${user}" ]; then
- echo ""
- echo "The script must run as root, $user or sudo."
- echo ""
- exit 1
- fi
- source=
- target=
- exclude=0
- OPTION="-e ${CONFIG_DIR}/${ENV_CONF_FILE} -s ${SECTION:-DEFAULT}"
- TEMP=`/usr/bin/getopt -o n:s:t:hx --long help,conrrent:,source:,target:,exclude -n 'hpcc-push' -- "$@"`
- if [ $? != 0 ] ; then echo "Failure to parse commandline." >&2 ; end 1 ; fi
- eval set -- "$TEMP"
- while true ; do
- case "$1" in
- -n|--concurrent)
- if [ -n "$2" ] && [[ $2 =~ ^[0-9]+$ ]]
- then
- [ $2 -gt 0 ] && $OPTION="${OPTION:+"$OPTION "}-n $2"
- fi
- shift 2 ;;
- -s|--source) source="$2"
- shift 2 ;;
- -t|--target) target="$2"
- shift 2 ;;
- -x|--exclude) OPTION="${OPTION:+"$OPTION "}-x"
- exclude=1
- shift ;;
- -h|--help) usage
- shift ;;
- --) shift ; break ;;
- *) usage ;;
- esac
- done
- if [ -z "$source" ] || [ -z "$target" ]; then
- usage
- fi
- SCRIPT_FILE=~/hpcc-push_$$
- createScriptFile
- python_expected_version=3.4
- is_python_installed ${python_expected_version}
- if [ $? -eq 0 ]
- then
- eval ${INSTALL_DIR}/sbin/cluster_script.py -f ${SCRIPT_FILE} $OPTION
- else
- echo ""
- echo "Cannot detect python version ${python_expected_version}+. Will run on the cluster hosts sequentially."
- echo ""
- run_cluster ${SCRIPT_FILE} ${exclude}
- fi
- rm -rf ${SCRIPT_FILE}
|