backend-app-api: move signal handlers to backend initializer + exit
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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.
|
||||
+1
-4
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user