Exemplo n.º 1
0
def stop_process(options):
    """Stop the synergy-data daemons"""
    import logging
    from supervisor import supervisor_helper as helper
    from model.box_configuration_entry import BoxConfigurationEntry

    if options.app is not None and options.app != process_context.PROCESS_SUPERVISOR:
        # mark individual process for termination
        # real work is performed by Supervisor
        if options.app not in PROCESSES_FOR_XXL:
            sys.stdout.write("ERROR: requested process must be withing allowed list of: %r \n" % PROCESSES_FOR_XXL)
            sys.exit(1)

        box_id = helper.get_box_id(logging)
        box_configuration = helper.retrieve_configuration(logging, box_id)
        box_configuration.set_process_state(options.app, BoxConfigurationEntry.STATE_OFF)
        helper.update_configuration(logging, box_configuration)
    else:
        # stop Supervisor
        try:
            pid = _get_supervisor_pid()
            if pid is None:
                message = "ERROR: Can not find Supervisor pidfile. Supervisor not running?\n"
                sys.stderr.write(message)
                sys.exit(1)

            # Try killing the daemon process
            sys.stdout.write("INFO: Killing %r \n" % process_context.PROCESS_SUPERVISOR)
            while 1:
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)
            ProcessContext.remove_pid_file(process_context.PROCESS_SUPERVISOR)
        except Exception as e:
            sys.stderr.write("Exception on killing %s : %s \n" % (process_context.PROCESS_SUPERVISOR, str(e)))
            sys.exit(0)
Exemplo n.º 2
0
def stop_process(options):
    """Stop specific daemon"""
    from system import process_helper
    from supervisor import supervisor_helper as helper
    from system.process_context import ProcessContext
    from supervisor.supervisor_constants import PROCESS_SUPERVISOR
    from constants import PROCESS_LAUNCH_PY

    logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
    box_id = helper.get_box_id(logger)
    if options.supervisor is True and options.app != PROCESS_SUPERVISOR:
        from db.model import box_configuration
        from db.dao.box_configuration_dao import BoxConfigurationDao

        message = 'INFO: Marking %r to be managed by Supervisor \n' % options.app
        sys.stdout.write(message)

        bc_dao = BoxConfigurationDao(logger)
        box_config = bc_dao.get_one(box_id)
        box_config.set_process_state(options.app, box_configuration.STATE_OFF)
        bc_dao.update(box_config)
        return
    try:
        pid = process_helper.get_process_pid(options.app)
        if pid is None or process_helper.poll_process(options.app) is False:
            message = 'ERROR: Process %r is already terminated %r\n' % (options.app, pid)
            sys.stderr.write(message)
            sys.exit(1)

        process_helper.kill_process(options.app)
    except Exception as e:
        sys.stderr.write('Exception on killing %s : %s \n' % (options.app, str(e)))
        traceback.print_exc(file=sys.stderr)
Exemplo n.º 3
0
def query_configuration(options):
    """ Queries process state """
    from system import process_helper

    if not options.supervisor:
        # reads status of one process only
        process_helper.poll_process(options.app)
    else:
        # reads current box configuration and prints it to the console
        from db.dao.box_configuration_dao import BoxConfigurationDao
        from supervisor import supervisor_helper as helper
        from system.process_context import ProcessContext
        from constants import PROCESS_LAUNCH_PY

        logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
        box_id = helper.get_box_id(logger)
        bc_dao = BoxConfigurationDao(logger)
        sys.stdout.write('\nConfiguration for BOX_ID=%r:\n' % box_id)
        box_configuration = bc_dao.get_one(box_id)
        process_list = box_configuration.get_process_list()
        i = 1
        for process in process_list:
            sys.stdout.write('%d\t%r:%r \n' % (i, process, process_list[process]))
            i += 1
        sys.stdout.write('\n')
