Пример #1
0
def server_main(*, insecure=False, **kwargs):
    logsetup.setup_logging(kwargs['log_level'], kwargs['log_to'])
    exceptions.install_excepthook()

    bump_rlimit_nofile()

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    if kwargs['devmode'] is not None:
        devmode.enable_dev_mode(kwargs['devmode'])

    server_args = srvargs.parse_args(insecure=insecure, **kwargs)

    if kwargs['background']:
        daemon_opts = {'detach_process': True}
        pidfile = kwargs['pidfile_dir'] / f".s.EDGEDB.{kwargs['port']}.lock"
        daemon_opts['pidfile'] = pidfile
        if kwargs['daemon_user']:
            daemon_opts['uid'] = kwargs['daemon_user']
        if kwargs['daemon_group']:
            daemon_opts['gid'] = kwargs['daemon_group']
        with daemon.DaemonContext(**daemon_opts):
            run_server(server_args, setproctitle=True)
    else:
        with devmode.CoverageConfig.enable_coverage_if_requested():
            run_server(server_args)
Пример #2
0
def server_main(*, insecure=False, **kwargs):

    logsetup.setup_logging(kwargs['log_level'], kwargs['log_to'])
    exceptions.install_excepthook()

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    if kwargs['devmode'] is not None:
        devmode.enable_dev_mode(kwargs['devmode'])

    if not kwargs['data_dir']:
        if devmode.is_in_dev_mode():
            kwargs['data_dir'] = os.path.expanduser('~/.edgedb')
        else:
            abort('Please specify the instance data directory '
                  'using the -D argument')

    kwargs['insecure'] = insecure

    if kwargs['background']:
        daemon_opts = {'detach_process': True}
        pidfile = os.path.join(kwargs['pidfile'],
                               '.s.EDGEDB.{}.lock'.format(kwargs['port']))
        daemon_opts['pidfile'] = pidfile
        if kwargs['daemon_user']:
            daemon_opts['uid'] = kwargs['daemon_user']
        if kwargs['daemon_group']:
            daemon_opts['gid'] = kwargs['daemon_group']
        with daemon.DaemonContext(**daemon_opts):
            setproctitle.setproctitle('edgedb-server-{}'.format(
                kwargs['port']))
            run_server(kwargs)
    else:
        with devmode.CoverageConfig.enable_coverage_if_requested():
            run_server(kwargs)
Пример #3
0
def server_main(**kwargs):
    exceptions.install_excepthook()

    bump_rlimit_nofile()

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    if kwargs['devmode'] is not None:
        devmode.enable_dev_mode(kwargs['devmode'])

    try:
        server_args = srvargs.parse_args(**kwargs)
    except srvargs.InvalidUsageError as e:
        abort(e.args[0], exit_code=e.args[1])

    if kwargs['background']:
        daemon_opts = {'detach_process': True}
        pidfile = kwargs['pidfile_dir'] / f".s.EDGEDB.{kwargs['port']}.lock"
        daemon_opts['pidfile'] = pidfile
        if kwargs['daemon_user']:
            daemon_opts['uid'] = kwargs['daemon_user']
        if kwargs['daemon_group']:
            daemon_opts['gid'] = kwargs['daemon_group']
        with daemon.DaemonContext(**daemon_opts):
            asyncio.run(run_server(server_args, setproctitle=True))
    else:
        with devmode.CoverageConfig.enable_coverage_if_requested():
            asyncio.run(run_server(server_args))
Пример #4
0
def server_main(*, insecure=False, **kwargs):
    logsetup.setup_logging(kwargs['log_level'], kwargs['log_to'])
    exceptions.install_excepthook()

    bump_rlimit_nofile()

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    if kwargs['devmode'] is not None:
        devmode.enable_dev_mode(kwargs['devmode'])

    if kwargs['temp_dir']:
        if kwargs['bootstrap']:
            abort('--temp-data-dir is incompatible with --bootstrap')
        if kwargs['data_dir']:
            abort('--temp-data-dir is incompatible with --data-dir/-D')
        if kwargs['runstate_dir']:
            abort('--temp-data-dir is incompatible with --runstate-dir')
        if kwargs['postgres_dsn']:
            abort('--temp-data-dir is incompatible with --postgres-dsn')
        kwargs['data_dir'] = kwargs['runstate_dir'] = pathlib.Path(
            tempfile.mkdtemp())
    else:
        if not kwargs['data_dir']:
            if kwargs['postgres_dsn']:
                pass
            elif devmode.is_in_dev_mode():
                kwargs['data_dir'] = os.path.expanduser('~/.edgedb')
            else:
                abort('Please specify the instance data directory '
                      'using the -D argument or the address of a remote '
                      'PostgreSQL cluster using the --postgres-dsn argument')
        elif kwargs['postgres_dsn']:
            abort('The -D and --postgres-dsn options are mutually exclusive.')

    kwargs['insecure'] = insecure

    if kwargs['background']:
        daemon_opts = {'detach_process': True}
        pidfile = kwargs['pidfile_dir'] / f".s.EDGEDB.{kwargs['port']}.lock"
        daemon_opts['pidfile'] = pidfile
        if kwargs['daemon_user']:
            daemon_opts['uid'] = kwargs['daemon_user']
        if kwargs['daemon_group']:
            daemon_opts['gid'] = kwargs['daemon_group']
        with daemon.DaemonContext(**daemon_opts):
            # TODO: setproctitle should probably be moved to where
            # management port is initialized, as that's where we know
            # the actual network port we listen on.  At this point
            # "port" can be "None".
            setproctitle.setproctitle(f"edgedb-server-{kwargs['port']}")

            run_server(ServerConfig(**kwargs))
    else:
        with devmode.CoverageConfig.enable_coverage_if_requested():
            run_server(ServerConfig(**kwargs))