install-helper.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. INSTALL_HELPER_SERVER="/var/lib/ambari-server/install-helper.sh"
  19. COMMON_DIR="/usr/lib/ambari-agent/lib/ambari_commons"
  20. RESOURCE_MANAGEMENT_DIR="/usr/lib/ambari-agent/lib/resource_management"
  21. JINJA_DIR="/usr/lib/ambari-agent/lib/ambari_jinja2"
  22. SIMPLEJSON_DIR="/usr/lib/ambari-agent/lib/ambari_simplejson"
  23. OLD_OLD_COMMON_DIR="/usr/lib/ambari-agent/lib/common_functions"
  24. AMBARI_AGENT="/usr/lib/ambari-agent/lib/ambari_agent"
  25. PYTHON_WRAPER_TARGET="/usr/bin/ambari-python-wrap"
  26. AMBARI_AGENT_VAR="/var/lib/ambari-agent"
  27. AMBARI_AGENT_BINARY="/etc/init.d/ambari-agent"
  28. AMBARI_AGENT_BINARY_SYMLINK="/usr/sbin/ambari-agent"
  29. OLD_COMMON_DIR="/usr/lib/python2.6/site-packages/ambari_commons"
  30. OLD_RESOURCE_MANAGEMENT_DIR="/usr/lib/python2.6/site-packages/resource_management"
  31. OLD_JINJA_DIR="/usr/lib/python2.6/site-packages/ambari_jinja2"
  32. OLD_SIMPLEJSON_DIR="/usr/lib/python2.6/site-packages/ambari_simplejson"
  33. OLD_AMBARI_AGENT_DIR="/usr/lib/python2.6/site-packages/ambari_agent"
  34. clean_pyc_files(){
  35. # cleaning old *.pyc files
  36. find ${RESOURCE_MANAGEMENT_DIR:?} -name *.pyc -exec rm {} \;
  37. find ${COMMON_DIR:?} -name *.pyc -exec rm {} \;
  38. find ${AMBARI_AGENT:?} -name *.pyc -exec rm {} \;
  39. find ${AMBARI_AGENT_VAR:?} -name *.pyc -exec rm {} \;
  40. }
  41. do_install(){
  42. if [ -d "/etc/ambari-agent/conf.save" ]; then
  43. cp -f /etc/ambari-agent/conf.save/* /etc/ambari-agent/conf
  44. mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
  45. fi
  46. # these symlinks (or directories) where created in ambari releases prior to ambari-2.6.2. Do clean up.
  47. rm -rf "$OLD_COMMON_DIR" "$OLD_RESOURCE_MANAGEMENT_DIR" "$OLD_JINJA_DIR" "$OLD_SIMPLEJSON_DIR" "$OLD_OLD_COMMON_DIR" "$OLD_AMBARI_AGENT_DIR"
  48. # setting up /usr/sbin/ambari-agent symlink
  49. rm -f "$AMBARI_AGENT_BINARY_SYMLINK"
  50. ln -s "$AMBARI_AGENT_BINARY" "$AMBARI_AGENT_BINARY_SYMLINK"
  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 $AMBARI_AGENT_VAR
  54. chmod 1777 $AMBARI_AGENT_VAR/tmp
  55. chmod 700 $AMBARI_AGENT_VAR/keys
  56. chmod 700 $AMBARI_AGENT_VAR/data
  57. #TODO we need this when upgrading from pre 2.4 versions to 2.4, remove this when upgrade from pre 2.4 versions will be
  58. #TODO unsupported
  59. clean_pyc_files
  60. which chkconfig > /dev/null 2>&1
  61. if [ "$?" -eq 0 ] ; then
  62. chkconfig --add ambari-agent
  63. fi
  64. which update-rc.d > /dev/null 2>&1
  65. if [ "$?" -eq 0 ] ; then
  66. update-rc.d ambari-agent defaults
  67. fi
  68. # remove old python wrapper
  69. rm -f "$PYTHON_WRAPER_TARGET"
  70. AMBARI_PYTHON=""
  71. python_binaries=( "/usr/bin/python" "/usr/bin/python2" "/usr/bin/python2.7" "/usr/bin/python2.6" )
  72. for python_binary in "${python_binaries[@]}"
  73. do
  74. $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
  75. if [ $? -eq 0 ] ; then
  76. AMBARI_PYTHON="$python_binary"
  77. break;
  78. fi
  79. done
  80. BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
  81. ORIG=/etc/ambari-agent/conf/ambari-agent.ini
  82. UPGRADE_AGENT_CONFIGS_SCRIPT=/var/lib/ambari-agent/upgrade_agent_configs.py
  83. if [ -z "$AMBARI_PYTHON" ] ; then
  84. >&2 echo "Cannot detect python for Ambari to use. Please manually set $PYTHON_WRAPER_TARGET link to point to correct python binary"
  85. >&2 echo "Cannot upgrade agent configs because python for Ambari is not configured. The old config file is saved as $BAK . Execution of $UPGRADE_AGENT_CONFIGS_SCRIPT was skipped."
  86. else
  87. ln -s "$AMBARI_PYTHON" "$PYTHON_WRAPER_TARGET"
  88. if [ -f $BAK ]; then
  89. if [ -f "$UPGRADE_AGENT_CONFIGS_SCRIPT" ]; then
  90. $UPGRADE_AGENT_CONFIGS_SCRIPT
  91. fi
  92. mv $BAK ${BAK}_$(date '+%d_%m_%y_%H_%M').save
  93. fi
  94. fi
  95. if [ -f "$AMBARI_ENV_RPMSAVE" ] ; then
  96. PYTHON_PATH_LINE='export PYTHONPATH=/usr/lib/ambari-agent/lib:$PYTHONPATH'
  97. grep "^$PYTHON_PATH_LINE\$" "$AMBARI_ENV_RPMSAVE" > /dev/null
  98. if [ $? -ne 0 ] ; then
  99. echo -e "\n$PYTHON_PATH_LINE" >> $AMBARI_ENV_RPMSAVE
  100. fi
  101. fi
  102. }
  103. do_remove(){
  104. /usr/sbin/ambari-agent stop > /dev/null 2>&1
  105. clean_pyc_files
  106. rm -f "$AMBARI_AGENT_BINARY_SYMLINK"
  107. if [ -d "/etc/ambari-agent/conf.save" ]; then
  108. mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
  109. fi
  110. mv /etc/ambari-agent/conf /etc/ambari-agent/conf.save
  111. if [ -f "$PYTHON_WRAPER_TARGET" ]; then
  112. rm -f "$PYTHON_WRAPER_TARGET"
  113. fi
  114. if [ -d "$COMMON_DIR" ]; then
  115. rm -rf $COMMON_DIR
  116. fi
  117. if [ -d "$RESOURCE_MANAGEMENT_DIR" ]; then
  118. rm -rf $RESOURCE_MANAGEMENT_DIR
  119. fi
  120. if [ -d "$JINJA_DIR" ]; then
  121. rm -rf $JINJA_DIR
  122. fi
  123. if [ -d "$SIMPLEJSON_DIR" ]; then
  124. rm -rf $SIMPLEJSON_DIR
  125. fi
  126. # if server package exists, restore their settings
  127. if [ -f "$INSTALL_HELPER_SERVER" ]; then # call server shared files installer
  128. $INSTALL_HELPER_SERVER install
  129. fi
  130. which chkconfig > /dev/null 2>&1
  131. if [ "$?" -eq 0 ] ; then
  132. chkconfig --list | grep ambari-server && chkconfig --del ambari-agent
  133. fi
  134. which update-rc.d > /dev/null 2>&1
  135. if [ "$?" -eq 0 ] ; then
  136. update-rc.d -f ambari-agent remove
  137. fi
  138. }
  139. do_upgrade(){
  140. do_install
  141. }
  142. case "$1" in
  143. install)
  144. do_install
  145. ;;
  146. remove)
  147. do_remove
  148. ;;
  149. upgrade)
  150. do_upgrade
  151. ;;
  152. esac