scp-hosts.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. workDir=`dirname $0`
  19. workDir=`cd ${workDir};pwd`
  20. source ${workDir}/env/install_env.sh
  21. workersGroup=(${workers//,/ })
  22. for workerGroup in ${workersGroup[@]}
  23. do
  24. echo $workerGroup;
  25. worker=`echo $workerGroup|awk -F':' '{print $1}'`
  26. group=`echo $workerGroup|awk -F':' '{print $2}'`
  27. workerNames+=($worker)
  28. groupNames+=(${group:-default})
  29. done
  30. hostsArr=(${ips//,/ })
  31. for host in ${hostsArr[@]}
  32. do
  33. if ! ssh -o StrictHostKeyChecking=no -p $sshPort $host test -e $installPath; then
  34. ssh -o StrictHostKeyChecking=no -p $sshPort $host "sudo mkdir -p $installPath; sudo chown -R $deployUser:$deployUser $installPath"
  35. fi
  36. echo "scp dirs to $host/$installPath starting"
  37. for i in ${!workerNames[@]}; do
  38. if [[ ${workerNames[$i]} == $host ]]; then
  39. workerIndex=$i
  40. break
  41. fi
  42. done
  43. # set worker groups in application.yaml
  44. [[ -n ${workerIndex} ]] && sed -i "s/- default/- ${groupNames[$workerIndex]}/" $workDir/../worker-server/conf/application.yaml
  45. for dsDir in bin master-server worker-server alert-server api-server ui tools
  46. do
  47. echo "start to scp $dsDir to $host/$installPath"
  48. # Use quiet mode to reduce command line output
  49. scp -q -P $sshPort -r $workDir/../$dsDir $host:$installPath
  50. done
  51. # restore worker groups to default
  52. [[ -n ${workerIndex} ]] && sed -i "s/- ${groupNames[$workerIndex]}/- default/" $workDir/../worker-server/conf/application.yaml
  53. echo "scp dirs to $host/$installPath complete"
  54. done