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

legacyServerOwner.ts

34 lines1.1 KB

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