From 777a26f492ab843d3c31e6dbbcf07589023d8a0c Mon Sep 17 00:00:00 2001 From: Erin of Yukis Date: Fri, 2 Jan 2026 10:15:25 +0000 Subject: [PATCH] Add systemd-compatible service manager notification after bewCloud has successfully started (#137) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add systemd-compatible service manager notification after bewCloud has successfully started * Use `systemd-notify` util instead of native integration while Deno APIs aren’t there yet * 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 * Remove unnecessary comments --------- Co-authored-by: Bruno Bernardino --- fresh.config.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fresh.config.ts b/fresh.config.ts index 8f0c2b0..19de787 100644 --- a/fresh.config.ts +++ b/fresh.config.ts @@ -5,8 +5,24 @@ import { startCrons } from '/crons/index.ts'; const isBuildMode = Deno.args.includes('build'); +async function notifyServiceManagerReady() { + const socketAddress = Deno.env.get('NOTIFY_SOCKET'); + if (typeof socketAddress !== 'string') { + return; + } + + 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})`); + } +} + if (!isBuildMode) { await startCrons(); + await notifyServiceManagerReady(); } export default defineConfig({