Esempio n. 1
0
def run_server(args):
    logger.info('EdgeDB server starting.')

    pg_cluster_started_by_us = False

    if args['data_dir']:
        server_settings = {
            'log_connections': 'yes',
            'log_statement': 'all',
            'log_disconnections': 'yes',
            'log_min_messages': 'INFO',
        }

        if args['timezone']:
            server_settings['TimeZone'] = args['timezone']

        cluster = pg_cluster.Cluster(data_dir=args['data_dir'])
        cluster_status = cluster.get_status()

        if cluster_status == 'not-initialized':
            logger.info('Initializing database cluster in %s',
                        args['data_dir'])
            initdb_output = cluster.init(username='******')
            for line in initdb_output.splitlines():
                logger.debug('initdb: %s', line)
            cluster.reset_hba()
            cluster.add_hba_entry(type='local',
                                  database='all',
                                  user='******',
                                  auth_method='trust')
            cluster.add_hba_entry(type='local',
                                  address=ipaddress.ip_network('127.0.0.0/24'),
                                  database='all',
                                  user='******',
                                  auth_method='trust')

        cluster_status = cluster.get_status()

        if cluster_status == 'stopped':
            cluster.start(port=edgedb_cluster.find_available_port(),
                          server_settings=server_settings)
            pg_cluster_started_by_us = True

        elif cluster_status != 'running':
            abort('Could not start database cluster in %s', args['data_dir'])

        cluster.override_connection_spec(user='******', database='template1')

    else:
        cluster = pg_cluster.RunningCluster(dsn=args['postgres'])

    if args['bootstrap']:
        _init_cluster(cluster, args)
    else:
        _run_server(cluster, args)

    if pg_cluster_started_by_us:
        cluster.stop()
Esempio n. 2
0
 def _get_pg_cluster(self, data_dir, pg_config_path):
     return pg_cluster.Cluster(data_dir, pg_config_path=pg_config_path)
Esempio n. 3
0
def get_pg_cluster(data_dir: os.PathLike) -> pg_cluster.Cluster:
    pg_config = buildmeta.get_pg_config_path()
    return pg_cluster.Cluster(data_dir=data_dir, pg_config_path=str(pg_config))