| 567 | |
| 568 | let shuttingDown = false; |
| 569 | const shutdown = async (signal: NodeJS.Signals): Promise<void> => { |
| 570 | if (shuttingDown) return; |
| 571 | shuttingDown = true; |
| 572 | |
| 573 | try { |
| 574 | await http.close(); |
| 575 | } catch (error) { |
| 576 | console.error(error); |
| 577 | } |
| 578 | try { |
| 579 | runner.disposeAll(); |
| 580 | } catch (error) { |
| 581 | console.error(error); |
| 582 | } |
| 583 | |
| 584 | if (fuse !== undefined) { |
| 585 | await unmount(fuse); |
| 586 | } |
| 587 | if (upstreamClient !== undefined) { |
| 588 | try { |
| 589 | stopSync(); |
| 590 | await upstreamClient.close(); |
| 591 | } catch (error) { |
| 592 | console.error(error); |
| 593 | } |
| 594 | } |
| 595 | teardownLogging(); |
| 596 | process.exit(signal === "SIGINT" ? 130 : 143); |
| 597 | }; |
| 598 | |
| 599 | process.once("SIGINT", (signal) => void shutdown(signal)); |
| 600 | process.once("SIGTERM", (signal) => void shutdown(signal)); |