فهرست منبع

AMBARI-19000. Ambari-server fails to restart with --debug if it is already running (aonishuk)

Andrew Onishuk 8 سال پیش
والد
کامیت
964c56e7a8
2فایلهای تغییر یافته به همراه22 افزوده شده و 1 حذف شده
  1. 11 1
      ambari-server/src/main/python/ambari-server.py
  2. 11 0
      ambari-server/src/main/python/ambari_server/serverUtils.py

+ 11 - 1
ambari-server/src/main/python/ambari-server.py

@@ -35,7 +35,7 @@ from ambari_commons.os_utils import remove_file
 from ambari_server.BackupRestore import main as BackupRestore_main
 from ambari_server.dbConfiguration import DATABASE_NAMES, LINUX_DBMS_KEYS_LIST
 from ambari_server.serverConfiguration import configDefaults, get_ambari_properties, PID_NAME
-from ambari_server.serverUtils import is_server_runing, refresh_stack_hash
+from ambari_server.serverUtils import is_server_runing, refresh_stack_hash, wait_for_server_to_stop
 from ambari_server.serverSetup import reset, setup, setup_jce_policy
 from ambari_server.serverUpgrade import upgrade, upgrade_stack, set_current
 from ambari_server.setupHttps import setup_https, setup_truststore
@@ -63,6 +63,8 @@ logger = logging.getLogger()
 
 formatstr = "%(levelname)s %(asctime)s %(filename)s:%(lineno)d - %(message)s"
 
+SERVER_STOP_TIMEOUT = 30
+
 class UserActionPossibleArgs(object):
   def __init__(self, i_fn, i_possible_args_numbers, *args, **kwargs):
     self.fn = i_fn
@@ -166,6 +168,14 @@ def stop(args):
     except OSError, e:
       print_info_msg("Unable to stop Ambari Server - " + str(e))
       return
+
+    print "Waiting for server stop..."
+    logger.info("Waiting for server stop...")
+
+    if not wait_for_server_to_stop(SERVER_STOP_TIMEOUT):
+      print "Ambari-server failed to stop"
+      logger.info("Ambari-server failed to stop")
+
     pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
     os.remove(pid_file_path)
     print "Ambari Server stopped"

+ 11 - 0
ambari-server/src/main/python/ambari_server/serverUtils.py

@@ -19,6 +19,7 @@ limitations under the License.
 '''
 
 import os
+import time
 from ambari_commons.exceptions import FatalException, NonFatalException
 from ambari_commons.logging_utils import get_verbose
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
@@ -62,6 +63,16 @@ def is_server_runing():
     return False, None
 
 
+def wait_for_server_to_stop(wait_timeout):
+  start_time = time.time()
+  is_timeout = lambda: time.time() - start_time > wait_timeout
+
+  while is_server_runing()[0] and not is_timeout():
+    time.sleep(0.1)
+
+  return not is_timeout()
+
+
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
 def is_server_runing():
   from ambari_commons.os_windows import SERVICE_STATUS_STARTING, SERVICE_STATUS_RUNNING, SERVICE_STATUS_STOPPING, \