install-helper.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information rega4rding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #########################################postinstall.sh#########################
  16. # SERVER INSTALL HELPER #
  17. ##################################################################
  18. ROOT="${RPM_INSTALL_PREFIX}" # Customized folder, which ambari-server files are installed into ('/' or '' are default).
  19. COMMON_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_commons"
  20. RESOURCE_MANAGEMENT_DIR="${ROOT}/usr/lib/python2.6/site-packages/resource_management"
  21. JINJA_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_jinja2"
  22. SIMPLEJSON_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_simplejson"
  23. OLD_COMMON_DIR="${ROOT}/usr/lib/python2.6/site-packages/common_functions"
  24. AMBARI_SERVER="${ROOT}/usr/lib/python2.6/site-packages/ambari_server"
  25. INSTALL_HELPER_AGENT="/var/lib/ambari-agent/install-helper.sh"
  26. CA_CONFIG="${ROOT}/var/lib/ambari-server/keys/ca.config"
  27. COMMON_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/ambari_commons"
  28. RESOURCE_MANAGEMENT_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/resource_management"
  29. JINJA_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_jinja2"
  30. SIMPLEJSON_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_simplejson"
  31. AMBARI_PROPERTIES="${ROOT}/etc/ambari-server/conf/ambari.properties"
  32. AMBARI_ENV_RPMSAVE="${ROOT}/var/lib/ambari-server/ambari-env.sh.rpmsave" # this turns into ambari-env.sh during ambari-server start
  33. PYTHON_WRAPER_DIR="${ROOT}/usr/bin/"
  34. PYTHON_WRAPER_TARGET="${PYTHON_WRAPER_DIR}/ambari-python-wrap"
  35. AMBARI_SERVER_EXECUTABLE_LINK="${ROOT}/usr/sbin/ambari-server"
  36. AMBARI_SERVER_EXECUTABLE="${ROOT}/etc/init.d/ambari-server"
  37. AMBARI_CONFIGS_DIR="${ROOT}/etc/ambari-server/conf"
  38. AMBARI_CONFIGS_DIR_SAVE="${ROOT}/etc/ambari-server/conf.save"
  39. AMBARI_CONFIGS_DIR_SAVE_BACKUP="${ROOT}/etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save"
  40. AMBARI_LOG4J="${AMBARI_CONFIGS_DIR}/log4j.properties"
  41. clean_pyc_files(){
  42. # cleaning old *.pyc files
  43. find ${RESOURCE_MANAGEMENT_DIR:?} -name *.pyc -exec rm {} \;
  44. find ${COMMON_DIR:?} -name *.pyc -exec rm {} \;
  45. find ${AMBARI_SERVER:?} -name *.pyc -exec rm {} \;
  46. }
  47. do_install(){
  48. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  49. ln -s "$AMBARI_SERVER_EXECUTABLE" "$AMBARI_SERVER_EXECUTABLE_LINK"
  50. # setting ambari_commons shared resource
  51. rm -rf "$OLD_COMMON_DIR"
  52. if [ ! -d "$COMMON_DIR" ]; then
  53. ln -s "$COMMON_DIR_SERVER" "$COMMON_DIR"
  54. fi
  55. # setting resource_management shared resource
  56. if [ ! -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  57. ln -s "$RESOURCE_MANAGEMENT_DIR_SERVER" "$RESOURCE_MANAGEMENT_DIR"
  58. fi
  59. # setting jinja2 shared resource
  60. if [ ! -d "$JINJA_DIR" ]; then
  61. ln -s "$JINJA_SERVER_DIR" "$JINJA_DIR"
  62. fi
  63. # setting simplejson shared resource
  64. if [ ! -d "$SIMPLEJSON_DIR" ]; then
  65. ln -s "$SIMPLEJSON_SERVER_DIR" "$SIMPLEJSON_DIR"
  66. fi
  67. #TODO we need this when upgrading from pre 2.4 versions to 2.4, remove this when upgrade from pre 2.4 versions will be
  68. #TODO unsupported
  69. clean_pyc_files
  70. # remove old python wrapper
  71. rm -f "$PYTHON_WRAPER_TARGET"
  72. AMBARI_PYTHON=""
  73. python_binaries=( "/usr/bin/python" "/usr/bin/python2" "/usr/bin/python2.7", "/usr/bin/python2.6" )
  74. for python_binary in "${python_binaries[@]}"
  75. do
  76. $python_binary -c "import sys ; ver = sys.version_info ; sys.exit(not (ver >= (2,6) and ver<(3,0)))" 1>/dev/null 2>/dev/null
  77. if [ $? -eq 0 ] ; then
  78. AMBARI_PYTHON="$python_binary"
  79. break;
  80. fi
  81. done
  82. if [ -z "$AMBARI_PYTHON" ] ; then
  83. >&2 echo "Cannot detect python for ambari to use. Please manually set $PYTHON_WRAPER link to point to correct python binary"
  84. else
  85. mkdir -p "$PYTHON_WRAPER_DIR"
  86. ln -s "$AMBARI_PYTHON" "$PYTHON_WRAPER_TARGET"
  87. fi
  88. sed -i "s|ambari.root.dir\s*=\s*/|ambari.root.dir=${ROOT}|g" "$AMBARI_LOG4J"
  89. sed -i "s|root_dir\s*=\s*/|root_dir = ${ROOT}|g" "$CA_CONFIG"
  90. AUTOSTART_SERVER_CMD=""
  91. which chkconfig > /dev/null 2>&1
  92. if [ "$?" -eq 0 ] ; then
  93. AUTOSTART_SERVER_CMD="chkconfig --add ambari-server"
  94. fi
  95. which update-rc.d > /dev/null 2>&1
  96. if [ "$?" -eq 0 ] ; then
  97. AUTOSTART_SERVER_CMD="update-rc.d ambari-server defaults"
  98. fi
  99. # if installed to customized root folder, skip ambari-server service actions,
  100. # as no file in /etc/init.d/ambari-server is present
  101. if [ ! "${ROOT}/" -ef "/" ] ; then
  102. echo "Not adding ambari-server service to startup, as installed to customized root."
  103. echo "If you need this functionality run the commands below, which create ambari-server service and configure it to run at startup: "
  104. echo "sudo ln -s ${AMBARI_SERVER_EXECUTABLE} /etc/init.d/ambari-server"
  105. echo "sudo $AUTOSTART_SERVER_CMD"
  106. else
  107. $AUTOSTART_SERVER_CMD
  108. fi
  109. if [ -f "$AMBARI_ENV_RPMSAVE" ] ; then
  110. PYTHON_PATH_LINE='export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/site-packages'
  111. grep "^$PYTHON_PATH_LINE\$" "$AMBARI_ENV_RPMSAVE" > /dev/null
  112. if [ $? -ne 0 ] ; then
  113. echo -e "\n$PYTHON_PATH_LINE" >> $AMBARI_ENV_RPMSAVE
  114. fi
  115. fi
  116. }
  117. do_remove(){
  118. $AMBARI_SERVER_EXECUTABLE stop > /dev/null 2>&1
  119. clean_pyc_files
  120. if [ -d "$AMBARI_CONFIGS_DIR_SAVE" ]; then
  121. mv "$AMBARI_CONFIGS_DIR_SAVE" "$AMBARI_CONFIGS_DIR_SAVE_BACKUP"
  122. fi
  123. # Remove link created during install
  124. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  125. mv "$AMBARI_CONFIGS_DIR" "$AMBARI_CONFIGS_DIR_SAVE"
  126. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  127. rm -f "$PYTHON_WRAPER_TARGET"
  128. fi
  129. if [ -d "$COMMON_DIR" ]; then
  130. rm -f $COMMON_DIR
  131. fi
  132. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  133. rm -f $RESOURCE_MANAGEMENT_DIR
  134. fi
  135. if [ -d "$JINJA_DIR" ]; then
  136. rm -f $JINJA_DIR
  137. fi
  138. if [ -d "$SIMPLEJSON_DIR" ]; then
  139. rm -f $SIMPLEJSON_DIR
  140. fi
  141. if [ -d "$OLD_COMMON_DIR" ]; then
  142. rm -rf $OLD_COMMON_DIR
  143. fi
  144. if [ -d "$AMBARI_SERVER" ]; then
  145. rm -rf "$AMBARI_SERVER"
  146. fi
  147. # if server package exists, restore their settings
  148. if [ -f "$INSTALL_HELPER_AGENT" ]; then # call agent shared files installer
  149. $INSTALL_HELPER_AGENT install
  150. fi
  151. which chkconfig > /dev/null 2>&1
  152. if [ "$?" -eq 0 ] ; then
  153. chkconfig --list | grep ambari-server && chkconfig --del ambari-server
  154. fi
  155. which update-rc.d > /dev/null 2>&1
  156. if [ "$?" -eq 0 ] ; then
  157. update-rc.d -f ambari-server remove
  158. fi
  159. }
  160. do_upgrade(){
  161. # this function only gets called for rpm. Deb packages always call do_install directly.
  162. do_install
  163. }
  164. case "$1" in
  165. install)
  166. do_install
  167. ;;
  168. remove)
  169. do_remove
  170. ;;
  171. upgrade)
  172. do_upgrade
  173. ;;
  174. esac