install-helper.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. COMMON_DIR="/usr/lib/python2.6/site-packages/ambari_commons"
  19. RESOURCE_MANAGEMENT_DIR="/usr/lib/python2.6/site-packages/resource_management"
  20. JINJA_DIR="/usr/lib/python2.6/site-packages/ambari_jinja2"
  21. SIMPLEJSON_DIR="/usr/lib/python2.6/site-packages/ambari_simplejson"
  22. OLD_COMMON_DIR="/usr/lib/python2.6/site-packages/common_functions"
  23. AMBARI_SERVER="/usr/lib/python2.6/site-packages/ambari_server"
  24. INSTALL_HELPER_AGENT="/var/lib/ambari-agent/install-helper.sh"
  25. COMMON_DIR_SERVER="/usr/lib/ambari-server/lib/ambari_commons"
  26. RESOURCE_MANAGEMENT_DIR_SERVER="/usr/lib/ambari-server/lib/resource_management"
  27. JINJA_SERVER_DIR="/usr/lib/ambari-server/lib/ambari_jinja2"
  28. SIMPLEJSON_SERVER_DIR="/usr/lib/ambari-server/lib/ambari_simplejson"
  29. PYTHON_WRAPER_TARGET="/usr/bin/ambari-python-wrap"
  30. PYTHON_WRAPER_SOURCE="/var/lib/ambari-server/ambari-python-wrap"
  31. do_install(){
  32. rm -f /usr/sbin/ambari-server
  33. ln -s /etc/init.d/ambari-server /usr/sbin/ambari-server
  34. # setting ambari_commons shared resource
  35. rm -rf "$OLD_COMMON_DIR"
  36. if [ ! -d "$COMMON_DIR" ]; then
  37. ln -s "$COMMON_DIR_SERVER" "$COMMON_DIR"
  38. fi
  39. # setting resource_management shared resource
  40. if [ ! -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  41. ln -s "$RESOURCE_MANAGEMENT_DIR_SERVER" "$RESOURCE_MANAGEMENT_DIR"
  42. fi
  43. # setting jinja2 shared resource
  44. if [ ! -d "$JINJA_DIR" ]; then
  45. ln -s "$JINJA_SERVER_DIR" "$JINJA_DIR"
  46. fi
  47. # setting simplejson shared resource
  48. if [ ! -d "$SIMPLEJSON_DIR" ]; then
  49. ln -s "$SIMPLEJSON_SERVER_DIR" "$SIMPLEJSON_DIR"
  50. fi
  51. # setting python-wrapper script
  52. if [ ! -f "$PYTHON_WRAPER_TARGET" ]; then
  53. ln -s "$PYTHON_WRAPER_SOURCE" "$PYTHON_WRAPER_TARGET"
  54. fi
  55. which chkconfig > /dev/null 2>&1
  56. if [ "$?" -eq 0 ] ; then
  57. chkconfig --add ambari-server
  58. fi
  59. which update-rc.d > /dev/null 2>&1
  60. if [ "$?" -eq 0 ] ; then
  61. update-rc.d ambari-server defaults
  62. fi
  63. }
  64. do_remove(){
  65. /usr/sbin/ambari-server stop > /dev/null 2>&1
  66. if [ -d "/etc/ambari-server/conf.save" ]; then
  67. mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
  68. fi
  69. # Remove link created during install
  70. rm -f /usr/sbin/ambari-server
  71. mv /etc/ambari-server/conf /etc/ambari-server/conf.save
  72. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  73. rm -f "$PYTHON_WRAPER_TARGET"
  74. fi
  75. if [ -d "$COMMON_DIR" ]; then
  76. rm -f $COMMON_DIR
  77. fi
  78. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  79. rm -f $RESOURCE_MANAGEMENT_DIR
  80. fi
  81. if [ -d "$JINJA_DIR" ]; then
  82. rm -f $JINJA_DIR
  83. fi
  84. if [ -d "$SIMPLEJSON_DIR" ]; then
  85. rm -f $SIMPLEJSON_DIR
  86. fi
  87. if [ -d "$OLD_COMMON_DIR" ]; then
  88. rm -rf $OLD_COMMON_DIR
  89. fi
  90. if [ -d "$AMBARI_SERVER" ]; then
  91. rm -rf "$AMBARI_SERVER"
  92. fi
  93. # if server package exists, restore their settings
  94. if [ -f "$INSTALL_HELPER_AGENT" ]; then # call agent shared files installer
  95. $INSTALL_HELPER_AGENT install
  96. fi
  97. which chkconfig > /dev/null 2>&1
  98. if [ "$?" -eq 0 ] ; then
  99. chkconfig --list | grep ambari-server && chkconfig --del ambari-server
  100. fi
  101. which update-rc.d > /dev/null 2>&1
  102. if [ "$?" -eq 0 ] ; then
  103. update-rc.d -f ambari-server remove
  104. fi
  105. }
  106. do_upgrade(){
  107. # this function only gets called for rpm. Deb packages always call do_install directly.
  108. do_install
  109. }
  110. case "$1" in
  111. install)
  112. do_install
  113. ;;
  114. remove)
  115. do_remove
  116. ;;
  117. upgrade)
  118. do_upgrade
  119. ;;
  120. esac