def __init__(self, core_client): log.debug('Core: Initializing...') super(Core, self).__init__() self.core_client = core_client self.process = None # core binary should be in ../core. Typically this happens since the cli # will be in /opt/meocloud/cli while the core will be in /opt/meocloud/core core_binary_dir = os.path.normpath( os.path.join(get_own_dir(__file__), '..', 'core')) self.core_binary_path = os.path.join(core_binary_dir, CORE_BINARY_FILENAME) self.core_env = os.environ.copy() self.core_env['CLD_CORE_SOCKET_PATH'] = DAEMON_LISTENER_SOCKET_ADDRESS self.core_env['CLD_UI_SOCKET_PATH'] = CORE_LISTENER_SOCKET_ADDRESS try: if sys.getfilesystemencoding().lower() != 'utf-8': if 'C.UTF-8' in check_output(['locale', '-a']).splitlines(): log.info('Forcing locale to C.UTF-8') self.core_env['LC_ALL'] = 'C.UTF-8' else: log.info('Forcing locale to en_US.utf8') self.core_env['LC_ALL'] = 'en_US.utf8' except Exception: log.exception( 'Something went wrong while trying to fix set the LC_ALL env variable' )
def _get_current_version(): if not DEV_MODE: own_dir = get_own_dir(__file__) version_path = os.path.join(own_dir, 'VERSION') with open(version_path) as f: current_version = f.read().strip() else: current_version = '0.0.0 dev' return current_version
def __init__(self, core_client): log.debug('Core: Initializing...') super(Core, self).__init__() self.core_client = core_client self.process = None # assumes core binary is in same dir as daemon core_binary_dir = get_own_dir(__file__) self.core_binary_path = os.path.join(core_binary_dir, CORE_BINARY_FILENAME) self.core_env = os.environ.copy() self.core_env['CLD_CORE_SOCKET_PATH'] = DAEMON_LISTENER_SOCKET_ADDRESS self.core_env['CLD_UI_SOCKET_PATH'] = CORE_LISTENER_SOCKET_ADDRESS if sys.getfilesystemencoding().lower() != 'utf-8': self.core_env['LC_ALL'] = 'C.UTF-8'
def _start_daemon(self): pid = self._daemon_already_running() if pid: if self._core_already_running(): raise AlreadyRunningException(pid) else: log.warning('CLIHandler._start_daemon: Core is not running and we don\'t know why. ' 'Just in case, we\'ll stop the daemon too and continue as if nothing happened.') self.stop(quiet=True) self._handle_dying_message() log.info('Starting daemon') # assumes daemon binary is in same dir as cli daemon_binary_dir = get_own_dir(__file__) daemon_binary_path = os.path.join(daemon_binary_dir, DAEMON_BINARY_FILENAME) self.process = Popen([daemon_binary_path], preexec_fn=lambda: os.setpgrp()) # Try pinging daemon to make sure the listener is on self.daemon_client.attemptFirstConnection()
def check_own_version(log): if not DEV_MODE: own_dir = get_own_dir(__file__) version_path = os.path.join(own_dir, "VERSION") restart_script_path = os.path.join(own_dir, "restart_meocloud.sh") try: while True: gevent.sleep(DAEMON_VERSION_CHECKER_PERIOD) with open(version_path) as f: current_version = f.read().strip() if current_version != VERSION: log.info("There seems to have been an update and nobody told us. Will now restart!") Popen(restart_script_path, close_fds=True) gevent.sleep(10) log.error("We should have been restarted, why are we still here?!") Events.shutdown_required.set() except IOError: log.exception("check_own_version error")
def _start_daemon(self): pid = self._daemon_already_running() if pid: if self._core_already_running(): raise AlreadyRunningException(pid) else: log.warning( 'CLIHandler._start_daemon: Core is not running and we don\'t know why. ' 'Just in case, we\'ll stop the daemon too and continue as if nothing happened.' ) self.stop(quiet=True) self._handle_dying_message() log.info('Starting daemon') # assumes daemon binary is in same dir as cli daemon_binary_dir = get_own_dir(__file__) daemon_binary_path = os.path.join(daemon_binary_dir, DAEMON_BINARY_FILENAME) self.process = Popen([daemon_binary_path], preexec_fn=lambda: os.setpgrp()) # Try pinging daemon to make sure the listener is on self.daemon_client.attemptFirstConnection()
def check_own_version(log): if not DEV_MODE: own_dir = get_own_dir(__file__) version_path = os.path.join(own_dir, 'VERSION') restart_script_path = os.path.join(own_dir, 'restart_meocloud.sh') try: while True: gevent.sleep(DAEMON_VERSION_CHECKER_PERIOD) with open(version_path) as f: current_version = f.read().strip() if current_version != VERSION: log.info( 'There seems to have been an update and nobody told us. Will now restart!' ) Popen(restart_script_path, close_fds=True) gevent.sleep(10) log.error( 'We should have been restarted, why are we still here?!' ) Events.shutdown_required.set() except IOError: log.exception('check_own_version error')
def __init__(self, core_client): log.debug('Core: Initializing...') super(Core, self).__init__() self.core_client = core_client self.process = None # core binary should be in ../core. Typically this happens since the cli # will be in /opt/meocloud/cli while the core will be in /opt/meocloud/core core_binary_dir = os.path.normpath(os.path.join(get_own_dir(__file__), '..', 'core')) self.core_binary_path = os.path.join(core_binary_dir, CORE_BINARY_FILENAME) self.core_env = os.environ.copy() self.core_env['CLD_CORE_SOCKET_PATH'] = DAEMON_LISTENER_SOCKET_ADDRESS self.core_env['CLD_UI_SOCKET_PATH'] = CORE_LISTENER_SOCKET_ADDRESS try: if sys.getfilesystemencoding().lower() != 'utf-8': if 'C.UTF-8' in check_output(['locale', '-a']).splitlines(): log.info('Forcing locale to C.UTF-8') self.core_env['LC_ALL'] = 'C.UTF-8' else: log.info('Forcing locale to en_US.utf8') self.core_env['LC_ALL'] = 'en_US.utf8' except Exception: log.exception('Something went wrong while trying to fix set the LC_ALL env variable')