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

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


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new ce57c77  AMBARI-25465 Postgresql service naming convention changed on 
SUSE 12 SP2 (#3174) (aszilárd via dgrinenko)
ce57c77 is described below

commit ce57c775c5891e0e95496cf05d6441011d41f40a
Author: Szilárd Antal <san...@cloudera.com>
AuthorDate: Tue Feb 4 14:53:09 2020 +0100

    AMBARI-25465 Postgresql service naming convention changed on SUSE 12 SP2 
(#3174) (aszilárd via dgrinenko)
---
 .../src/main/python/ambari_commons/os_linux.py     |  7 +++++++
 .../src/main/python/ambari_commons/os_utils.py     |  7 +++++--
 .../src/main/python/ambari_commons/os_windows.py   | 10 ++++++++++
 .../python/ambari_server/dbConfiguration_linux.py  | 23 ++++++++++++++++++----
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/ambari-common/src/main/python/ambari_commons/os_linux.py 
b/ambari-common/src/main/python/ambari_commons/os_linux.py
index 053051b..4480183 100644
--- a/ambari-common/src/main/python/ambari_commons/os_linux.py
+++ b/ambari-common/src/main/python/ambari_commons/os_linux.py
@@ -84,3 +84,10 @@ def os_set_open_files_limit(maxOpenFiles):
 
 def os_getpass(prompt):
   return getpass.unix_getpass(prompt)
+
+def os_is_service_exist(serviceName):
+  if os.path.exists('/run/systemd/system/'):
+    return os.popen('systemctl list-units --full -all | grep "%s.service"' % 
serviceName).read().strip() != ''
+
+  status = os.system("service %s status >/dev/null 2>&1" % serviceName)
+  return status != 256
\ No newline at end of file
diff --git a/ambari-common/src/main/python/ambari_commons/os_utils.py 
b/ambari-common/src/main/python/ambari_commons/os_utils.py
index 620bd0e..0757acb 100644
--- a/ambari-common/src/main/python/ambari_commons/os_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/os_utils.py
@@ -33,11 +33,11 @@ else:
 
 if OSCheck.is_windows_family():
   from ambari_commons.os_windows import os_change_owner, os_getpass, 
os_is_root, os_run_os_command, \
-    os_set_open_files_limit, os_set_file_permissions
+    os_set_open_files_limit, os_set_file_permissions, os_is_service_exist
 else:
   # MacOS not supported
   from ambari_commons.os_linux import os_change_owner, os_getpass, os_is_root, 
os_run_os_command, \
-    os_set_open_files_limit, os_set_file_permissions
+    os_set_open_files_limit, os_set_file_permissions, os_is_service_exist
   pass
 
 from ambari_commons.exceptions import FatalException
@@ -131,6 +131,9 @@ def set_open_files_limit(maxOpenFiles):
 def get_password(prompt):
   return os_getpass(prompt)
 
+def is_service_exist(serviceName):
+  return os_is_service_exist(serviceName)
+
 def find_in_path(file):
   full_path = _search_file(file, os.environ["PATH"], os.pathsep)
   if full_path is None:
diff --git a/ambari-common/src/main/python/ambari_commons/os_windows.py 
b/ambari-common/src/main/python/ambari_commons/os_windows.py
index 4c22384..f674894 100644
--- a/ambari-common/src/main/python/ambari_commons/os_windows.py
+++ b/ambari-common/src/main/python/ambari_commons/os_windows.py
@@ -471,6 +471,16 @@ def wait_for_pid_wmi(processName, parentPid, pattern, 
timeout):
   return 0
 
 
+def os_is_service_exist(serviceName):
+  try:
+    win32serviceutil.QueryServiceStatus(serviceName)
+  except:
+    # "Windows service NOT installed"
+    return False
+  else:
+    # "Windows service installed"
+    return True
+
 #need this for redirecting output form python process to file
 class SyncStreamWriter(object):
   def __init__(self, stream, hMutexWrite):
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 e95bbbd..4790f5d 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -31,7 +31,7 @@ import pwd
 from ambari_commons import OSCheck, OSConst
 from ambari_commons.logging_utils import get_silent, get_verbose, 
print_error_msg, print_info_msg, print_warning_msg
 from ambari_commons.exceptions import NonFatalException, FatalException
-from ambari_commons.os_utils import copy_files, find_in_path, is_root, 
remove_file, run_os_command
+from ambari_commons.os_utils import copy_files, find_in_path, is_root, 
remove_file, run_os_command, is_service_exist
 from ambari_server.dbConfiguration import DBMSConfig, USERNAME_PATTERN, 
SETUP_DB_CONNECT_ATTEMPTS, \
     SETUP_DB_CONNECT_TIMEOUT, STORAGE_TYPE_LOCAL, DEFAULT_USERNAME, 
DEFAULT_PASSWORD
 from ambari_server.serverConfiguration import encrypt_password, 
store_password_file, \
@@ -385,11 +385,25 @@ class PGConfig(LinuxDBMSConfig):
     PG_HBA_RELOAD_CMD = AMBARI_SUDO_BINARY + " %s reload %s" % (SERVICE_CMD, 
PG_SERVICE_NAME)
   else:
     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_INITDB_CMD = "%s %s initdb" % (SERVICE_CMD, PG_SERVICE_NAME)
+
+      if OSCheck.is_suse_family() and not is_service_exist(PG_SERVICE_NAME):
+        versioned_script_paths = 
glob.glob("/usr/pgsql-*/bin/postgresql*-setup")
+        if versioned_script_paths:
+          versioned_script_path_tps = map(lambda path: 
(re.search(r'pgsql-([0-9]+\.?[0-9]*)', path).group(1), path), 
versioned_script_paths)
+          versioned_script_path_tps.sort(key = lambda t: float(t[0]), reverse 
= True)
+          for versioned_script_path_tp in versioned_script_path_tps:
+            pgsql_service_file_name = "postgresql-%s" % 
versioned_script_path_tp[0]
+            if is_service_exist(pgsql_service_file_name):
+              PG_SERVICE_NAME = pgsql_service_file_name
+              PG_INITDB_CMD = "%s initdb" % versioned_script_path_tp[1]
+              PG_HBA_DIR = "/var/lib/pgsql/%s/data" % 
versioned_script_path_tp[0]
+              break
+
+    PG_ST_CMD = "%s %s status" % (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)
@@ -433,7 +447,8 @@ class PGConfig(LinuxDBMSConfig):
 
     if self.persistence_type == STORAGE_TYPE_LOCAL:
       PGConfig.PG_STATUS_RUNNING = get_postgre_running_status()
-      PGConfig.PG_HBA_DIR = get_postgre_hba_dir(OS_FAMILY)
+      if not PGConfig.PG_HBA_DIR:
+        PGConfig.PG_HBA_DIR = get_postgre_hba_dir(OS_FAMILY)
 
       PGConfig.PG_HBA_CONF_FILE = os.path.join(PGConfig.PG_HBA_DIR, 
"pg_hba.conf")
       PGConfig.PG_HBA_CONF_FILE_BACKUP = os.path.join(PGConfig.PG_HBA_DIR, 
"pg_hba_bak.conf.old")

Reply via email to