From 0dbb4ddd2b8073ac716e7a57a5280a8278d0d56a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 22 Apr 2024 19:56:05 +0200 Subject: taler-wallet-cli: clean up socket --- packages/taler-wallet-cli/src/index.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 1cceb8446..59be964b2 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -1210,7 +1210,26 @@ advancedCli help: "Do not initialize the wallet. The client must send the initWallet message.", }) .action(async (args) => { - logger.info(`serving at ${args.serve.unixPath}`); + const socketPath = args.serve.unixPath; + logger.info(`serving at ${socketPath}`); + let cleanupCalled = false; + + const cleanupSocket = (signal: string, code: number) => { + if (cleanupCalled) { + return; + } + cleanupCalled = true; + try { + logger.info("cleaning up socket"); + fs.unlinkSync(socketPath); + } catch (e) { + logger.warn(`unable to clean up socket: ${e}`); + } + process.exit(128 + code); + }; + process.on("SIGTERM", cleanupSocket); + process.on("SIGINT", cleanupSocket); + const onNotif = (notif: WalletNotification) => { if (observabilityEventFile) { switch (notif.type) { -- cgit v1.2.3