Beispiel #1
0
def start_process(parser_args):
    """ Start up specific daemon """
    import psutil
    import process_starter
    from system import process_helper

    try:
        pid = process_helper.get_process_pid(parser_args.process_name)
        if pid is not None:
            if psutil.pid_exists(pid):
                message = 'ERROR: Process {0} is already running with pid {1}\n'.format(
                    parser_args.process_name, pid)
                sys.stderr.write(message)
                sys.exit(1)

        if not parser_args.console:
            # this block triggers if the options.console is not defined or is False
            process_helper.start_process(parser_args.process_name,
                                         parser_args.extra_parameters)
        else:
            process_starter.start_by_process_name(parser_args.process_name,
                                                  parser_args.extra_parameters)
    except Exception as e:
        sys.stderr.write('Exception on starting {0} : {1}\n'.format(
            parser_args.process_name, e))
        traceback.print_exc(file=sys.stderr)
Beispiel #2
0
def start_process(parser_args):
    """ Start up specific daemon """
    import psutil
    import process_starter
    import settings
    from synergy.system import process_helper, utils

    utils.ensure_dir(settings.settings['pid_directory'])
    utils.ensure_dir(settings.settings['log_directory'])

    try:
        pid = process_helper.get_process_pid(parser_args.process_name)
        if pid is not None:
            if psutil.pid_exists(pid):
                message = f'ERROR: Process {parser_args.process_name} is already running with pid {pid}\n'
                sys.stderr.write(message)
                sys.exit(1)

        if not parser_args.console:
            # this block triggers if the options.console is not defined or is False
            process_helper.start_process(parser_args.process_name,
                                         parser_args.extra_parameters)
        else:
            process_starter.start_by_process_name(parser_args.process_name,
                                                  parser_args.extra_parameters)
    except Exception as e:
        sys.stderr.write(
            f'Exception on starting {parser_args.process_name} : {e}\n')
        traceback.print_exc(file=sys.stderr)
 def test_starting_method(self, mock_tracker, mock_consumer):
     """
     performance_ticker and Flopsy consumer must be mocked
     otherwise they will instantiate threads
     and cause Unit Tests to fail to finish
     """
     from tests.ut_context import PROCESS_CLASS_EXAMPLE
     process_starter.start_by_process_name(PROCESS_CLASS_EXAMPLE, None)
 def test_starting_method(self, mock_tracker):
     """
     performance_tracker must be mocked
     otherwise they will instantiate threads
     and prevent Unit Tests from finishing
     """
     from tests.ut_process_context import PROCESS_CLASS_EXAMPLE
     process_starter.start_by_process_name(PROCESS_CLASS_EXAMPLE, None)
 def test_starting_method(self, mock_tracker):
     """
     performance_tracker must be mocked
     otherwise they will instantiate threads
     and prevent Unit Tests from finishing
     """
     from tests.ut_process_context import PROCESS_CLASS_EXAMPLE
     process_starter.start_by_process_name(PROCESS_CLASS_EXAMPLE, None)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
def start_process(options, args):
    """Start up specific daemon """
    import psutil
    import process_starter
    from synergy.system import process_helper

    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)
Beispiel #9
0
def start_process(parser_args):
    """ Start up specific daemon """
    import psutil
    import process_starter
    from system import process_helper

    try:
        pid = process_helper.get_process_pid(parser_args.process_name)
        if pid is not None:
            if psutil.pid_exists(pid):
                message = 'ERROR: Process {0} is already running with pid {1}\n'.format(parser_args.process_name, pid)
                sys.stderr.write(message)
                sys.exit(1)

        if not parser_args.console:
            # this block triggers if the options.console is not defined or is False
            process_helper.start_process(parser_args.process_name, parser_args.extra_parameters)
        else:
            process_starter.start_by_process_name(parser_args.process_name, parser_args.extra_parameters)
    except Exception as e:
        sys.stderr.write('Exception on starting {0} : {1}\n'.format(parser_args.process_name, e))
        traceback.print_exc(file=sys.stderr)
 def test_starting_function(self):
     from tests.ut_context import PROCESS_SCRIPT_EXAMPLE
     process_starter.start_by_process_name(PROCESS_SCRIPT_EXAMPLE, 'parameters')
 def test_starting_function(self):
     from tests.ut_process_context import PROCESS_SCRIPT_EXAMPLE
     process_starter.start_by_process_name(PROCESS_SCRIPT_EXAMPLE,
                                           'parameters')