fix: 修正 Monitor status 就绪退出语义
This commit is contained in:
@@ -372,8 +372,11 @@ async function monitorCommand(config: UniDeskConfig, action: string, options: Pl
|
||||
const script = action === "status" ? monitorStatusScript(pg, target) : monitorResetScript(pg, target);
|
||||
const capture = await runSshCommandCapture(config, pg.node.route, ["sh"], script);
|
||||
const parsed = parseJsonOutput(capture.stdout);
|
||||
const commandOk = action === "status"
|
||||
? monitorStatusSucceeded(capture.exitCode, parsed)
|
||||
: capture.exitCode === 0 && parsed?.ok === true;
|
||||
return {
|
||||
ok: capture.exitCode === 0 && parsed?.ok === true,
|
||||
ok: commandOk,
|
||||
...base,
|
||||
mutation: action === "reset",
|
||||
...(action === "reset" ? { confirmed: true } : {}),
|
||||
@@ -382,6 +385,10 @@ async function monitorCommand(config: UniDeskConfig, action: string, options: Pl
|
||||
};
|
||||
}
|
||||
|
||||
export function monitorStatusSucceeded(exitCode: number, parsed: Record<string, unknown> | null): boolean {
|
||||
return exitCode === 0 && parsed?.ok === true && parsed.ready === true;
|
||||
}
|
||||
|
||||
function unsupported(args: string[]): Record<string, unknown> {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -1105,7 +1112,8 @@ fi
|
||||
empty=false
|
||||
ready=false
|
||||
if [ "$schema_ready" = true ] && [ "$business_rows" = "0" ]; then empty=true; ready=true; fi
|
||||
printf '{"ok":true,"databaseExists":%s,"schemaReady":%s,"empty":%s,"ready":%s,"databaseOid":"%s","schemaVersion":"%s","businessRows":%s,"siblingDatabaseOids":"%s"}\n' "$([ -n "$database_oid" ] && printf true || printf false)" "$schema_ready" "$empty" "$ready" "$database_oid" "$schema_version_observed" "$([ -n "$business_rows" ] && printf '%s' "$business_rows" || printf null)" "$sibling_oids"
|
||||
printf '{"ok":%s,"databaseExists":%s,"schemaReady":%s,"empty":%s,"ready":%s,"databaseOid":"%s","schemaVersion":"%s","businessRows":%s,"siblingDatabaseOids":"%s"}\n' "$ready" "$([ -n "$database_oid" ] && printf true || printf false)" "$schema_ready" "$empty" "$ready" "$database_oid" "$schema_version_observed" "$([ -n "$business_rows" ] && printf '%s' "$business_rows" || printf null)" "$sibling_oids"
|
||||
if [ "$ready" != true ]; then exit 1; fi
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user