Ejemplo n.º 1
0
    def _on_server(self, show_output=True, *ignored):

        server_conf = ConfigObj(os.path.join(self.config_dir, 'repo', 'server.conf'))
        port = server_conf['main']['gunicorn_bind'].split(':')[1]
        server_prefix = '{0}'.format(port).zfill(5)

        socket_name = 'server-{0}.sock'.format(server_prefix)
        socket_name = os.path.join(self.config_dir, 'zdaemon', socket_name)

        # If we have a socket of that name then we already have a running
        # server, in which case we refrain from starting new processes now.
        if os.path.exists(socket_name):
            msg = 'Server at {0} is already running'.format(self.component_dir)
            self.logger.debug(msg)
            return self.SYS_ERROR.COMPONENT_ALREADY_RUNNING

        zdaemon_conf_name = 'zdaemon-{0}.conf'.format(port)
        socket_prefix = 'server-{0}'.format(port)
        program = '{} -m zato.server.main {}'.format(get_executable(), self.component_dir)
        logfile_path_prefix = 'zdaemon-{}'.format(port)

        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix,
                            logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato server at {0} has been started'.format(self.component_dir))
            else:
                self.logger.info('OK')
Ejemplo n.º 2
0
def start_connector(repo_location, file_, env_item_name, def_id, item_id):
    """ Starts a new connector process.
    """
    
    # Believe it or not but this is the only sane way to make connector subprocesses 
    # work as of now (15 XI 2011).
    
    # Subprocesses spawned in a shell need to use
    # the wrapper which sets up the PYTHONPATH instead of the regular Python
    # executable, because the executable may not have all the dependencies required.
    # Of course, this needs to be squared away before Zato gets into any Linux 
    # distribution but then the situation will be much simpler as we simply won't 
    # have to patch up anything, the distro will take care of any dependencies.
    executable = get_executable()
    
    if file_[-1] in('c', 'o'): # Need to use the source code file
        file_ = file_[:-1]
    
    program = '{0} {1}'.format(executable, file_)
    
    zato_env = {}
    zato_env['ZATO_REPO_LOCATION'] = repo_location
    if def_id:
        zato_env['ZATO_CONNECTOR_DEF_ID'] = str(def_id)
    zato_env[env_item_name] = str(item_id)
    
    _env = os.environ
    _env.update(zato_env)
    
    Popen(program, close_fds=True, shell=True, env=_env)
Ejemplo n.º 3
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.
        """
        tmp_path = mkstemp('-zato-start-{}.txt'.format(name.replace(' ','')))[1]
        stdout_redirect = '' if self.args.fg else '1> /dev/null'
        stderr_redirect = '2> {}'.format(tmp_path)
        program = '{} -m {} {} {} {}'.format(get_executable(), py_path, program_dir, stdout_redirect, stderr_redirect)
        try:
            _stderr = _StdErr(
                tmp_path, stderr_sleep_fg if self.args.fg else stderr_sleep_bg)

            run(program, async=False if self.args.fg else True)

            # Wait a moment for any potential errors
            _err = _stderr.wait_for_error()
            if _err:
                self.logger.warn(_err)
                sys.exit(self.SYS_ERROR.FAILED_TO_START)

        except KeyboardInterrupt:
            if on_keyboard_interrupt:
                on_keyboard_interrupt()
            sys.exit(0)

        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')
Ejemplo n.º 4
0
Archivo: start.py Proyecto: dsuch/zato
    def _on_server(self, show_output=True, *ignored):

        server_conf = ConfigObj(os.path.join(self.config_dir, 'repo', 'server.conf'))
        port = server_conf['main']['gunicorn_bind'].split(':')[1]
        server_prefix = '{0}'.format(port).zfill(5)

        socket_name = 'server-{0}.sock'.format(server_prefix)
        socket_name = os.path.join(self.config_dir, 'zdaemon', socket_name)

        # If we have a socket of that name then we already have a running
        # server, in which case we refrain from starting new processes now.
        if os.path.exists(socket_name):
            msg = 'Server at {0} is already running'.format(self.component_dir)
            self.logger.debug(msg)
            return self.SYS_ERROR.COMPONENT_ALREADY_RUNNING

        zdaemon_conf_name = 'zdaemon-{0}.conf'.format(port)
        socket_prefix = 'server-{0}'.format(port)
        program = '{} -m zato.server.main {}'.format(get_executable(), self.component_dir)
        logfile_path_prefix = 'zdaemon-{}'.format(port)

        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix,
                            logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato server at {0} has been started'.format(self.component_dir))
            else:
                self.logger.info('OK')
Ejemplo n.º 5
0
def start_connector(repo_location, file_, env_item_name, def_id, item_id):
    """ Starts a new connector process.
    """

    # Believe it or not but this is the only sane way to make connector subprocesses
    # work as of now (15 XI 2011).

    # Subprocesses spawned in a shell need to use
    # the wrapper which sets up the PYTHONPATH instead of the regular Python
    # executable, because the executable may not have all the dependencies required.
    # Of course, this needs to be squared away before Zato gets into any Linux
    # distribution but then the situation will be much simpler as we simply won't
    # have to patch up anything, the distro will take care of any dependencies.
    executable = get_executable()

    if file_[-1] in ('c', 'o'):  # Need to use the source code file
        file_ = file_[:-1]

    program = '{0} {1}'.format(executable, file_)

    zato_env = {}
    zato_env['ZATO_REPO_LOCATION'] = repo_location
    if def_id:
        zato_env['ZATO_CONNECTOR_DEF_ID'] = str(def_id)
    zato_env[env_item_name] = str(item_id)

    _env = os.environ
    _env.update(zato_env)

    Popen(program, close_fds=True, shell=True, env=_env)
Ejemplo n.º 6
0
    def _on_server(self, show_output=True, *ignored):

        server_conf = ConfigObj(os.path.join(self.config_dir, "repo", "server.conf"))
        port = server_conf["main"]["gunicorn_bind"].split(":")[1]
        server_prefix = "{0}".format(port).zfill(5)

        socket_name = "server-{0}.sock".format(server_prefix)
        socket_name = os.path.join(self.config_dir, "zdaemon", socket_name)

        # If we have a socket of that name then we already have a running
        # server, in which case we refrain from starting new processes now.
        if os.path.exists(socket_name):
            msg = "Server at {0} is already running".format(self.component_dir)
            self.logger.debug(msg)
            return self.SYS_ERROR.COMPONENT_ALREADY_RUNNING

        zdaemon_conf_name = "zdaemon-{0}.conf".format(port)
        socket_prefix = "server-{0}".format(port)
        program = "{} -m zato.server.main {}".format(get_executable(), self.component_dir)
        logfile_path_prefix = "zdaemon-{}".format(port)

        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug("Zato server at {0} has been started".format(self.component_dir))
            else:
                self.logger.info("OK")
Ejemplo n.º 7
0
    def _on_web_admin(self, *ignored):

        zdaemon_conf_name = 'zdaemon-web-admin.conf'
        socket_prefix = 'web-admin'
        program = '{} -m zato.admin.main'.format(get_executable())
        logfile_path_prefix = 'zdaemon-web-admin'
        
        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato web admin started in {0}'.format(self.component_dir))
            else:
                self.logger.info('OK')
Ejemplo n.º 8
0
Archivo: start.py Proyecto: dsuch/zato
    def _on_zato_admin(self, *ignored):

        zdaemon_conf_name = 'zdaemon-zato-admin.conf'
        socket_prefix = 'zato-admin'
        program = '{} -m zato.admin.main'.format(get_executable())
        logfile_path_prefix = 'zdaemon-zato-admin'
        
        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato admin started in {0}'.format(self.component_dir))
            else:
                self.logger.info('OK')
Ejemplo n.º 9
0
    def _on_web_admin(self, *ignored):

        zdaemon_conf_name = "zdaemon-web-admin.conf"
        socket_prefix = "web-admin"
        program = "{} -m zato.admin.main".format(get_executable())
        logfile_path_prefix = "zdaemon-web-admin"

        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        if self.show_output:
            if self.verbose:
                self.logger.debug("Zato web admin started in {0}".format(self.component_dir))
            else:
                self.logger.info("OK")
Ejemplo n.º 10
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.
        """
        program = '{} -m {} {} {}'.format(get_executable(), py_path, program_dir, ('' if self.args.fg else '2>&1 >/dev/null'))
        try:
            run(program, async=False if self.args.fg else True)
        except KeyboardInterrupt:
            if on_keyboard_interrupt:
                on_keyboard_interrupt()
            sys.exit(0)

        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')
