install-helper.sh 5.2 KB

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