You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2015/04/27 19:24:47 UTC
ambari git commit: AMBARI-10771. Agent upgrade loses custom hostname
config (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/trunk f13d983dd -> e8f315cea
AMBARI-10771. Agent upgrade loses custom hostname config (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e8f315ce
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e8f315ce
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e8f315ce
Branch: refs/heads/trunk
Commit: e8f315cea72f95a8de5011eefd6c298cf47b14c5
Parents: f13d983
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Apr 27 20:24:32 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Apr 27 20:24:32 2015 +0300
----------------------------------------------------------------------
ambari-agent/conf/unix/upgrade_agent_configs.py | 51 ++++++++++++++++++++
ambari-agent/pom.xml | 22 +++++++++
.../src/main/package/deb/control/postinst | 7 +--
.../src/main/package/rpm/postinstall.sh | 7 +--
4 files changed, 81 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e8f315ce/ambari-agent/conf/unix/upgrade_agent_configs.py
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/upgrade_agent_configs.py b/ambari-agent/conf/unix/upgrade_agent_configs.py
new file mode 100644
index 0000000..8b7be7a
--- /dev/null
+++ b/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)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/e8f315ce/ambari-agent/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-agent/pom.xml b/ambari-agent/pom.xml
index 4476011..a57e760 100644
--- a/ambari-agent/pom.xml
+++ b/ambari-agent/pom.xml
@@ -341,6 +341,17 @@
</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>
<username>root</username>
@@ -522,6 +533,17 @@
</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>
<path>${package.pid.dir}</path>
http://git-wip-us.apache.org/repos/asf/ambari/blob/e8f315ce/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 69a09e8..ceca9be 100644
--- a/ambari-agent/src/main/package/deb/control/postinst
+++ b/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
http://git-wip-us.apache.org/repos/asf/ambari/blob/e8f315ce/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 53c5958..56c6573 100644
--- a/ambari-agent/src/main/package/rpm/postinstall.sh
+++ b/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