Browse Source

AMBARI-10771. Agent upgrade loses custom hostname config (aonishuk)

Andrew Onishuk 10 years ago
parent
commit
e8f315cea7

+ 51 - 0
ambari-agent/conf/unix/upgrade_agent_configs.py

@@ -0,0 +1,51 @@
+#!/usr/bin/ambari-python-wrap
+'''
+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.
+'''
+
+import os
+import ConfigParser
+
+PROPERTIES_TO_REWRITE = [
+  ('heartbeat', 'dirs')
+]
+
+CONFIG_FILE_BACKUP = '/etc/ambari-agent/conf/ambari-agent.ini.old'
+CONFIG_FILE = '/etc/ambari-agent/conf/ambari-agent.ini'
+
+if os.path.isfile(CONFIG_FILE_BACKUP):
+  if os.path.isfile(CONFIG_FILE):
+    print "Upgrading configs in {0}".format(CONFIG_FILE)
+    print "Values will be updated from {0} except the following list: {1}".format(CONFIG_FILE_BACKUP, PROPERTIES_TO_REWRITE)
+
+    agent_config_backup = ConfigParser.ConfigParser()
+    agent_config_backup.read(CONFIG_FILE_BACKUP)
+
+    agent_config = ConfigParser.ConfigParser()
+    agent_config.read(CONFIG_FILE)
+
+    for section in agent_config_backup.sections():
+      for (property_name, property_val) in agent_config_backup.items(section):
+        if (section, property_name) not in PROPERTIES_TO_REWRITE:
+          agent_config.set(section, property_name, property_val)
+
+    with (open(CONFIG_FILE, "wb")) as new_agent_config:
+      agent_config.write(new_agent_config)
+  else:
+    print "Values are not updated, configs {0} is not found".format(CONFIG_FILE)
+else:
+  print "Values are not updated, backup {0} is not found".format(CONFIG_FILE_BACKUP)

+ 22 - 0
ambari-agent/pom.xml

@@ -340,6 +340,17 @@
                 </source>
               </sources>
             </mapping>
+            <mapping>
+              <directory>/var/lib/ambari-agent</directory>
+              <filemode>700</filemode>
+              <username>root</username>
+              <groupname>root</groupname>
+              <sources>
+                <source>
+                  <location>conf/unix/upgrade_agent_configs.py</location>
+                </source>
+              </sources>
+            </mapping>
             <mapping>
               <directory>${package.pid.dir}</directory>
               <filemode>755</filemode>
@@ -521,6 +532,17 @@
                 <filemode>700</filemode>
               </mapper>
             </data>
+            <data>
+              <src>conf/unix/upgrade_agent_configs.py</src>
+              <type>file</type>
+              <mapper>
+                <type>perm</type>
+                <prefix>/var/lib/ambari-agent</prefix>
+                <user>root</user>
+                <group>root</group>
+                <filemode>700</filemode>
+              </mapper>
+            </data>
             <data>
               <type>template</type>
               <paths>

+ 4 - 3
ambari-agent/src/main/package/deb/control/postinst

@@ -25,8 +25,9 @@ BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
 ORIG=/etc/ambari-agent/conf/ambari-agent.ini
 
 if [ -f $BAK ];then
-  SERV_HOST=`grep -e hostname\s*= $BAK | sed -r -e 's/hostname\s*=//' -e 's/\./\\\./g'`
-  sed -i -r -e "s/(hostname\s*=).*/\1$SERV_HOST/" $ORIG
-  rm $BAK -f
+  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

+ 4 - 3
ambari-agent/src/main/package/rpm/postinstall.sh

@@ -38,9 +38,10 @@ BAK=/etc/ambari-agent/conf/ambari-agent.ini.old
 ORIG=/etc/ambari-agent/conf/ambari-agent.ini
 
 if [ -f $BAK ]; then
-  SERV_HOST=`grep -e hostname\s*= $BAK | sed -r -e 's/hostname\s*=//' -e 's/\./\\\./g'`
-  sed -i -r -e "s/(hostname\s*=).*/\1$SERV_HOST/" $ORIG
-  rm $BAK -f
+  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