install-helper.sh 5.6 KB

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