Exemplo n.º 4
0
def stop_process(options):
    """Stop specific daemon"""
    from system import process_helper
    from supervisor import supervisor_helper as helper
    from system.process_context import ProcessContext
    from supervisor.supervisor_constants import PROCESS_SUPERVISOR
    from constants import PROCESS_LAUNCH_PY

    logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
    box_id = helper.get_box_id(logger)
    if options.supervisor is True and options.app != PROCESS_SUPERVISOR:
        from db.model import box_configuration
        from db.dao.box_configuration_dao import BoxConfigurationDao

        message = 'INFO: Marking %r to be managed by Supervisor \n' % options.app
        sys.stdout.write(message)

        bc_dao = BoxConfigurationDao(logger)
        box_config = bc_dao.get_one(box_id)
        box_config.set_process_state(options.app, box_configuration.STATE_OFF)
        bc_dao.update(box_config)
        return
    try:
        pid = process_helper.get_process_pid(options.app)
        if pid is None or process_helper.poll_process(options.app) is False:
            message = 'ERROR: Process %r is already terminated %r\n' % (
                options.app, pid)
            sys.stderr.write(message)
            sys.exit(1)

        process_helper.kill_process(options.app)
    except Exception as e:
        sys.stderr.write('Exception on killing %s : %s \n' %
                         (options.app, str(e)))
        traceback.print_exc(file=sys.stderr)
Exemplo n.º 5
0
def query_configuration(options):
    """ Queries process state """
    from system import process_helper

    if not options.supervisor:
        # reads status of one process only
        process_helper.poll_process(options.app)
    else:
        # reads current box configuration and prints it to the console
        from db.dao.box_configuration_dao import BoxConfigurationDao
        from supervisor import supervisor_helper as helper
        from system.process_context import ProcessContext
        from constants import PROCESS_LAUNCH_PY

        logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
        box_id = helper.get_box_id(logger)
        bc_dao = BoxConfigurationDao(logger)
        sys.stdout.write('\nConfiguration for BOX_ID=%r:\n' % box_id)
        box_configuration = bc_dao.get_one(box_id)
        process_list = box_configuration.get_process_list()
        i = 1
        for process in process_list:
            sys.stdout.write('%d\t%r:%r \n' %
                             (i, process, process_list[process]))
            i += 1
        sys.stdout.write('\n')
Exemplo n.º 6
0
 def __init__(self, process_name):
     super(Supervisor, self).__init__(process_name)
     self.pid = os.getpid()
     self.thread_handlers = dict()
     self.lock = Lock()
     self.box_id = supervisor_helper.get_box_id(self.logger)
     self.bc_dao = BoxConfigurationDao(self.logger)
     self.logger.info('Started %s with configuration for BOX_ID=%r' % (self.process_name, self.box_id))
Exemplo n.º 7
0
def query_configuration(options):
    """ reads current box configuration and prints it to the console """
    import logging
    from supervisor import supervisor_helper as helper

    box_id = helper.get_box_id(logging)
    sys.stdout.write("\nConfiguration for BOX_ID=%r:\n" % box_id)
    box_configuration = helper.retrieve_configuration(logging, box_id)
    process_list = box_configuration.get_process_list()
    i = 1
    for process in process_list:
        sys.stdout.write("%d\t%r:%r \n" % (i, process, process_list[process]))
        i += 1
    sys.stdout.write("\n")
