Beispiel #1
0
    def start_component(self,
                        py_path,
                        name,
                        program_dir,
                        on_keyboard_interrupt=None):
        """ Starts a component in background or foreground, depending on the 'fg' flag.
        """

        # Zato
        from zato.common.util.proc import start_python_process

        start_python_process(name,
                             self.args.fg,
                             py_path,
                             program_dir,
                             on_keyboard_interrupt,
                             self.SYS_ERROR.FAILED_TO_START, {
                                 'sync_internal': self.args.sync_internal,
                                 'secret_key': self.args.secret_key or '',
                                 'stderr_path': self.args.stderr_path,
                             },
                             stderr_path=self.args.stderr_path,
                             stdin_data=self.stdin_data)

        if self.show_output:
            if not self.args.fg and self.verbose:
                self.logger.debug('Zato {} `{}` starting in background'.format(
                    name, self.component_dir))
            else:
                self.logger.info('OK')
Beispiel #2
0
    def start_connector(self, ipc_tcp_start_port, timeout=5):
        """ Starts an HTTP server acting as an connector process. Its port will be greater than ipc_tcp_start_port,
        which is the starting point to find a free port from.
        """
        if self.check_enabled:
            self._check_enabled()

        self.ipc_tcp_port = get_free_port(ipc_tcp_start_port)
        logger.info('Starting {} connector for server `%s` on `%s`'.format(self.connector_name),
            self.server.name, self.ipc_tcp_port)

        # Credentials for both servers and connectors
        username, password = self.get_credentials()

        # Employ IPC to exchange subprocess startup configuration
        self.server.connector_config_ipc.set_config(self.ipc_config_name, dumps({
            'port': self.ipc_tcp_port,
            'username': username,
            'password': password,
            'server_port': self.server.port,
            'server_name': self.server.name,
            'server_path': '/zato/internal/callback/{}'.format(self.callback_suffix),
            'base_dir': self.server.base_dir,
            'needs_pidfile': not self.server.has_fg,
            'pidfile_suffix': self.pidfile_suffix,
            'logging_conf_path': self.server.logging_conf_path
        }))

        # Start connector in a sub-process
        start_python_process('{} connector'.format(self.connector_name), False, self.connector_module, '', extra_options={
            'deployment_key': self.server.deployment_key,
            'shmem_size': self.server.shmem_size
        })

        # Wait up to timeout seconds for the connector to start as indicated by its responding to a PING request
        now = datetime.utcnow()
        warn_after = now + timedelta(seconds=3)
        should_warn = False
        until = now + timedelta(seconds=timeout)
        is_ok = False
        address = address_pattern.format(self.ipc_tcp_port, 'ping')
        auth = self.get_credentials()

        while not is_ok or now >= until:
            if not should_warn:
                if now >= warn_after:
                    should_warn = True
            is_ok = self._ping_connector(address, auth, should_warn)
            if is_ok:
                break
            else:
                sleep(2)
                now = datetime.utcnow()

        if not is_ok:
            logger.warn('{} connector (%s) could not be started after %s'.format(self.connector_name), address, timeout)
        else:
            return is_ok
Beispiel #3
0
    def start_websphere_mq_connector(self, ipc_tcp_start_port, timeout=5):
        """ Starts an HTTP server acting as an IBM MQ MQ connector. Its port will be greater than ipc_tcp_start_port,
        which is the starting point to find a free port from.
        """
        self.wmq_ipc_tcp_port = get_free_port(ipc_tcp_start_port)
        logger.info('Starting IBM MQ connector for server `%s` on `%s`',
                    self.wmq_ipc_tcp_port, self.name)

        # Credentials for both servers and connectors
        username, password = self.get_wmq_credentials()

        # User kernel's facilities to store configuration
        self.keyutils.user_set(
            b'zato-wmq',
            dumps({
                'port': self.wmq_ipc_tcp_port,
                'username': username,
                'password': password,
                'server_port': self.port,
                'server_name': self.name,
                'server_path': '/zato/internal/callback/wmq',
                'base_dir': self.base_dir,
                'logging_conf_path': self.logging_conf_path
            }), self.pid)

        # Start IBM MQ connector in a sub-process
        start_python_process(False,
                             'zato.server.connection.jms_wmq.jms.container',
                             'IBM MQ connector', '')

        # Wait up to timeout seconds for the connector to start as indicated by its responding to a PING request
        now = datetime.utcnow()
        until = timedelta(seconds=timeout)
        is_ok = False
        address = address_pattern.format(self.wmq_ipc_tcp_port, 'ping')
        auth = self.get_wmq_credentials()

        while not is_ok or now >= until:
            is_ok = self._ping_connector(address, auth)
            if is_ok:
                break
            else:
                sleep(0.2)
                now = datetime.utcnow()

        if not is_ok:
            logger.warn('IBM MQ connector (%s) could not be started after %s',
                        address, timeout)
        else:
            return is_ok