install-helper.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_DIR_PATH="${RPM_INSTALL_PREFIX}"
  19. ROOT=`echo "${RPM_INSTALL_PREFIX}" | sed 's|/$||g'` # Customized folder, which ambari-server files are installed into ('/' or '' are default).
  20. COMMON_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_commons"
  21. RESOURCE_MANAGEMENT_DIR="${ROOT}/usr/lib/python2.6/site-packages/resource_management"
  22. JINJA_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_jinja2"
  23. SIMPLEJSON_DIR="${ROOT}/usr/lib/python2.6/site-packages/ambari_simplejson"
  24. OLD_COMMON_DIR="${ROOT}/usr/lib/python2.6/site-packages/common_functions"
  25. AMBARI_SERVER="${ROOT}/usr/lib/python2.6/site-packages/ambari_server"
  26. INSTALL_HELPER_AGENT="/var/lib/ambari-agent/install-helper.sh"
  27. CA_CONFIG="${ROOT}/var/lib/ambari-server/keys/ca.config"
  28. COMMON_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/ambari_commons"
  29. RESOURCE_MANAGEMENT_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/resource_management"
  30. JINJA_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_jinja2"
  31. SIMPLEJSON_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_simplejson"
  32. AMBARI_PROPERTIES="${ROOT}/etc/ambari-server/conf/ambari.properties"
  33. AMBARI_ENV_RPMSAVE="${ROOT}/var/lib/ambari-server/ambari-env.sh.rpmsave" # this turns into ambari-env.sh during ambari-server start
  34. PYTHON_WRAPER_DIR="${ROOT}/usr/bin/"
  35. PYTHON_WRAPER_TARGET="${PYTHON_WRAPER_DIR}/ambari-python-wrap"
  36. AMBARI_SERVER_EXECUTABLE_LINK="${ROOT}/usr/sbin/ambari-server"
  37. AMBARI_SERVER_EXECUTABLE="${ROOT}/etc/init.d/ambari-server"
  38. AMBARI_CONFIGS_DIR="${ROOT}/etc/ambari-server/conf"
  39. AMBARI_CONFIGS_DIR_SAVE="${ROOT}/etc/ambari-server/conf.save"
  40. AMBARI_CONFIGS_DIR_SAVE_BACKUP="${ROOT}/etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save"
  41. AMBARI_LOG4J="${AMBARI_CONFIGS_DIR}/log4j.properties"
  42. clean_pyc_files(){
  43. # cleaning old *.pyc files
  44. find ${RESOURCE_MANAGEMENT_DIR:?} -name *.pyc -exec rm {} \;
  45. find ${COMMON_DIR:?} -name *.pyc -exec rm {} \;
  46. find ${AMBARI_SERVER:?} -name *.pyc -exec rm {} \;
  47. }
  48. do_install(){
  49. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  50. ln -s "$AMBARI_SERVER_EXECUTABLE" "$AMBARI_SERVER_EXECUTABLE_LINK"
  51. # setting ambari_commons shared resource
  52. rm -rf "$OLD_COMMON_DIR"
  53. if [ ! -d "$COMMON_DIR" ]; then
  54. ln -s "$COMMON_DIR_SERVER" "$COMMON_DIR"
  55. fi
  56. # setting resource_management shared resource
  57. if [ ! -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  58. ln -s "$RESOURCE_MANAGEMENT_DIR_SERVER" "$RESOURCE_MANAGEMENT_DIR"
  59. fi
  60. # setting jinja2 shared resource
  61. if [ ! -d "$JINJA_DIR" ]; then
  62. ln -s "$JINJA_SERVER_DIR" "$JINJA_DIR"
  63. fi
  64. # setting simplejson shared resource
  65. if [ ! -d "$SIMPLEJSON_DIR" ]; then
  66. ln -s "$SIMPLEJSON_SERVER_DIR" "$SIMPLEJSON_DIR"
  67. fi
  68. #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
  69. #TODO unsupported
  70. clean_pyc_files
  71. # remove old python wrapper
  72. rm -f "$PYTHON_WRAPER_TARGET"
  73. AMBARI_PYTHON=""
  74. python_binaries=( "/usr/bin/python" "/usr/bin/python2" "/usr/bin/python2.7", "/usr/bin/python2.6" )
  75. for python_binary in "${python_binaries[@]}"
  76. do
  77. $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
  78. if [ $? -eq 0 ] ; then
  79. AMBARI_PYTHON="$python_binary"
  80. break;
  81. fi
  82. done
  83. if [ -z "$AMBARI_PYTHON" ] ; then
  84. >&2 echo "Cannot detect python for ambari to use. Please manually set $PYTHON_WRAPER link to point to correct python binary"
  85. else
  86. mkdir -p "$PYTHON_WRAPER_DIR"
  87. ln -s "$AMBARI_PYTHON" "$PYTHON_WRAPER_TARGET"
  88. fi
  89. sed -i "s|ambari.root.dir\s*=\s*/|ambari.root.dir=${ROOT_DIR_PATH}|g" "$AMBARI_LOG4J"
  90. sed -i "s|root_dir\s*=\s*/|root_dir = ${ROOT_DIR_PATH}|g" "$CA_CONFIG"
  91. sed -i "s|^ROOT=\"/\"$|ROOT=\"${ROOT_DIR_PATH}\"|g" "$AMBARI_SERVER_EXECUTABLE"
  92. AUTOSTART_SERVER_CMD=""
  93. which chkconfig > /dev/null 2>&1
  94. if [ "$?" -eq 0 ] ; then
  95. AUTOSTART_SERVER_CMD="chkconfig --add ambari-server"
  96. fi
  97. which update-rc.d > /dev/null 2>&1
  98. if [ "$?" -eq 0 ] ; then
  99. AUTOSTART_SERVER_CMD="update-rc.d ambari-server defaults"
  100. fi
  101. # if installed to customized root folder, skip ambari-server service actions,
  102. # as no file in /etc/init.d/ambari-server is present
  103. if [ ! "${ROOT}/" -ef "/" ] ; then
  104. echo "Not adding ambari-server service to startup, as installed to customized root."
  105. echo "If you need this functionality run the commands below, which create ambari-server service and configure it to run at startup: "
  106. echo "sudo ln -s ${AMBARI_SERVER_EXECUTABLE} /etc/init.d/ambari-server"
  107. echo "sudo $AUTOSTART_SERVER_CMD"
  108. else
  109. $AUTOSTART_SERVER_CMD
  110. fi
  111. if [ -f "$AMBARI_ENV_RPMSAVE" ] ; then
  112. PYTHON_PATH_LINE='export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/site-packages'
  113. grep "^$PYTHON_PATH_LINE\$" "$AMBARI_ENV_RPMSAVE" > /dev/null
  114. if [ $? -ne 0 ] ; then
  115. echo -e "\n$PYTHON_PATH_LINE" >> $AMBARI_ENV_RPMSAVE
  116. fi
  117. fi
  118. }
  119. do_remove(){
  120. $AMBARI_SERVER_EXECUTABLE stop > /dev/null 2>&1
  121. clean_pyc_files
  122. if [ -d "$AMBARI_CONFIGS_DIR_SAVE" ]; then
  123. mv "$AMBARI_CONFIGS_DIR_SAVE" "$AMBARI_CONFIGS_DIR_SAVE_BACKUP"
  124. fi
  125. # Remove link created during install
  126. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  127. mv "$AMBARI_CONFIGS_DIR" "$AMBARI_CONFIGS_DIR_SAVE"
  128. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  129. rm -f "$PYTHON_WRAPER_TARGET"
  130. fi
  131. if [ -d "$COMMON_DIR" ]; then
  132. rm -f $COMMON_DIR
  133. fi
  134. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  135. rm -f $RESOURCE_MANAGEMENT_DIR
  136. fi
  137. if [ -d "$JINJA_DIR" ]; then
  138. rm -f $JINJA_DIR
  139. fi
  140. if [ -d "$SIMPLEJSON_DIR" ]; then
  141. rm -f $SIMPLEJSON_DIR
  142. fi
  143. if [ -d "$OLD_COMMON_DIR" ]; then
  144. rm -rf $OLD_COMMON_DIR
  145. fi
  146. if [ -d "$AMBARI_SERVER" ]; then
  147. rm -rf "$AMBARI_SERVER"
  148. fi
  149. # if server package exists, restore their settings
  150. if [ -f "$INSTALL_HELPER_AGENT" ]; then # call agent shared files installer
  151. $INSTALL_HELPER_AGENT install
  152. fi
  153. which chkconfig > /dev/null 2>&1
  154. if [ "$?" -eq 0 ] ; then
  155. chkconfig --list | grep ambari-server && chkconfig --del ambari-server
  156. fi
  157. which update-rc.d > /dev/null 2>&1
  158. if [ "$?" -eq 0 ] ; then
  159. update-rc.d -f ambari-server remove
  160. fi
  161. }
  162. do_upgrade(){
  163. # this function only gets called for rpm. Deb packages always call do_install directly.
  164. do_install
  165. }
  166. case "$1" in
  167. install)
  168. do_install
  169. ;;
  170. remove)
  171. do_remove
  172. ;;
  173. upgrade)
  174. do_upgrade
  175. ;;
  176. esac