Repository: ambari
Updated Branches:
  refs/heads/trunk 58b91c845 -> f6a75a609


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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f6a75a60
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f6a75a60
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f6a75a60

Branch: refs/heads/trunk
Commit: f6a75a609caa1ce24c6cf9ab1f6303eb5bc9e923
Parents: 58b91c8
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Wed Feb 3 11:52:49 2016 +0200
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Wed Feb 3 11:52:49 2016 +0200

----------------------------------------------------------------------
 ambari-agent/conf/unix/install-helper.sh        | 40 +++++++++++++++-
 .../src/main/package/deb/control/postinst       | 12 +----
 .../src/main/package/deb/control/posttrm        | 15 ------
 ambari-agent/src/main/package/deb/control/prerm |  8 ----
 .../src/main/package/rpm/postinstall.sh         | 19 +-------
 ambari-agent/src/main/package/rpm/preremove.sh  |  8 ----
 ambari-agent/src/packages/tarball/all.xml       |  4 +-
 ambari-server/conf/unix/install-helper.sh       | 48 ++++++++++++++++----
 ambari-server/src/main/assemblies/server.xml    |  2 +-
 .../src/main/package/deb/control/postinst       | 10 +---
 .../src/main/package/deb/control/posttrm        | 15 ------
 .../src/main/package/deb/control/prerm          | 18 +-------
 .../src/main/package/rpm/postinstall.sh         |  8 +---
 ambari-server/src/main/package/rpm/preremove.sh | 18 ++------
 14 files changed, 92 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/conf/unix/install-helper.sh
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/install-helper.sh 
b/ambari-agent/conf/unix/install-helper.sh
index 185290c..91ae248 100644
--- a/ambari-agent/conf/unix/install-helper.sh
+++ b/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(){

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/main/package/deb/control/postinst
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/package/deb/control/postinst 
b/ambari-agent/src/main/package/deb/control/postinst
index ceca9be..48cb07c 100644
--- a/ambari-agent/src/main/package/deb/control/postinst
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/main/package/deb/control/posttrm
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/package/deb/control/posttrm 
b/ambari-agent/src/main/package/deb/control/posttrm
deleted file mode 100644
index 21a01fa..0000000
--- a/ambari-agent/src/main/package/deb/control/posttrm
+++ /dev/null
@@ -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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/main/package/deb/control/prerm
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/package/deb/control/prerm 
b/ambari-agent/src/main/package/deb/control/prerm
index 70a9c63..8da949c 100644
--- a/ambari-agent/src/main/package/deb/control/prerm
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/main/package/rpm/postinstall.sh
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/package/rpm/postinstall.sh 
b/ambari-agent/src/main/package/rpm/postinstall.sh
index 56c6573..17e6e0e 100644
--- a/ambari-agent/src/main/package/rpm/postinstall.sh
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/main/package/rpm/preremove.sh
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/package/rpm/preremove.sh 
b/ambari-agent/src/main/package/rpm/preremove.sh
index 2078acd..e266114 100644
--- a/ambari-agent/src/main/package/rpm/preremove.sh
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-agent/src/packages/tarball/all.xml
----------------------------------------------------------------------
diff --git a/ambari-agent/src/packages/tarball/all.xml 
b/ambari-agent/src/packages/tarball/all.xml
index d4ed2ff..d9732cc 100644
--- a/ambari-agent/src/packages/tarball/all.xml
+++ b/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>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/conf/unix/install-helper.sh
----------------------------------------------------------------------
diff --git a/ambari-server/conf/unix/install-helper.sh 
b/ambari-server/conf/unix/install-helper.sh
index 2635694..c7d05b4 100644
--- a/ambari-server/conf/unix/install-helper.sh
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/assemblies/server.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/assemblies/server.xml 
b/ambari-server/src/main/assemblies/server.xml
index c24bce6..17d6bdb 100644
--- a/ambari-server/src/main/assemblies/server.xml
+++ b/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>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/package/deb/control/postinst
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/deb/control/postinst 
b/ambari-server/src/main/package/deb/control/postinst
index c3b6235..e8d12c3 100644
--- a/ambari-server/src/main/package/deb/control/postinst
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/package/deb/control/posttrm
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/deb/control/posttrm 
b/ambari-server/src/main/package/deb/control/posttrm
deleted file mode 100644
index 21a01fa..0000000
--- a/ambari-server/src/main/package/deb/control/posttrm
+++ /dev/null
@@ -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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/package/deb/control/prerm
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/deb/control/prerm 
b/ambari-server/src/main/package/deb/control/prerm
index 927ba4c..98e3be5 100644
--- a/ambari-server/src/main/package/deb/control/prerm
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/package/rpm/postinstall.sh
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/rpm/postinstall.sh 
b/ambari-server/src/main/package/rpm/postinstall.sh
index 9b0b54a..5ca1d17 100644
--- a/ambari-server/src/main/package/rpm/postinstall.sh
+++ b/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

http://git-wip-us.apache.org/repos/asf/ambari/blob/f6a75a60/ambari-server/src/main/package/rpm/preremove.sh
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/package/rpm/preremove.sh 
b/ambari-server/src/main/package/rpm/preremove.sh
index 6febaa8..445e9ad 100644
--- a/ambari-server/src/main/package/rpm/preremove.sh
+++ b/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
\ No newline at end of file

Reply via email to