Пример #1
0
    def execute(self):
        """
        :return:
        """
        if not self.valid_embattle:
            return False

        # has been for some prerequisite check for corps operation
        if self.is_embattled:
            console.warning("Agent was initialized before.")
            return False

        with self._inspect_lock:

            if self.is_embattled:
                console.warning('agent was initialized before, skip it now.')
                return False

            log_bootstrap("Stating init agent environment %s." %
                          self._settings)
            self.is_embattled = True

            try:
                self.inspect_prerequisites()
                self.activate_weapons()
            except Exception as err:
                console.error("Errors. when initial the agent system. %s", err)
                return False

            return True
Пример #2
0
    def __init__(self, config_file):
        """
        :param config_file:
        :return:
        """
        self.config_file = config_file
        self.is_embattled = False
        self.valid_embattle = True
        self._config_parser = ConfigParser.RawConfigParser()
        self._settings = global_settings()
        self._inspect_lock = threading.Lock()

        if not config_file:
            self.config_file = os.environ.get(ENV_CONFIG_FILE, None)

        if not self.config_file:
            log_bootstrap(
                'Agent config file is not found, agent start failed.')
            self.valid_embattle = False

        log_bootstrap("get config file %s" % self.config_file)
Пример #3
0
    def inspect_prerequisites(self):
        """ Do some prerequisite check for corps operation
        :return:
        """
        log_bootstrap("Inspecting config file %s" % self.config_file,
                      close=True)

        if not self._config_parser.read(self.config_file):
            raise ConfigurationError("Unable to access the config file. %s",
                                     self.config_file)

        self._settings.config_file = self.config_file
        self.load_settings()
        self.load_settings('tingyun:exclude', "plugins")
        self.load_settings('tingyun:private', "port")
        self.load_settings('tingyun:private', "host")
        self.load_settings('tingyun:proxy', "proxy_host")
        self.load_settings('tingyun:proxy', "proxy_port")
        self.load_settings('tingyun:proxy', "proxy_user")
        self.load_settings('tingyun:proxy', "proxy_pwd")
        self.load_settings('tingyun:proxy', "proxy_scheme")

        # we can not access the log file and log level from the config parser. it maybe empty.
        initialize_logging(self._settings.log_file, self._settings.log_level)
import os
import sys
import imp

from tingyun.config.start_log import log_bootstrap
from tingyun.logistics.mapper import ENV_CONFIG_FILE

log_bootstrap('Ting Yun Bootstrap = %s' % __file__)
log_bootstrap('working_directory = %r' % os.getcwd())

# manual load the customize module, just avoid the python module system return something cached when pythonpath changed
boot_directory = os.path.dirname(__file__)
root_directory = os.path.dirname(boot_directory)
log_bootstrap("root dir is: %s" % boot_directory)

path = list(sys.path)
if boot_directory in path:
    del path[path.index(boot_directory)]

# load the other sitecustomize module, which defined in other packages.
try:
    (filename, pathname, description) = imp.find_module('sitecustomize', path)
except ImportError:
    pass
else:
    imp.load_module('sitecustomize', filename, pathname, description)

config_file = os.environ.get(ENV_CONFIG_FILE, None)
log_bootstrap("get config  %s" % config_file, close=True)

if config_file is None: