From 173d90c5b087cdaf0bd18ba4540121ac220db2e5 Mon Sep 17 00:00:00 2001 From: Dmytro Sen Date: Thu, 17 Nov 2016 17:38:05 +0200 Subject: AMBARI-18760 ambari-server.pid might not be created (additional patch) (dsen) --- ambari-server/src/main/python/ambari_server/serverUtils.py | 2 +- ambari-server/src/main/python/ambari_server/utils.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ambari-server/src/main/python/ambari_server/serverUtils.py b/ambari-server/src/main/python/ambari_server/serverUtils.py index 069e24d610..3af233cf54 100644 --- a/ambari-server/src/main/python/ambari_server/serverUtils.py +++ b/ambari-server/src/main/python/ambari_server/serverUtils.py @@ -47,7 +47,7 @@ def is_server_runing(): pid = f.readline().strip() if not pid.isdigit(): - err = "%s is corrupt. Removing" % (pid_file_path) + err = "'%s' is incorrect PID value. %s is corrupt. Removing" % (pid, pid_file_path) f.close() run_os_command("rm -f " + pid_file_path) raise NonFatalException(err) diff --git a/ambari-server/src/main/python/ambari_server/utils.py b/ambari-server/src/main/python/ambari_server/utils.py index 5f0a64d78f..f5054440e9 100644 --- a/ambari-server/src/main/python/ambari_server/utils.py +++ b/ambari-server/src/main/python/ambari_server/utils.py @@ -25,8 +25,11 @@ import sys import time import glob import subprocess +import logging from ambari_commons import OSConst,OSCheck +logger = logging.getLogger(__name__) + # PostgreSQL settings PG_STATUS_RUNNING_DEFAULT = "running" PG_HBA_ROOT_DEFAULT = "/var/lib/pgsql/data" @@ -104,13 +107,13 @@ def save_pid(pid, pidfile): pfile = open(pidfile, "w") pfile.write("%s\n" % pid) except IOError as e: - print_error_msg("Failed to write PID to " + pidfile + " due to " + str(e)) + logger.error("Failed to write PID to " + pidfile + " due to " + str(e)) pass finally: try: pfile.close() except Exception as e: - print_error_msg("Failed to close PID file " + pidfile + " due to " + str(e)) + logger.error("Failed to close PID file " + pidfile + " due to " + str(e)) pass @@ -127,19 +130,20 @@ def save_main_pid_ex(pids, pidfile, exclude_list=[], kill_exclude_list=False, sk for item in pids: if pid_exists(item["pid"]) and (item["exe"] not in exclude_list): pfile.write("%s\n" % item["pid"]) + logger.info("Ambari server started with PID " + str(item["pid"])) if pid_exists(item["pid"]) and (item["exe"] in exclude_list) and not skip_daemonize: try: os.kill(int(item["pid"]), signal.SIGKILL) except: pass except IOError as e: - print_error_msg("Failed to write PID to " + pidfile + " due to " + str(e)) + logger.error("Failed to write PID to " + pidfile + " due to " + str(e)) pass finally: try: pfile.close() except Exception as e: - print_error_msg("Failed to close PID file " + pidfile + " due to " + str(e)) + logger.error("Failed to close PID file " + pidfile + " due to " + str(e)) pass -- cgit v1.2.3