Browse Source

AMBARI-17061. [ambari] ambari-agent restart is failing due to unsupported locale setting (aonishuk)

Andrew Onishuk 9 năm trước cách đây
mục cha
commit
02d36acb2a
1 tập tin đã thay đổi với 7 bổ sung4 xóa
  1. 7 4
      ambari-agent/src/main/python/ambari_agent/main.py

+ 7 - 4
ambari-agent/src/main/python/ambari_agent/main.py

@@ -27,6 +27,7 @@ import traceback
 import getpass
 import os
 import time
+import locale
 import platform
 import ConfigParser
 import ProcessHelper
@@ -49,10 +50,6 @@ from resource_management.core.logger import Logger
 logger = logging.getLogger()
 alerts_logger = logging.getLogger('ambari_alerts')
 
-# use the host's locale for numeric formatting
-import locale
-locale.setlocale(locale.LC_ALL, '')
-
 formatstr = "%(levelname)s %(asctime)s %(filename)s:%(lineno)d - %(message)s"
 agentPid = os.getpid()
 config = AmbariConfig.AmbariConfig()
@@ -268,6 +265,12 @@ def main(heartbeat_stop_callback=None):
   setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level)
   Logger.initialize_logger('resource_management', logging_level=logging_level)
 
+  # use the host's locale for numeric formatting
+  try:
+    locale.setlocale(locale.LC_ALL, '')
+  except locale.Error as ex:
+    logger.warning("Cannot set locale for ambari-agent. Please check your systemwide locale settings. Failed due to: {0}.".format(str(ex)))
+
   default_cfg = {'agent': {'prefix': '/home/ambari'}}
   config.load(default_cfg)