From fbd7527cf48aeeff30b5d4dd9096e33ea704cc8e Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 20 May 2026 19:55:40 +0800 Subject: [PATCH] Stop hub cleanly from CLI command --- cli/src/commands/hub.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/src/commands/hub.ts b/cli/src/commands/hub.ts index b702cc86..454f516b 100644 --- a/cli/src/commands/hub.ts +++ b/cli/src/commands/hub.ts @@ -34,7 +34,21 @@ export const hubCommand: CommandDefinition = { process.env.HAPI_LISTEN_PORT = port } const { startHub } = await import('hapi-hub/startHub') - await startHub({ args: context.commandArgs }) + const hub = await startHub({ args: context.commandArgs }) + let shuttingDown = false + const shutdown = async () => { + if (shuttingDown) { + return + } + shuttingDown = true + process.off('SIGINT', shutdown) + process.off('SIGTERM', shutdown) + console.log('\nShutting down...') + await hub.stop() + process.exit(0) + } + process.on('SIGINT', shutdown) + process.on('SIGTERM', shutdown) await new Promise(() => {}) } catch (error) { console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error')