Skip to content
Source
Sign inSign up
Open History to see the last commit

legacyServerOwner.ts

29 lines1.0 KB

1// Effect-free so the service launcher shares the pre-lock owner identity check with server startup.
2​
3export const legacyOwnerStartTimeCommand = (pid: number, platform: NodeJS.Platform) => {
4 const windows = platform === "win32";
5 return {
6 command: windows ? "powershell.exe" : "ps",
7 args: windows
8 ? [
9 "-NoProfile",
10 "-NonInteractive",
11 "-Command",
12 `(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().ToString('o')`,
13 ]
14 : ["-p", String(pid), "-o", "lstart="],
15 env: { LC_ALL: "C", TZ: "UTC" },
16 };
17};
18​
19// ps reports whole seconds. Unknown identity (no output) stays conservative.
20export const legacyOwnerStartedBeforeRecord = (
21 output: string | undefined,
22 recordedAt: number,
23 platform: NodeJS.Platform,
24): boolean => {
25 if (output === undefined) return true;
26 const trimmed = output.trim();
27 const startedAt = Date.parse(platform === "win32" ? trimmed : `${trimmed} UTC`);
28 return !Number.isFinite(startedAt) || startedAt <= recordedAt + 1_000;
29};