From addaf3af62e5bcfd36f315d5066382f87a1df425 Mon Sep 17 00:00:00 2001 From: Erin of Yukis Date: Sun, 28 Dec 2025 03:16:34 +0100 Subject: [PATCH] =?UTF-8?q?Use=20`systemd-notify`=20util=20instead=20of=20?= =?UTF-8?q?native=20integration=20while=20Deno=20APIs=20aren=E2=80=99t=20t?= =?UTF-8?q?here=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fresh.config.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fresh.config.ts b/fresh.config.ts index 5490310..77de016 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -1,4 +1,3 @@ -import { tmpdir } from 'node:os'; import { defineConfig } from 'fresh/server.ts'; import tailwind from 'fresh/plugins/tailwind.ts'; @@ -16,11 +15,16 @@ async function notifyServiceManagerReady(message) { return; // Service manager doesn’t expect any messages } - // Alternative using systemd CLI (systemd specific, requires CLI utils in $PATH) - /*await (new Deno.Command("systemd-notify", { + // Send message using `systemd-notify` util until the native Deno APIs become stable + const result = await (new Deno.Command("systemd-notify", { args: ["--ready", `MESSAGE=${message.replace("\n", " ")}`] - })).spawn();*/ + })).output(); + if (!result.success) { + const output = new TextDecoder().decode(result.stderr); + throw new Deno.errors.NotCapable(`Failed to execute “systemd-notify”: ${output} (code ${result.code})`); + } + /* // Map socket path syntax if (socketAddress[0] === "@") { socketAddress = `\0${socketAddress.slice(1)}`; @@ -30,15 +34,16 @@ async function notifyServiceManagerReady(message) { // Send message to service manager // - // Passing a valid `path` here is required, even though it is not used (Deno bug/limitation). - const senderAddress = `${tmpdir()}/bewcloud-notify-${crypto.randomUUID()}.sock`; - const connection = Deno.listenDatagram({ transport: "unixpacket", path: senderAddress }); - await Deno.remove(senderAddress); + // Blockers: + // * https://github.com/denoland/deno/pull/31681 + // * Deno stabilization of `Deno.listenDatagram` (`--unstable-net`) + const connection = Deno.listenDatagram({ transport: "unixpacket" }); await connection.send( new TextEncoder().encode(`READY=1\nSTATUS=${message.replace("\n", " ")}`), { transport: "unixpacket", path: socketAddress } ); await connection.close(); + */ } export default defineConfig({