install-cluster.sh.in 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/bash
  2. ################################################################################
  3. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. ################################################################################
  17. #
  18. # Usage: install-cluster.sh
  19. #
  20. # This script is used as a remote engine for a cluster installation.
  21. #
  22. # Flow:
  23. #
  24. # 1. SSH Keys Generated.
  25. # 2. Run install-hpcc.sh through cluster-script.py to perform HPCC install and
  26. # configuration on remote hosts
  27. # 3. Return.
  28. #
  29. ###<REPLACE>###
  30. source ${INSTALL_DIR}/etc/init.d/hpcc_common
  31. source ${INSTALL_DIR}/etc/init.d/init-functions
  32. source ${INSTALL_DIR}/etc/init.d/export-path
  33. export REMOTE_INSTALL="/tmp/remote_install"
  34. export NEW="${REMOTE_INSTALL}/new_keys"
  35. export CMDPREFIX="sudo"
  36. print_usage(){
  37. echo ""
  38. echo "usage: install-cluster.sh [-h|--help] [-p|--pushkeydir <directory>] [-k|--newkey] [-n|--concurrent <number>] <Platform Package>"
  39. echo " -p: copy previously generated keys from a directory"
  40. echo " -k: generate a new ssh key pair."
  41. echo " -n: how many concurrent execution allowd. The default is 5"
  42. echo " <Platform Package>: HPCCSystems package file."
  43. echo ""
  44. exit 1
  45. }
  46. getUserAndPasswd(){
  47. trial=0
  48. max_trial=3
  49. while [ 1 ]
  50. do
  51. echo ""
  52. read -p "Please enter admin username: " ADMIN_USER;
  53. echo ""
  54. echo "Please enter ssh/scp user password. If this is no password required (assume"
  55. echo "the user has ssh private key: <user home>/.ssh/id_rsa) just press 'Enter':"
  56. read -s PASS
  57. echo ""
  58. password_string="and a password ($(echo $PASS | sed 's/./\./g'))."
  59. [ -z "$password_string" ] && password_string="with an empty password for passwordless login."
  60. echo "You entered user $ADMIN_USER $password_string"
  61. read -p "Are these correct? [Y|n] " answer
  62. if [ "$answer" = "Y" ] || [ "$answer" = "y" ]
  63. then
  64. break
  65. fi
  66. trial=$(expr $trial \+ 1)
  67. if [ $trial -eq $max_trial ]
  68. then
  69. echo ""
  70. echo "Exceeded maximum attempts. Giving up."
  71. echo ""
  72. exit 1
  73. fi
  74. done
  75. if [ "$file_transfer_user" == "root" ]
  76. then
  77. CMDPREFIX=""
  78. fi
  79. export ADMIN_USER
  80. export PASS
  81. }
  82. generateKey(){
  83. GENKEY=${PWD}/new_ssh
  84. if [ -d ${GENKEY} ]; then
  85. rm -rf ${GENKEY}
  86. fi
  87. mkdir -p ${GENKEY}
  88. ssh-keygen -t rsa -f ${GENKEY}/id_rsa -P ""
  89. }
  90. createPayload(){
  91. if [ -d ${REMOTE_INSTALL} ]; then
  92. rm -rf ${REMOTE_INSTALL};
  93. fi
  94. mkdir -p ${REMOTE_INSTALL};
  95. if [ ${NEW_KEY} -eq 1 ]; then
  96. mkdir -p ${NEW}
  97. cp -r ${GENKEY}/* ${NEW}/
  98. elif [[ ${COPY_KEY} -eq 1 && -n $KEY_DIR ]]; then
  99. mkdir -p ${NEW}
  100. cp -r ${KEY_DIR}/* ${NEW}/
  101. fi
  102. cp -r ${PKG} ${REMOTE_INSTALL}
  103. cp -r ${CONFIG_DIR}/${ENV_XML_FILE} ${REMOTE_INSTALL}
  104. cp -r ${CONFIG_DIR}/${ENV_CONF_FILE} ${REMOTE_INSTALL}
  105. cp -r ${INSTALL_DIR}/sbin/remote-install-engine.sh ${REMOTE_INSTALL}
  106. echo "tar -zcvf /tmp/remote_install.tgz ${REMOTE_INSTALL}/*"
  107. tar -zcvf /tmp/remote_install.tgz ${REMOTE_INSTALL}/*
  108. ls -l /tmp/remote_install.tgz
  109. rm -rf ${REMOTE_INSTALL}
  110. }
  111. removePayload(){
  112. rm /tmp/remote_install.tgz
  113. }
  114. ######################################################################
  115. #
  116. # MAIN
  117. #
  118. ######################################################################
  119. cluster_tools_init
  120. if [ "$(whoami)" != "root" ]; then
  121. echo ""
  122. echo "The script must run as root or sudo."
  123. echo ""
  124. exit 1
  125. fi
  126. NEW_KEY=0
  127. COPY_KEY=0
  128. OPTIONS="-l DEBUG -e ${CONFIG_DIR}/${ENV_CONF_FILE} -s ${SECTION:-DEFAULT}"
  129. TEMP=`/usr/bin/getopt -o p:n:s:kh --long help,pushkeydir,newkey,concurrent: -n 'install-cluster' -- "$@"`
  130. if [ $? != 0 ] ; then echo "Failure to parse commandline." >&2 ; exit 1 ; fi
  131. eval set -- "$TEMP"
  132. while true ; do
  133. case "$1" in
  134. -k|--newkey)
  135. NEW_KEY=1
  136. if [[ $COPY_KEY -eq 1 ]]; then
  137. echo "Cannot use both [-p|--pushkeydir] and [-k|--newkey] options"
  138. exit 1
  139. fi
  140. shift ;;
  141. -p|--pushkeydir)
  142. COPY_KEY=1
  143. KEY_DIR=$2
  144. if [[ $NEW_KEY -eq 1 ]]; then
  145. echo "Cannot use both [-p|--pushkeydir] and [-k|--newkey] options"
  146. exit 1
  147. fi
  148. shift 2 ;;
  149. -n|--concurrent)
  150. if [ -n "$2" ] && [[ $2 =~ ^[0-9]+$ ]]
  151. then
  152. [ $2 -gt 0 ] && OPTOINS="${OPTIONS:+"$OPTIONS "}-n $2"
  153. fi
  154. shift 2 ;;
  155. -h|--help) print_usage
  156. shift ;;
  157. --) shift ; break ;;
  158. *) print_usage ;;
  159. esac
  160. done
  161. for arg do arg=$arg; done
  162. PKG=${arg}
  163. [ -z "$PKG" ] && print_usage
  164. export PKG
  165. getUserAndPasswd
  166. pkgtype=`echo "${PKG}" | grep -i rpm`
  167. if [ -z $pkgtype ]; then
  168. pkgcmd="dpkg"
  169. else
  170. pkgcmd="rpm"
  171. fi
  172. if [ ${NEW_KEY} -eq 1 ]; then
  173. generateKey
  174. fi
  175. export NEW_KEY
  176. export KEY_DIR
  177. createPayload;
  178. expected_python_version=3.4
  179. is_python_installed ${expected_python_version}
  180. if [ $? -eq 0 ]
  181. then
  182. chksum=$(md5sum ${INSTALL_DIR}/sbin/install-hpcc.exp | cut -d' ' -f1)
  183. eval ${INSTALL_DIR}/sbin/cluster_script.py -f ${INSTALL_DIR}/sbin/install-hpcc.exp -c $chksum $OPTIONS
  184. else
  185. echo ""
  186. echo "Cannot detect python version ${expected_python_version}+. Will run on the cluster hosts sequentially."
  187. echo ""
  188. run_cluster ${INSTALL_DIR}/sbin/install-hpcc.exp 0
  189. fi
  190. removePayload;