Forráskód Böngészése

AMBARI-14877. [Ambari tarballs] Refactor postinstall and postremove scripts to use install-helper.sh exclusively (aonishuk)

Andrew Onishuk 9 éve
szülő
commit
f6a75a609c

+ 39 - 1
ambari-agent/conf/unix/install-helper.sh

@@ -33,6 +33,11 @@ PYTHON_WRAPER_TARGET="/usr/bin/ambari-python-wrap"
 PYTHON_WRAPER_SOURCE="/var/lib/ambari-agent/ambari-python-wrap"
 
 do_install(){
+  if [ -d "/etc/ambari-agent/conf.save" ]; then
+    cp -f /etc/ambari-agent/conf.save/* /etc/ambari-agent/conf
+    mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
+  fi
+    
   # setting ambari_commons shared resource
   rm -rf "$OLD_COMMON_DIR"
   if [ ! -d "$COMMON_DIR" ]; then
@@ -61,10 +66,34 @@ do_install(){
   
   chmod 777 /var/lib/ambari-agent/tmp
   chmod 700 /var/lib/ambari-agent/data
+
+  which chkconfig > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    chkconfig --add ambari-agent
+  fi
+  which update-rc.d > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    update-rc.d ambari-agent defaults
+  fi
+
+  BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
+  ORIG=/etc/ambari-agent/conf/ambari-agent.ini
+
+  if [ -f $BAK ]; then
+    if [ -f "/var/lib/ambari-agent/upgrade_agent_configs.py" ]; then
+      /var/lib/ambari-agent/upgrade_agent_configs.py
+    fi
+    mv $BAK ${BAK}_$(date '+%d_%m_%y_%H_%M').save
+  fi
 }
 
 do_remove(){
-
+  /usr/sbin/ambari-agent stop > /dev/null 2>&1
+  if [ -d "/etc/ambari-agent/conf.save" ]; then
+    mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
+  fi
+  mv /etc/ambari-agent/conf /etc/ambari-agent/conf.save
+    
   if [ -f "$PYTHON_WRAPER_TARGET" ]; then
     rm -f "$PYTHON_WRAPER_TARGET"
   fi
@@ -93,6 +122,15 @@ do_remove(){
   if [ -f "$INSTALL_HELPER_SERVER" ]; then  #  call server shared files installer
     $INSTALL_HELPER_SERVER install
   fi
+
+  which chkconfig > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    chkconfig --list | grep ambari-server && chkconfig --del ambari-agent
+  fi
+  which update-rc.d > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    update-rc.d -f ambari-agent remove
+  fi
 }
 
 do_upgrade(){

+ 2 - 10
ambari-agent/src/main/package/deb/control/postinst

@@ -14,20 +14,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License
 
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
+
 if [ "$1" == "configure" ]; then  # Action is install
   if [ -f "/var/lib/ambari-agent/install-helper.sh" ]; then
     /var/lib/ambari-agent/install-helper.sh install
   fi
-  update-rc.d ambari-agent defaults
 fi
 
-BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
-ORIG=/etc/ambari-agent/conf/ambari-agent.ini
-
-if [ -f $BAK ];then
-  if [ -f "/var/lib/ambari-agent/upgrade_agent_configs.py" ]; then
-    /var/lib/ambari-agent/upgrade_agent_configs.py
-  fi
-  mv $BAK ${BAK}_$(date '+%d_%m_%y_%H_%M').save
-fi
 exit 0

+ 0 - 15
ambari-agent/src/main/package/deb/control/posttrm

@@ -1,15 +0,0 @@
-#!/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License

+ 0 - 8
ambari-agent/src/main/package/deb/control/prerm

@@ -19,17 +19,9 @@
 # for details
 
 if [ "$1" == "remove" ]; then # Action is uninstall
-    /usr/sbin/ambari-agent stop > /dev/null 2>&1
-    if [ -d "/etc/ambari-agent/conf.save" ];  then
-        mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
-    fi
-    mv /etc/ambari-agent/conf /etc/ambari-agent/conf.save
-
     if [ -f "/var/lib/ambari-agent/install-helper.sh" ]; then
       /var/lib/ambari-agent/install-helper.sh remove
     fi
-
-    update-rc.d -f ambari-agent remove
 fi
 
 exit 0

+ 1 - 18
ambari-agent/src/main/package/rpm/postinstall.sh

@@ -13,36 +13,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License
 
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
 
 case "$1" in
   1) # Action install
     if [ -f "/var/lib/ambari-agent/install-helper.sh" ]; then
         /var/lib/ambari-agent/install-helper.sh install
     fi
-  chkconfig --add ambari-agent
   ;;
   2) # Action upgrade
-    if [ -d "/etc/ambari-agent/conf.save" ]; then
-        cp -f /etc/ambari-agent/conf.save/* /etc/ambari-agent/conf
-        mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
-    fi
-
     if [ -f "/var/lib/ambari-agent/install-helper.sh" ]; then
         /var/lib/ambari-agent/install-helper.sh upgrade
     fi
   ;;
 esac
 
-
-BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
-ORIG=/etc/ambari-agent/conf/ambari-agent.ini
-
-if [ -f $BAK ]; then
-  if [ -f "/var/lib/ambari-agent/upgrade_agent_configs.py" ]; then
-    /var/lib/ambari-agent/upgrade_agent_configs.py
-  fi
-  mv $BAK ${BAK}_$(date '+%d_%m_%y_%H_%M').save
-fi
-
-
 exit 0

+ 0 - 8
ambari-agent/src/main/package/rpm/preremove.sh

@@ -19,17 +19,9 @@
 
 
 if [ "$1" -eq 0 ]; then  # Action is uninstall
-    /usr/sbin/ambari-agent stop > /dev/null 2>&1
-    if [ -d "/etc/ambari-agent/conf.save" ]; then
-        mv /etc/ambari-agent/conf.save /etc/ambari-agent/conf_$(date '+%d_%m_%y_%H_%M').save
-    fi
-    mv /etc/ambari-agent/conf /etc/ambari-agent/conf.save
-
     if [ -f "/var/lib/ambari-agent/install-helper.sh" ]; then
       /var/lib/ambari-agent/install-helper.sh remove
     fi
-
-    chkconfig --list | grep ambari-server && chkconfig --del ambari-server
 fi
 
 exit 0

+ 2 - 2
ambari-agent/src/packages/tarball/all.xml

@@ -161,7 +161,7 @@
     </file>
     <file>
       <fileMode>755</fileMode>
-      <source>conf/unix/ambari-agent</source>
+      <source>${basedir}/target/src/ambari-agent</source>
       <outputDirectory>/usr/sbin</outputDirectory>
     </file>
     <file>
@@ -187,7 +187,7 @@
     <file>
       <fileMode>755</fileMode>
       <source>etc/init.d/ambari-agent</source>
-      <outputDirectory>/etc/init.d/ambari-agent</outputDirectory>
+      <outputDirectory>/etc/init.d</outputDirectory>
     </file>
     <file>
       <fileMode>644</fileMode>

+ 39 - 9
ambari-server/conf/unix/install-helper.sh

@@ -33,6 +33,9 @@ PYTHON_WRAPER_TARGET="/usr/bin/ambari-python-wrap"
 PYTHON_WRAPER_SOURCE="/var/lib/ambari-server/ambari-python-wrap"
 
 do_install(){
+  rm -f /usr/sbin/ambari-server
+  ln -s /etc/init.d/ambari-server /usr/sbin/ambari-server
+ 
   # setting ambari_commons shared resource
   rm -rf "$OLD_COMMON_DIR"
   if [ ! -d "$COMMON_DIR" ]; then
@@ -54,10 +57,27 @@ do_install(){
   if [ ! -f "$PYTHON_WRAPER_TARGET" ]; then
     ln -s "$PYTHON_WRAPER_SOURCE" "$PYTHON_WRAPER_TARGET"
   fi
+
+  which chkconfig > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    chkconfig --add ambari-server
+  fi
+  which update-rc.d > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    update-rc.d ambari-server defaults
+  fi
 }
 
 do_remove(){
+  /usr/sbin/ambari-server stop > /dev/null 2>&1
+  if [ -d "/etc/ambari-server/conf.save" ]; then
+      mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
+  fi
+  # Remove link created during install
+  rm -f /usr/sbin/ambari-server
 
+  mv /etc/ambari-server/conf /etc/ambari-server/conf.save
+    
   if [ -f "$PYTHON_WRAPER_TARGET" ]; then
     rm -f "$PYTHON_WRAPER_TARGET"
   fi
@@ -90,20 +110,30 @@ do_remove(){
   if [ -f "$INSTALL_HELPER_AGENT" ]; then  #  call agent shared files installer
     $INSTALL_HELPER_AGENT install
   fi
+
+  which chkconfig > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    chkconfig --list | grep ambari-server && chkconfig --del ambari-server
+  fi
+  which update-rc.d > /dev/null 2>&1
+  if [ "$?" -eq 0 ] ; then
+    update-rc.d -f ambari-server remove
+  fi
 }
 
 do_upgrade(){
+  # this function only gets called for rpm. Deb packages always call do_install directly.
   do_install
 }
 
 case "$1" in
-install)
-  do_install
-  ;;
-remove)
-  do_remove
-  ;;
-upgrade)
-  do_upgrade
-  ;;
+	install)
+	  do_install
+	  ;;
+	remove)
+	  do_remove
+	  ;;
+	upgrade)
+	  do_upgrade
+	  ;;
 esac

+ 1 - 1
ambari-server/src/main/assemblies/server.xml

@@ -200,7 +200,7 @@
     </file>
     <file>
       <fileMode>755</fileMode>
-      <source>sbin/ambari-server</source>
+      <source>${basedir}/target/ambari-server</source>
       <outputDirectory>/etc/init.d</outputDirectory>
     </file>
     <file>

+ 2 - 8
ambari-server/src/main/package/deb/control/postinst

@@ -14,18 +14,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License
 
-if [ -e "/usr/sbin/ambari-server" ]; then # Check is needed for upgrade
-    # Remove link created by previous package version
-    rm -f /usr/sbin/ambari-server
-fi
-
-ln -s /etc/init.d/ambari-server /usr/sbin/ambari-server
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
 
-if [ "$1" == "configure" ]; then  # Action is install
+if [ "$1" == "configure" ] ; then
   if [ -f "/var/lib/ambari-server/install-helper.sh" ]; then
       /var/lib/ambari-server/install-helper.sh install
   fi
-  update-rc.d ambari-server defaults
 fi
 
 exit 0

+ 0 - 15
ambari-server/src/main/package/deb/control/posttrm

@@ -1,15 +0,0 @@
-#!/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License

+ 2 - 16
ambari-server/src/main/package/deb/control/prerm

@@ -14,26 +14,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License
 
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
 
-
-if [ "$1" == "remove" ]; then # Action is uninstall
-    /usr/sbin/ambari-server stop > /dev/null 2>&1
-    if [ -d "/etc/ambari-server/conf.save" ]; then
-        mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
-    fi
-
-    if [ -e "/usr/sbin/ambari-server" ]; then
-        # Remove link created during install
-        rm /usr/sbin/ambari-server
-    fi
-
-    mv /etc/ambari-server/conf /etc/ambari-server/conf.save
-
+if [ "$1" == "remove" ] ; then # Action is uninstall
     if [ -f "/var/lib/ambari-server/install-helper.sh" ]; then
       /var/lib/ambari-server/install-helper.sh remove
     fi
-
-    update-rc.d -f ambari-server remove
 fi
 
 exit 0

+ 1 - 7
ambari-server/src/main/package/rpm/postinstall.sh

@@ -13,19 +13,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License
 
-if [ -e "/usr/sbin/ambari-server" ]; then # Check is needed for upgrade
-    # Remove link created by previous package version
-    rm -f /usr/sbin/ambari-server
-fi
-
-ln -s /etc/init.d/ambari-server /usr/sbin/ambari-server
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
 
 case "$1" in
   1) # Action install
     if [ -f "/var/lib/ambari-server/install-helper.sh" ]; then
         /var/lib/ambari-server/install-helper.sh install
     fi
-    chkconfig --add ambari-server
   ;;
   2) # Action upgrade
     if [ -f "/var/lib/ambari-server/install-helper.sh" ]; then

+ 3 - 15
ambari-server/src/main/package/rpm/preremove.sh

@@ -17,24 +17,12 @@
 # during package update. See http://www.ibm.com/developerworks/library/l-rpm2/
 # for details
 
-if [ "$1" -eq 0 ]; then  # Action is uninstall
-    /usr/sbin/ambari-server stop > /dev/null 2>&1
-    if [ -d "/etc/ambari-server/conf.save" ]; then
-        mv /etc/ambari-server/conf.save /etc/ambari-server/conf_$(date '+%d_%m_%y_%H_%M').save
-    fi
-
-    if [ -e "/usr/sbin/ambari-server" ]; then
-        # Remove link created during install
-        rm /usr/sbin/ambari-server
-    fi
-
-    mv /etc/ambari-server/conf /etc/ambari-server/conf.save
+# Warning: don't add changes to this script directly, please add changes to install-helper.sh.
 
+if [ "$1" -eq 0 ]; then  # Action is uninstall
     if [ -f "/var/lib/ambari-server/install-helper.sh" ]; then
       /var/lib/ambari-server/install-helper.sh remove
     fi
-
-    chkconfig --list | grep ambari-server && chkconfig --del ambari-server
 fi
 
-exit 0
+exit 0