Exemplo n.º 8
0
def start_process(options, daemonize):
    """Start up supervisor and proper synergy-data daemons"""
    import logging
    import psutil
    from settings import settings
    from supervisor import supervisor_helper as helper
    from model.box_configuration_entry import BoxConfigurationEntry

    box_id = helper.get_box_id(logging)
    if options.app is not None and options.app != process_context.PROCESS_SUPERVISOR:
        # mark individual process for execution
        # real work is performed by Supervisor
        if options.app not in PROCESSES_FOR_XXL:
            sys.stdout.write("ERROR: requested process must be withing allowed list of: %r \n" % PROCESSES_FOR_XXL)
            sys.exit(1)

        box_configuration = helper.retrieve_configuration(logging, box_id)
        box_configuration.set_process_state(options.app, BoxConfigurationEntry.STATE_ON)
        helper.update_configuration(logging, box_configuration)
    else:
        # start Supervisor
        try:
            pid = _get_supervisor_pid()
            if pid is not None:
                if psutil.pid_exists(pid):
                    message = "ERROR: Supervisor is already running with pid %r\n" % pid
                    sys.stderr.write(message)
                    sys.exit(1)

            p = psutil.Popen(
                [get_python(), PROJECT_ROOT + "/" + PROCESS_STARTER, process_context.PROCESS_SUPERVISOR],
                close_fds=True,
                cwd=settings["process_cwd"],
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
            )
            sys.stdout.write(
                "Started %s with pid = %r with configuration for BOX_ID=%r \n"
                % (process_context.PROCESS_SUPERVISOR, p.pid, box_id)
            )
        except Exception as e:
            sys.stderr.write("Exception on starting %s : %s \n" % (process_context.PROCESS_SUPERVISOR, str(e)))
Exemplo n.º 9
0
def start_process(options, args):
    """Start up specific daemon """
    import psutil
    from system import process_helper
    from supervisor import supervisor_helper as helper
    from system.process_context import ProcessContext
    from supervisor.supervisor_constants import PROCESS_SUPERVISOR
    from constants import PROCESS_LAUNCH_PY

    logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
    box_id = helper.get_box_id(logger)
    if options.supervisor is True and options.app != PROCESS_SUPERVISOR:
        from db.model import box_configuration
        from db.dao.box_configuration_dao import BoxConfigurationDao

        message = 'INFO: Marking %r to be managed by Supervisor \n' % options.app
        sys.stdout.write(message)

        bc_dao = BoxConfigurationDao(logger)
        box_config = bc_dao.get_one(box_id)
        box_config.set_process_state(options.app, box_configuration.STATE_ON)
        bc_dao.update(box_config)
        return

    try:
        pid = process_helper.get_process_pid(options.app)
        if pid is not None:
            if psutil.pid_exists(pid):
                message = 'ERROR: Process %r is already running with pid %r\n' % (
                    options.app, pid)
                sys.stderr.write(message)
                sys.exit(1)

        if not options.interactive:
            # this block triggers if the options.interactive is not defined or is False
            process_helper.start_process(options.app, args)
        else:
            process_starter.start_by_process_name(options.app, args)
    except Exception as e:
        sys.stderr.write('Exception on starting %s : %s \n' %
                         (options.app, str(e)))
        traceback.print_exc(file=sys.stderr)
Exemplo n.º 10
0
def start_process(options, args):
    """Start up specific daemon """
    import psutil
    from system import process_helper
    from supervisor import supervisor_helper as helper
    from system.process_context import ProcessContext
    from supervisor.supervisor_constants import PROCESS_SUPERVISOR
    from constants import PROCESS_LAUNCH_PY

    logger = ProcessContext.get_logger(PROCESS_LAUNCH_PY)
    box_id = helper.get_box_id(logger)
    if options.supervisor is True and options.app != PROCESS_SUPERVISOR:
        from db.model import box_configuration
        from db.dao.box_configuration_dao import BoxConfigurationDao

        message = 'INFO: Marking %r to be managed by Supervisor \n' % options.app
        sys.stdout.write(message)

        bc_dao = BoxConfigurationDao(logger)
        box_config = bc_dao.get_one(box_id)
        box_config.set_process_state(options.app, box_configuration.STATE_ON)
        bc_dao.update(box_config)
        return

    try:
        pid = process_helper.get_process_pid(options.app)
        if pid is not None:
            if psutil.pid_exists(pid):
                message = 'ERROR: Process %r is already running with pid %r\n' % (options.app, pid)
                sys.stderr.write(message)
                sys.exit(1)

        if not options.interactive:
            # this block triggers if the options.interactive is not defined or is False
            process_helper.start_process(options.app, args)
        else:
            process_starter.start_by_process_name(options.app, args)
    except Exception as e:
        sys.stderr.write('Exception on starting %s : %s \n' % (options.app, str(e)))
        traceback.print_exc(file=sys.stderr)