This is an automated email from the ASF dual-hosted git repository.

amagyar pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.6 by this push:
     new 45712a4  AMBARI-25191. Ambari server setup failed with postgres 
connectivity error when using postgres 9.3 (amagyar) (#2859)
45712a4 is described below

commit 45712a497d4b44c079b2fc68bab47ad2c7530322
Author: Attila Magyar <m.magy...@gmail.com>
AuthorDate: Wed Mar 13 12:34:13 2019 +0100

    AMBARI-25191. Ambari server setup failed with postgres connectivity error 
when using postgres 9.3 (amagyar) (#2859)
---
 .../src/main/python/ambari_commons/os_check.py     |  2 ++
 .../python/ambari_server/dbConfiguration_linux.py  | 39 +++++++++++++++++-----
 .../src/main/python/ambari_server/utils.py         | 14 +++++---
 3 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/ambari-common/src/main/python/ambari_commons/os_check.py 
b/ambari-common/src/main/python/ambari_commons/os_check.py
index 0416584..b2b2274 100644
--- a/ambari-common/src/main/python/ambari_commons/os_check.py
+++ b/ambari-common/src/main/python/ambari_commons/os_check.py
@@ -164,6 +164,8 @@ class OS_CONST_TYPE(type):
 class OSConst:
   __metaclass__ = OS_CONST_TYPE
 
+  systemd_redhat_os_major_versions = ["7"]
+
 
 class OSCheck:
 
diff --git 
a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py 
b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
index 5a78816..4c5316b 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -351,19 +351,42 @@ class PGConfig(LinuxDBMSConfig):
   PG_ERROR_BLOCKED = "is being accessed by other users"
   PG_STATUS_RUNNING = None
   PG_STATUS_STOPPED = "stopped"
-  SERVICE_CMD = "/usr/bin/env service"
   PG_SERVICE_NAME = "postgresql"
   PG_HBA_DIR = None
 
-  PG_ST_CMD = "%s %s status" % (SERVICE_CMD, PG_SERVICE_NAME)
-  if os.path.isfile("/usr/bin/postgresql-setup"):
+  if OSCheck.is_redhat_family() and OSCheck.get_os_major_version() in 
OSConst.systemd_redhat_os_major_versions:
+    if os.path.isfile("/usr/bin/postgresql-setup"):
       PG_INITDB_CMD = "/usr/bin/postgresql-setup initdb"
+    else:
+      versioned_script_path = glob.glob("/usr/pgsql-*/bin/postgresql*-setup")
+      # versioned version of psql
+      if versioned_script_path:
+        PG_INITDB_CMD = "{0} initdb".format(versioned_script_path[0])
+
+        psql_service_file = 
glob.glob("/usr/lib/systemd/system/postgresql-*.service")
+        if psql_service_file:
+          psql_service_file_name = os.path.basename(psql_service_file[0])
+          PG_SERVICE_NAME = psql_service_file_name[:-8] # remove .service
+      else:
+        raise FatalException(1, "Cannot find postgresql-setup script.")
+
+    SERVICE_CMD = "/usr/bin/env systemctl"
+    PG_ST_CMD = "%s status %s" % (SERVICE_CMD, PG_SERVICE_NAME)
+
+    PG_START_CMD = AMBARI_SUDO_BINARY + " %s start %s" % (SERVICE_CMD, 
PG_SERVICE_NAME)
+    PG_RESTART_CMD = AMBARI_SUDO_BINARY + " %s restart %s" % (SERVICE_CMD, 
PG_SERVICE_NAME)
+    PG_HBA_RELOAD_CMD = AMBARI_SUDO_BINARY + " %s reload %s" % (SERVICE_CMD, 
PG_SERVICE_NAME)
   else:
-      PG_INITDB_CMD = "%s %s initdb" % (SERVICE_CMD, PG_SERVICE_NAME)
+    SERVICE_CMD = "/usr/bin/env service"
+    PG_ST_CMD = "%s %s status" % (SERVICE_CMD, PG_SERVICE_NAME)
+    if os.path.isfile("/usr/bin/postgresql-setup"):
+        PG_INITDB_CMD = "/usr/bin/postgresql-setup initdb"
+    else:
+        PG_INITDB_CMD = "%s %s initdb" % (SERVICE_CMD, PG_SERVICE_NAME)
 
-  PG_START_CMD = AMBARI_SUDO_BINARY + " %s %s start" % (SERVICE_CMD, 
PG_SERVICE_NAME)
-  PG_RESTART_CMD = AMBARI_SUDO_BINARY + " %s %s restart" % (SERVICE_CMD, 
PG_SERVICE_NAME)
-  PG_HBA_RELOAD_CMD = AMBARI_SUDO_BINARY + " %s %s reload" % (SERVICE_CMD, 
PG_SERVICE_NAME)
+    PG_START_CMD = AMBARI_SUDO_BINARY + " %s %s start" % (SERVICE_CMD, 
PG_SERVICE_NAME)
+    PG_RESTART_CMD = AMBARI_SUDO_BINARY + " %s %s restart" % (SERVICE_CMD, 
PG_SERVICE_NAME)
+    PG_HBA_RELOAD_CMD = AMBARI_SUDO_BINARY + " %s %s reload" % (SERVICE_CMD, 
PG_SERVICE_NAME)
 
   PG_HBA_CONF_FILE = None
   PG_HBA_CONF_FILE_BACKUP = None
@@ -607,7 +630,7 @@ class PGConfig(LinuxDBMSConfig):
     retcode, out, err = run_os_command(PGConfig.PG_ST_CMD)
     # on RHEL and SUSE PG_ST_COMD returns RC 0 for running and 3 for stoppped
     if retcode == 0:
-      if out.strip() == "Running clusters:":
+      if out.strip() == "Running clusters:" or "active: inactive" in 
out.lower():
         pg_status = PGConfig.PG_STATUS_STOPPED
       else:
         pg_status = PGConfig.PG_STATUS_RUNNING
diff --git a/ambari-server/src/main/python/ambari_server/utils.py 
b/ambari-server/src/main/python/ambari_server/utils.py
index fcba7f1..e5cb828 100644
--- a/ambari-server/src/main/python/ambari_server/utils.py
+++ b/ambari-server/src/main/python/ambari_server/utils.py
@@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
 # PostgreSQL settings
 PG_STATUS_RUNNING_DEFAULT = "running"
 PG_HBA_ROOT_DEFAULT = "/var/lib/pgsql/data"
+PG_HBA_ROOT_DEFAULT_VERSIONED = "/var/lib/pgsql/*/data"
 
 #Environment
 ENV_PATH_DEFAULT = ['/bin', '/usr/bin', '/sbin', '/usr/sbin']  # default 
search path
@@ -259,9 +260,7 @@ def get_postgre_hba_dir(OS_FAMILY):
     # Like: /etc/postgresql/9.1/main/
     return os.path.join(get_pg_hba_init_files(), get_ubuntu_pg_version(),
                         "main")
-  elif not glob.glob(get_pg_hba_init_files() + '*'): # this happens when the 
service file is of new format (/usr/lib/systemd/system/postgresql.service)
-    return PG_HBA_ROOT_DEFAULT
-  else:
+  elif glob.glob(get_pg_hba_init_files() + '*'): # this happens when the 
service file is of old format (not like 
/usr/lib/systemd/system/postgresql.service)
     if not os.path.isfile(get_pg_hba_init_files()):
       # Link: /etc/init.d/postgresql --> /etc/init.d/postgresql-9.1
       os.symlink(glob.glob(get_pg_hba_init_files() + '*')[0],
@@ -279,8 +278,13 @@ def get_postgre_hba_dir(OS_FAMILY):
 
     if PG_HBA_ROOT and len(PG_HBA_ROOT.strip()) > 0:
       return PG_HBA_ROOT.strip()
-    else:
-      return PG_HBA_ROOT_DEFAULT
+
+  if not os.path.exists(PG_HBA_ROOT_DEFAULT):
+    versioned_dirs = glob.glob(PG_HBA_ROOT_DEFAULT_VERSIONED)
+    if versioned_dirs:
+      return versioned_dirs[0]
+
+  return PG_HBA_ROOT_DEFAULT
 
 
 def get_postgre_running_status():

Reply via email to