install-helper.sh 6.2 KB

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