install-helper.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. ##################################################################
  16. # AGENT 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. INSTALL_HELPER_SERVER="/var/lib/ambari-server/install-helper.sh"
  24. COMMON_DIR_AGENT="/usr/lib/ambari-agent/lib/ambari_commons"
  25. RESOURCE_MANAGEMENT_DIR_AGENT="/usr/lib/ambari-agent/lib/resource_management"
  26. JINJA_AGENT_DIR="/usr/lib/ambari-agent/lib/ambari_jinja2"
  27. SIMPLEJSON_AGENT_DIR="/usr/lib/ambari-agent/lib/ambari_simplejson"
  28. PYTHON_WRAPER_TARGET="/usr/bin/ambari-python-wrap"
  29. do_install(){
  30. if [ -d "/etc/ambari-agent/conf.save" ]; then
  31. cp -f /etc/ambari-agent/conf.save/* /etc/ambari-agent/conf
  32. mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
  33. fi
  34. # setting ambari_commons shared resource
  35. rm -rf "$OLD_COMMON_DIR"
  36. if [ ! -d "$COMMON_DIR" ]; then
  37. ln -s "$COMMON_DIR_AGENT" "$COMMON_DIR"
  38. fi
  39. # setting resource_management shared resource
  40. if [ ! -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  41. ln -s "$RESOURCE_MANAGEMENT_DIR_AGENT" "$RESOURCE_MANAGEMENT_DIR"
  42. fi
  43. # setting jinja2 shared resource
  44. if [ ! -d "$JINJA_DIR" ]; then
  45. ln -s "$JINJA_AGENT_DIR" "$JINJA_DIR"
  46. fi
  47. # setting simplejson shared resource
  48. if [ ! -d "$SIMPLEJSON_DIR" ]; then
  49. ln -s "$SIMPLEJSON_AGENT_DIR" "$SIMPLEJSON_DIR"
  50. fi
  51. # on nano Ubuntu, when umask=027 those folders are created without 'x' bit for 'others'.
  52. # which causes failures when hadoop users try to access tmp_dir
  53. chmod a+x /var/lib/ambari-agent
  54. chmod 777 /var/lib/ambari-agent/tmp
  55. chmod 700 /var/lib/ambari-agent/data
  56. which chkconfig > /dev/null 2>&1
  57. if [ "$?" -eq 0 ] ; then
  58. chkconfig --add ambari-agent
  59. fi
  60. which update-rc.d > /dev/null 2>&1
  61. if [ "$?" -eq 0 ] ; then
  62. update-rc.d ambari-agent defaults
  63. fi
  64. BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
  65. ORIG=/etc/ambari-agent/conf/ambari-agent.ini
  66. if [ -f $BAK ]; then
  67. if [ -f "/var/lib/ambari-agent/upgrade_agent_configs.py" ]; then
  68. /var/lib/ambari-agent/upgrade_agent_configs.py
  69. fi
  70. mv $BAK ${BAK}_$(date '+%d_%m_%y_%H_%M').save
  71. fi
  72. # remove old python wrapper
  73. rm -f "$PYTHON_WRAPER_TARGET"
  74. AMBARI_PYTHON=""
  75. python_binaries=( "/usr/bin/python" "/usr/bin/python2" "/usr/bin/python2.7", "/usr/bin/python2.6" )
  76. for python_binary in "${python_binaries[@]}"
  77. do
  78. $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
  79. if [ $? -eq 0 ] ; then
  80. AMBARI_PYTHON="$python_binary"
  81. break;
  82. fi
  83. done
  84. if [ -z "$AMBARI_PYTHON" ] ; then
  85. >&2 echo "Cannot detect python for ambari to use. Please manually set $PYTHON_WRAPER link to point to correct python binary"
  86. else
  87. ln -s "$AMBARI_PYTHON" "$PYTHON_WRAPER_TARGET"
  88. fi
  89. }
  90. do_remove(){
  91. /usr/sbin/ambari-agent stop > /dev/null 2>&1
  92. if [ -d "/etc/ambari-agent/conf.save" ]; then
  93. mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
  94. fi
  95. mv /etc/ambari-agent/conf /etc/ambari-agent/conf.save
  96. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  97. rm -f "$PYTHON_WRAPER_TARGET"
  98. fi
  99. if [ -d "$COMMON_DIR" ]; then
  100. rm -f $COMMON_DIR
  101. fi
  102. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  103. rm -rf $RESOURCE_MANAGEMENT_DIR
  104. fi
  105. if [ -d "$JINJA_DIR" ]; then
  106. rm -rf $JINJA_DIR
  107. fi
  108. if [ -d "$SIMPLEJSON_DIR" ]; then
  109. rm -f $SIMPLEJSON_DIR
  110. fi
  111. if [ -d "$OLD_COMMON_DIR" ]; then
  112. rm -f $OLD_COMMON_DIR
  113. fi
  114. # if server package exists, restore their settings
  115. if [ -f "$INSTALL_HELPER_SERVER" ]; then # call server shared files installer
  116. $INSTALL_HELPER_SERVER install
  117. fi
  118. which chkconfig > /dev/null 2>&1
  119. if [ "$?" -eq 0 ] ; then
  120. chkconfig --list | grep ambari-server && chkconfig --del ambari-agent
  121. fi
  122. which update-rc.d > /dev/null 2>&1
  123. if [ "$?" -eq 0 ] ; then
  124. update-rc.d -f ambari-agent remove
  125. fi
  126. }
  127. do_upgrade(){
  128. do_install
  129. }
  130. case "$1" in
  131. install)
  132. do_install
  133. ;;
  134. remove)
  135. do_remove
  136. ;;
  137. upgrade)
  138. do_upgrade
  139. ;;
  140. esac