fix: something

This commit is contained in:
hibna
2026-08-02 20:26:54 +03:00
parent 5215560ede
commit 11924416a9
38 changed files with 2198 additions and 466 deletions
+39 -3
View File
@@ -25,6 +25,9 @@ export interface DaemonCreateServerRequest {
environment: Record<string, string>;
ports: DaemonPortMapping[];
install_plugin_urls: string[];
data_path: string;
stop_command: string;
stop_timeout_seconds: number;
}
export interface DaemonUpdateServerRequest {
@@ -36,6 +39,16 @@ export interface DaemonUpdateServerRequest {
startup_command: string;
environment: Record<string, string>;
ports: DaemonPortMapping[];
data_path: string;
stop_command: string;
stop_timeout_seconds: number;
}
export interface DaemonPowerOptions {
/** In-game shutdown command; lets the daemon skip the SIGTERM wait entirely. */
stopCommand?: string | null;
/** Total graceful-shutdown budget in seconds. */
stopTimeoutSeconds?: number | null;
}
interface DaemonServerResponse {
@@ -216,7 +229,12 @@ interface DaemonServiceClient extends grpc.Client {
callback: UnaryCallback<EmptyResponse>,
): void;
setPowerState(
request: { uuid: string; action: number },
request: {
uuid: string;
action: number;
stop_command: string;
stop_timeout_seconds: number;
},
metadata: grpc.Metadata,
callback: UnaryCallback<EmptyResponse>,
): void;
@@ -437,6 +455,7 @@ function toBuffer(data: Uint8Array | Buffer): Buffer {
const DEFAULT_CONNECT_TIMEOUT_MS = 8_000;
const DEFAULT_RPC_TIMEOUT_MS = 20_000;
const POWER_RPC_TIMEOUT_MS = 45_000;
const MAX_POWER_RPC_TIMEOUT_MS = 360_000;
interface DaemonRequestTimeoutOptions {
connectTimeoutMs?: number;
@@ -641,18 +660,35 @@ export async function daemonSetPowerState(
node: DaemonNodeConnection,
serverUuid: string,
action: PowerAction,
options: DaemonPowerOptions = {},
): Promise<void> {
const stopTimeoutSeconds = Number(options.stopTimeoutSeconds) > 0
? Math.floor(Number(options.stopTimeoutSeconds))
: 0;
// The daemon waits out the shutdown before replying, so the RPC deadline has
// to outlive the game's own budget (ARK saves its world for minutes).
const rpcTimeoutMs =
action === 'stop' || action === 'restart'
? Math.min(Math.max((stopTimeoutSeconds + 20) * 1_000, POWER_RPC_TIMEOUT_MS), MAX_POWER_RPC_TIMEOUT_MS)
: POWER_RPC_TIMEOUT_MS;
const client = createClient(node);
try {
await waitForReady(client, DEFAULT_CONNECT_TIMEOUT_MS);
await callUnary<EmptyResponse>(
(callback) =>
client.setPowerState(
{ uuid: serverUuid, action: POWER_ACTIONS[action] },
{
uuid: serverUuid,
action: POWER_ACTIONS[action],
stop_command: options.stopCommand?.trim() ?? '',
stop_timeout_seconds: stopTimeoutSeconds,
},
getMetadata(node.daemonToken),
callback,
),
POWER_RPC_TIMEOUT_MS,
rpcTimeoutMs,
);
} finally {
client.close();