Updated Branches: refs/heads/trunk 99e0e02a0 -> ac5bd63c6
AMBARI-1369. Changes to ambari-server.py setup and start to support ubuntu. (Arpit Gupta via mahadev) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/ac5bd63c Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/ac5bd63c Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/ac5bd63c Branch: refs/heads/trunk Commit: ac5bd63c6320f8095a948b6231d84541407c6ce2 Parents: 99e0e02 Author: Mahadev Konar <[email protected]> Authored: Tue Oct 29 12:40:12 2013 -0700 Committer: Mahadev Konar <[email protected]> Committed: Tue Oct 29 12:40:12 2013 -0700 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 66 ++++++++++++--------- 1 file changed, 38 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ac5bd63c/ambari-server/src/main/python/ambari-server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py index 325a405..55c104a 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -19,7 +19,6 @@ limitations under the License. ''' import optparse -from pprint import pprint import shlex import sys import os @@ -37,7 +36,6 @@ import time import getpass import socket import datetime -import socket import tempfile import random import pwd @@ -47,6 +45,10 @@ VERBOSE = False SILENT = False SERVER_START_DEBUG = False +# OS info +OS = platform.dist()[0].lower() +OS_UBUNTU = 'ubuntu' + # action commands SETUP_ACTION = "setup" START_ACTION = "start" @@ -74,10 +76,6 @@ SE_STATUS_ENABLED = "enabled" SE_MODE_ENFORCING = "enforcing" SE_MODE_PERMISSIVE = "permissive" -# iptables commands -IP_TBLS_STATUS_CMD = "/sbin/service iptables status" -IP_TBLS_IS_NOT_RUNNING = "iptables: Firewall is not running." - # server commands ambari_provider_module_option = "" ambari_provider_module = os.environ.get('AMBARI_PROVIDER_MODULE') @@ -227,17 +225,33 @@ SETUP_DB_CMD = ['su', '-', 'postgres', UPGRADE_STACK_CMD = ['su', 'postgres', '--command=psql -f {0} -v stack_name="\'{1}\'" -v stack_version="\'{2}\'" -v dbname="{3}"'] UPDATE_METAINFO_CMD = 'curl -X PUT "http://{0}:{1}/api/v1/stacks2" -u "{2}":"{3}"' -PG_ST_CMD = "/sbin/service postgresql status" -PG_INITDB_CMD = "/sbin/service postgresql initdb" -PG_START_CMD = "/sbin/service postgresql start" -PG_RESTART_CMD = "/sbin/service postgresql restart" + PG_STATUS_RUNNING = "running" -PG_HBA_DIR = "/var/lib/pgsql/data/" -PG_HBA_CONF_FILE = PG_HBA_DIR + "pg_hba.conf" -PG_HBA_CONF_FILE_BACKUP = PG_HBA_DIR + "pg_hba_bak.conf.old" -POSTGRESQL_CONF_FILE = PG_HBA_DIR + "postgresql.conf" -PG_HBA_RELOAD_CMD = "su postgres --command='pg_ctl -D {0} reload'" PG_DEFAULT_PASSWORD = "bigdata" +SERVICE_CMD = "/sbin/service" +PG_SERVICE_NAME = "postgresql" +PG_HBA_DIR = "/var/lib/pgsql/data" +# iptables commands +FIREWALL_SERVICE_NAME = "iptables" +IP_TBLS_IS_NOT_RUNNING = "iptables: Firewall is not running." +# on ubuntu iptables service is called ufw and other changes +if OS == OS_UBUNTU: + FIREWALL_SERVICE_NAME = "ufw" + IP_TBLS_IS_NOT_RUNNING = "ufw stop/waiting" + PG_HBA_DIR = '/etc/postgresql/8.4/main' + SERVICE_CMD = "/usr/sbin/service" + +IP_TBLS_STATUS_CMD = "%s %s status" % (SERVICE_CMD, FIREWALL_SERVICE_NAME) + +PG_ST_CMD = "%s %s status" % (SERVICE_CMD, PG_SERVICE_NAME) +PG_INITDB_CMD = "%s %s initdb" % (SERVICE_CMD, PG_SERVICE_NAME) +PG_START_CMD = "%s %s start" % (SERVICE_CMD, PG_SERVICE_NAME) +PG_RESTART_CMD = "%s %s restart" % (SERVICE_CMD, PG_SERVICE_NAME) +PG_HBA_RELOAD_CMD = "%s %s reload" % (SERVICE_CMD, PG_SERVICE_NAME) + +PG_HBA_CONF_FILE = os.path.join(PG_HBA_DIR, "pg_hba.conf") +PG_HBA_CONF_FILE_BACKUP = os.path.join(PG_HBA_DIR, "pg_hba_bak.conf.old") +POSTGRESQL_CONF_FILE = os.path.join(PG_HBA_DIR, "postgresql.conf") JDBC_DATABASE_PROPERTY = "server.jdbc.database" JDBC_HOSTNAME_PROPERTY = "server.jdbc.hostname" @@ -771,7 +785,7 @@ def check_iptables(): print err if out and len(out) > 0 and not out.strip() == IP_TBLS_IS_NOT_RUNNING: - print_warning_msg("iptables is running. Confirm the necessary Ambari ports are accessible. " + + print_warning_msg("%s is running. Confirm the necessary Ambari ports are accessible. " % FIREWALL_SERVICE_NAME + "Refer to the Ambari documentation for more details on ports.") ok = get_YN_input("OK to continue [y/n] (y)? ", True) if not ok: @@ -796,8 +810,7 @@ def configure_pg_hba_ambaridb_users(): pgHbaConf.write("host all " + args.database_username + ",mapred ::/0 md5") pgHbaConf.write("\n") - command = PG_HBA_RELOAD_CMD.format(PG_HBA_DIR) - retcode, out, err = run_os_command(command) + retcode, out, err = run_os_command(PG_HBA_RELOAD_CMD) if not retcode == 0: raise FatalException(retcode, err) @@ -964,28 +977,26 @@ def check_db_consistency(args, file): return 0 return -1 - - def get_postgre_status(): retcode, out, err = run_os_command(PG_ST_CMD) try: - pg_status = re.search('(stopped|running)', out).group(0) + pg_status = re.search('(stopped|running)', out, re.IGNORECASE).group(0).lower() except AttributeError: pg_status = None return pg_status - - def check_postgre_up(): pg_status = get_postgre_status() if pg_status == PG_STATUS_RUNNING: print_info_msg ("PostgreSQL is running") return 0 else: - print "Running initdb: This may take upto a minute." - retcode, out, err = run_os_command(PG_INITDB_CMD) - if retcode == 0: - print out + # run initdb only on non ubuntu systems as ubuntu does not have initdb cmd. + if OS != OS_UBUNTU: + print "Running initdb: This may take upto a minute." + retcode, out, err = run_os_command(PG_INITDB_CMD) + if retcode == 0: + print out print "About to start PostgreSQL" try: process = subprocess.Popen(PG_START_CMD.split(' '), @@ -3758,7 +3769,6 @@ def main(): parser.add_option('--databasepassword', default=None, help="Database user password", dest="database_password") parser.add_option('--sidorsname', default="sname", help="Oracle database identifier type, Service ID/Service " "Name sid|sname", dest="sid_or_sname") - (options, args) = parser.parse_args() # set verbose
