backend-app-api: move signal handlers to backend initializer + exit

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-31 17:58:58 +01:00
parent 90616df9a8
commit ab22515647
3 changed files with 18 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-app-api': patch
---
The shutdown signal handlers are now installed as part of the backend instance rather than the lifecycle service, and explicitly cause the process to exit.
@@ -22,11 +22,8 @@ import {
LoggerService,
} from '@backstage/backend-plugin-api';
const CALLBACKS = ['SIGTERM', 'SIGINT', 'beforeExit'];
export class BackendLifecycleImpl implements RootLifecycleService {
constructor(private readonly logger: LoggerService) {
CALLBACKS.map(signal => process.on(signal, () => this.shutdown()));
}
constructor(private readonly logger: LoggerService) {}
#isCalled = false;
#shutdownTasks: Array<LifecycleServiceShutdownHook> = [];
@@ -87,6 +87,18 @@ export class BackendInitializer {
}
this.#started = true;
for (const event of ['SIGTERM', 'SIGINT', 'beforeExit']) {
process.on(event, async () => {
try {
await this.stop();
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
});
}
// Initialize all root scoped services
for (const ref of this.#serviceHolder.getServiceRefs()) {
if (ref.scope === 'root') {