install-helper.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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="${AMBARI_ROOT_FOLDER}"
  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="${ROOT}/var/lib/ambari-agent/install-helper.sh"
  26. COMMON_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/ambari_commons"
  27. RESOURCE_MANAGEMENT_DIR_SERVER="${ROOT}/usr/lib/ambari-server/lib/resource_management"
  28. JINJA_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_jinja2"
  29. SIMPLEJSON_SERVER_DIR="${ROOT}/usr/lib/ambari-server/lib/ambari_simplejson"
  30. AMBARI_PROPERTIES="${ROOT}/etc/ambari-server/conf/ambari.properties"
  31. PYTHON_WRAPER_DIR="${ROOT}/usr/bin/"
  32. PYTHON_WRAPER_TARGET="${PYTHON_WRAPER_DIR}/ambari-python-wrap"
  33. AMBARI_SERVER_EXECUTABLE_LINK="${ROOT}/usr/sbin/ambari-server"
  34. AMBARI_SERVER_EXECUTABLE="${ROOT}/etc/init.d/ambari-server"
  35. AMBARI_CONFIGS_DIR="${ROOT}/etc/ambari-server/conf"
  36. AMBARI_CONFIGS_DIR_SAVE="${ROOT}/etc/ambari-server/conf.save"
  37. AMBARI_CONFIGS_DIR_SAVE_BACKUP="${ROOT}/etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save"
  38. do_install(){
  39. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  40. ln -s "$AMBARI_SERVER_EXECUTABLE" "$AMBARI_SERVER_EXECUTABLE_LINK"
  41. # setting ambari_commons shared resource
  42. rm -rf "$OLD_COMMON_DIR"
  43. if [ ! -d "$COMMON_DIR" ]; then
  44. ln -s "$COMMON_DIR_SERVER" "$COMMON_DIR"
  45. fi
  46. # setting resource_management shared resource
  47. if [ ! -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  48. ln -s "$RESOURCE_MANAGEMENT_DIR_SERVER" "$RESOURCE_MANAGEMENT_DIR"
  49. fi
  50. # setting jinja2 shared resource
  51. if [ ! -d "$JINJA_DIR" ]; then
  52. ln -s "$JINJA_SERVER_DIR" "$JINJA_DIR"
  53. fi
  54. # setting simplejson shared resource
  55. if [ ! -d "$SIMPLEJSON_DIR" ]; then
  56. ln -s "$SIMPLEJSON_SERVER_DIR" "$SIMPLEJSON_DIR"
  57. fi
  58. # remove old python wrapper
  59. rm -f "$PYTHON_WRAPER_TARGET"
  60. AMBARI_PYTHON=""
  61. python_binaries=( "/usr/bin/python" "/usr/bin/python2" "/usr/bin/python2.7", "/usr/bin/python2.6" )
  62. for python_binary in "${python_binaries[@]}"
  63. do
  64. $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
  65. if [ $? -eq 0 ] ; then
  66. AMBARI_PYTHON="$python_binary"
  67. break;
  68. fi
  69. done
  70. if [ -z "$AMBARI_PYTHON" ] ; then
  71. >&2 echo "Cannot detect python for ambari to use. Please manually set $PYTHON_WRAPER link to point to correct python binary"
  72. else
  73. mkdir -p "$PYTHON_WRAPER_DIR"
  74. ln -s "$AMBARI_PYTHON" "$PYTHON_WRAPER_TARGET"
  75. fi
  76. which chkconfig > /dev/null 2>&1
  77. if [ "$?" -eq 0 ] ; then
  78. chkconfig --add ambari-server
  79. fi
  80. which update-rc.d > /dev/null 2>&1
  81. if [ "$?" -eq 0 ] ; then
  82. update-rc.d ambari-server defaults
  83. fi
  84. }
  85. do_remove(){
  86. $AMBARI_SERVER_EXECUTABLE stop > /dev/null 2>&1
  87. if [ -d "$AMBARI_CONFIGS_DIR_SAVE" ]; then
  88. mv "$AMBARI_CONFIGS_DIR_SAVE" "$AMBARI_CONFIGS_DIR_SAVE_BACKUP"
  89. fi
  90. # Remove link created during install
  91. rm -f "$AMBARI_SERVER_EXECUTABLE_LINK"
  92. mv "$AMBARI_CONFIGS_DIR" "$AMBARI_CONFIGS_DIR_SAVE"
  93. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  94. rm -f "$PYTHON_WRAPER_TARGET"
  95. fi
  96. if [ -d "$COMMON_DIR" ]; then
  97. rm -f $COMMON_DIR
  98. fi
  99. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  100. rm -f $RESOURCE_MANAGEMENT_DIR
  101. fi
  102. if [ -d "$JINJA_DIR" ]; then
  103. rm -f $JINJA_DIR
  104. fi
  105. if [ -d "$SIMPLEJSON_DIR" ]; then
  106. rm -f $SIMPLEJSON_DIR
  107. fi
  108. if [ -d "$OLD_COMMON_DIR" ]; then
  109. rm -rf $OLD_COMMON_DIR
  110. fi
  111. if [ -d "$AMBARI_SERVER" ]; then
  112. rm -rf "$AMBARI_SERVER"
  113. fi
  114. # if server package exists, restore their settings
  115. if [ -f "$INSTALL_HELPER_AGENT" ]; then # call agent shared files installer
  116. $INSTALL_HELPER_AGENT install
  117. fi
  118. which chkconfig > /dev/null 2>&1
  119. if [ "$?" -eq 0 ] ; then
  120. chkconfig --list | grep ambari-server && chkconfig --del ambari-server
  121. fi
  122. which update-rc.d > /dev/null 2>&1
  123. if [ "$?" -eq 0 ] ; then
  124. update-rc.d -f ambari-server remove
  125. fi
  126. }
  127. do_upgrade(){
  128. # this function only gets called for rpm. Deb packages always call do_install directly.
  129. do_install
  130. }
  131. case "$1" in
  132. install)
  133. do_install
  134. ;;
  135. remove)
  136. do_remove
  137. ;;
  138. upgrade)
  139. do_upgrade
  140. ;;
  141. esac