Ejemplo n.º 11
0
Archivo: start.py Proyecto: znavy/zato
    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.
        """
        tmp_path = mkstemp('-zato-start-{}.txt'.format(name.replace(' ',
                                                                    '')))[1]
        stdout_redirect = '' if self.args.fg else '1> /dev/null'
        stderr_redirect = '2> {}'.format(tmp_path)

        options = {
            'sync_internal': self.args.sync_internal,
            'fg': self.args.fg,
        }
        options = CLI_ARG_SEP.join('{}={}'.format(k, v)
                                   for k, v in options.items())

        program = '{} -m {} {} {} {} {}'.format(get_executable(), py_path,
                                                program_dir, options,
                                                stdout_redirect,
                                                stderr_redirect)
        try:
            _stderr = _StdErr(
                tmp_path, stderr_sleep_fg if self.args.fg else stderr_sleep_bg)
            run(program, async=False if self.args.fg else True)

            # Wait a moment for any potential errors
            _err = _stderr.wait_for_error()
            if _err:
                self.logger.warn(_err)
                sys.exit(self.SYS_ERROR.FAILED_TO_START)

        except KeyboardInterrupt:
            if on_keyboard_interrupt:
                on_keyboard_interrupt()
            sys.exit(0)

        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')
Ejemplo n.º 12
0
    def _on_lb(self, *ignored):

        # Start the agent which will in turn start the load balancer
        repo_dir = os.path.join(self.config_dir, 'repo')

        zdaemon_conf_name = 'zdaemon-lb.conf'
        socket_prefix = 'lb-agent'
        program = '{} -m zato.agent.load_balancer.main {}'.format(get_executable(), repo_dir)
        logfile_path_prefix = 'zdaemon-lb-agent'
        
        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        # Now start HAProxy

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato load balancer and agent started in {0}'.format(self.component_dir))
            else:
                self.logger.info('OK')
Ejemplo n.º 13
0
Archivo: start.py Proyecto: dsuch/zato
    def _on_lb(self, *ignored):

        # Start the agent which will in turn start the load balancer
        repo_dir = os.path.join(self.config_dir, 'repo')

        zdaemon_conf_name = 'zdaemon-lb.conf'
        socket_prefix = 'lb-agent'
        program = '{} -m zato.agent.load_balancer.main {}'.format(get_executable(), repo_dir)
        logfile_path_prefix = 'zdaemon-lb-agent'
        
        self._zdaemon_start(zdaemon_conf_name_contents, zdaemon_conf_name, socket_prefix, logfile_path_prefix, program)

        # Now start HAProxy

        if self.show_output:
            if self.verbose:
                self.logger.debug('Zato load balancer and agent started in {0}'.format(self.component_dir))
            else:
                self.logger.info('OK')