Destroy the database cluster when its bootstrap fails
Remove the database cluster directory when the boostrap fails,
rather than Rather than keep it around half-initialized.
@@ -127,8 +127,10 @@ def run_server(args):
else:
logger.info('EdgeDB server starting.')
+ pg_cluster_init_by_us = False
pg_cluster_started_by_us = False
+ try:
if args['data_dir']:
server_settings = {
'log_connections': 'yes',
@@ -162,6 +164,7 @@ def run_server(args):
database='all', user='all',
auth_method='trust'
)
+ pg_cluster_init_by_us = True
cluster_status = cluster.get_status()
@@ -172,7 +175,8 @@ def run_server(args):
pg_cluster_started_by_us = True
elif cluster_status != 'running':
- abort('Could not start database cluster in %s', args['data_dir'])
+ abort('Could not start database cluster in %s',
+ args['data_dir'])
cluster.override_connection_spec(
user='postgres', database='template1')
@@ -185,6 +189,15 @@ def run_server(args):
else:
_run_server(cluster, args)
+ except BaseException as e:
+ if pg_cluster_init_by_us:
+ logger.warning('server bootstrap did not complete successfully, '
+ 'removing the data directory')
+ if cluster.get_status() == 'running':
+ cluster.stop()
+ cluster.destroy()
+ raise
+
if pg_cluster_started_by_us:
cluster.stop()
