def main(heartbeat_stop_callback=None): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), options.verbose) global is_logger_setup is_logger_setup = True setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), options.verbose) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Add syslog hanlder based on ambari config file add_syslog_handler(logger) # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_hostname = hostname.server_hostname(config) server_url = config.get_api_url() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until server is reachable netutil = NetUtil(heartbeat_stop_callback) retries, connected = netutil.try_to_connect(server_url, -1, logger) # Ambari Agent was stopped using stop event if connected: # Launch Controller communication controller = Controller(config, heartbeat_stop_callback) controller.start() controller.join() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: ExitHelper.execute_cleanup() stop_agent() logger.info("finished")
def get_api_url(self): return "%s://%s:%s" % (self.CONNECTION_PROTOCOL, hostname.server_hostname(self), self.get('server', 'url_port'))
def get_api_url(self): return "%s://%s:%s" % (self.CONNECTION_PROTOCOL, hostname.server_hostname(self), self.get('server', 'url_port'))
def __init__(self, config): self.config = config self.keysdir = os.path.abspath(self.config.get('security', 'keysdir')) self.server_crt = self.config.get('security', 'server_crt') self.server_url = 'https://' + hostname.server_hostname(config) + ':' \ + self.config.get('server', 'url_port')
def __init__(self, config): self.connected = False self.config = config self.server = hostname.server_hostname(config) self.port = config.get('server', 'secured_url_port') self.connect()
def main(heartbeat_stop_callback=None): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname current_user = getpass.getuser() logging_level = logging.DEBUG if options.verbose else logging.INFO setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), logging_level) setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level) Logger.initialize_logger('resource_management', logging_level=logging_level) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) bind_signal_handlers(agentPid) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Add syslog hanlder based on ambari config file add_syslog_handler(logger) # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_hostname = hostname.server_hostname(config) server_url = config.get_api_url() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until server is reachable netutil = NetUtil(heartbeat_stop_callback) retries, connected = netutil.try_to_connect(server_url, -1, logger) # Ambari Agent was stopped using stop event if connected: # Launch Controller communication controller = Controller(config, heartbeat_stop_callback) controller.start() controller.join() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: ExitHelper.execute_cleanup() stop_agent() logger.info("finished")