Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Feb 23, 2025
1 parent b8eae3e commit fd76051
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class Controller {
}

async stop(restart = false): Promise<void> {
this.sdNotify?.stopping();
this.sdNotify?.notifyStopping();

// Call extensions
await this.callExtensions('stop', this.extensions);
Expand Down
10 changes: 4 additions & 6 deletions lib/util/sd-notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import logger from './logger';
* Handle sd_notify protocol, @see https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
* No-op if running on unsupported platforms or without Type=notify
*/
export async function initSdNotify(): Promise<{stopping: () => void; stop: () => void} | undefined> {
export async function initSdNotify(): Promise<{notifyStopping: () => void; stop: () => void} | undefined> {
if (!process.env.NOTIFY_SOCKET) {
return;
}
Expand All @@ -23,7 +23,7 @@ export async function initSdNotify(): Promise<{stopping: () => void; stop: () =>
}
});
};
const stopping = (): void => sendToSystemd('STOPPING=1');
const notifyStopping = (): void => sendToSystemd('STOPPING=1');

sendToSystemd('READY=1');

Expand All @@ -34,7 +34,7 @@ export async function initSdNotify(): Promise<{stopping: () => void; stop: () =>
const watchdogInterval = setInterval(() => sendToSystemd('WATCHDOG=1'), wdUSec / 1000 / 2);

return {
stopping,
notifyStopping,
stop: (): void => clearInterval(watchdogInterval),
};
}
Expand All @@ -44,15 +44,13 @@ export async function initSdNotify(): Promise<{stopping: () => void; stop: () =>
}

return {
stopping,
notifyStopping,
stop: (): void => {},
};
} catch (error) {
console.log('1');
// Ignore error on Windows if not running on WSL, as UNIX sockets don't exist on Windows.
// Unlikely that NOTIFY_SOCKET is set anyways but better be safe.
if (platform() !== 'win32' || process.env.WSL_DISTRO_NAME) {
console.log('2');
throw error;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/sd-notify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('sd-notify', () => {

await vi.advanceTimersByTimeAsync(7500);

res!.stopping();
res!.notifyStopping();
expect(mockUnixDgramSocket.send).toHaveBeenCalledTimes(2);
expectSocketNthSend(2, 'STOPPING=1');

Expand All @@ -116,7 +116,7 @@ describe('sd-notify', () => {

await vi.advanceTimersByTimeAsync(7500);

res!.stopping();
res!.notifyStopping();
expect(mockUnixDgramSocket.send).toHaveBeenCalledTimes(2);
expectSocketNthSend(2, 'STOPPING=1');

Expand All @@ -137,7 +137,7 @@ describe('sd-notify', () => {
expect(mockUnixDgramSocket.send).toHaveBeenCalledTimes(2);
expectSocketNthSend(2, 'WATCHDOG=1');

res!.stopping();
res!.notifyStopping();
expect(mockUnixDgramSocket.send).toHaveBeenCalledTimes(3);
expectSocketNthSend(3, 'STOPPING=1');

Expand Down

0 comments on commit fd76051

Please sign in to comment.