From fbee0f3774baf5b29082e6ad227fb10370f41da9 Mon Sep 17 00:00:00 2001 From: Bruno Bernardino Date: Fri, 2 Jan 2026 10:13:27 +0000 Subject: [PATCH] Implement different approach for systemd-notification reporting I went with a slightly different option, given I was struggling to lose a lot of flexibility in the original listening log (because it's started with some server state parameters) or allow so much unnecessary/duplicate complexity from Fresh in `fresh.config.ts` because I'll probably eventually ditch it (given #99). Some relevant references in the original `fresh` code: - https://github.com/denoland/fresh/blob/ab14d1044c04051dae96828100ad6d50aa45e2ad/docs/1.x/concepts/server-configuration.md?plain=1#L207-L208 - https://github.com/denoland/fresh/blob/d9764e20055c2a972074c86907d8cc674b27dabc/src/server/config.ts#L95 - https://github.com/denoland/fresh/blob/d9764e20055c2a972074c86907d8cc674b27dabc/src/server/mod.ts#L115-L118 - https://github.com/denoland/fresh/blob/d9764e20055c2a972074c86907d8cc674b27dabc/src/server/boot.ts#L52-L57 --- fresh.config.ts | 57 +++++++++---------------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/fresh.config.ts b/fresh.config.ts index 77de016..02af8cd 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -5,64 +5,27 @@ import { startCrons } from '/crons/index.ts'; const isBuildMode = Deno.args.includes('build'); -if (!isBuildMode) { - await startCrons(); -} - -async function notifyServiceManagerReady(message) { - const socketAddress = Deno.env.get("NOTIFY_SOCKET"); - if (typeof(socketAddress) !== "string") { - return; // Service manager doesn’t expect any messages +async function notifyServiceManagerReady() { + const socketAddress = Deno.env.get('NOTIFY_SOCKET'); + if (typeof socketAddress !== 'string') { + return; // Service manager doesn’t expect any messages } // 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", " ")}`] + const result = await (new Deno.Command('systemd-notify', { + args: ['--ready', `MESSAGE=bewCloud is ready`], })).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)}`; - } else if (socketAddress[0] !== "/") { - throw `Invalid NOTIFY_SOCKET address format: ${socketAddress}`; - } - - // Send message to service manager - // - // 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(); - */ +if (!isBuildMode) { + await startCrons(); + await notifyServiceManagerReady(); } export default defineConfig({ plugins: [tailwind()], - server: { - onListen: (params) => { - // Format listening address - const fmtHostPort = (hostname, port) => - hostname.includes(":") ? `[${hostname}]:${port}` : `${hostname}:${port}`; - - const addr = ( - params.transport === "unix" ? `http+unix://${encodeURIComponent(params.path)}` : - params.transport === "vsock" ? `http+vsock://${params.cid}:${parms.port}` : - params.transport === "tcp" ? `http://${fmtHostPort(params.hostname, params.port)}/` : null - ); - - const message = "bewCloud listening for requests" + (addr ? ` on ${addr}` : ""); - console.info(message); - notifyServiceManagerReady(message); - }, - }, });