home-hosted 0.9.9 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +75 -1
- package/README.md +13 -0
- package/dist/cli.js +541 -233
- package/dist/cli.js.map +1 -1
- package/docs/RESTORE_DEMO.md +45 -12
- package/docs/SERVERS.md +23 -2
- package/package.json +1 -1
- package/uis/stock/dist/assets/{de-Cf0vh5VW.js → de-BP4HfMC9.js} +1 -1
- package/uis/stock/dist/assets/{es-DvlrGqi4.js → es-Cehmpy7G.js} +1 -1
- package/uis/stock/dist/assets/{fr-CRZwjDEG.js → fr-DN3eC8Ey.js} +1 -1
- package/uis/stock/dist/assets/{index-BkfQL_xe.js → index-CB6K3K2b.js} +12 -12
- package/uis/stock/dist/assets/{ja-DtLbY1Wl.js → ja-CYAuNjfG.js} +1 -1
- package/uis/stock/dist/assets/{ko-D0_fMO0J.js → ko-wQEmDRMK.js} +1 -1
- package/uis/stock/dist/assets/{ru-DQOEnxXc.js → ru-BtbhojJ0.js} +1 -1
- package/uis/stock/dist/assets/{vi-nanLxe06.js → vi-BfUCVFk_.js} +1 -1
- package/uis/stock/dist/assets/{zh-CN-M5LvmyF0.js → zh-CN-DEhi0m5s.js} +1 -1
- package/uis/stock/dist/index.html +1 -1
- package/uis/stock/dist/ui.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -2249,6 +2249,46 @@ function writeFileAtomic(file, content, options = {}) {
|
|
|
2249
2249
|
}
|
|
2250
2250
|
var init_atomic = __esmMin((() => {}));
|
|
2251
2251
|
//#endregion
|
|
2252
|
+
//#region src/helpers/config-text.ts
|
|
2253
|
+
/**
|
|
2254
|
+
* Decodes a hand-editable state file the way the editors that write them save it.
|
|
2255
|
+
*
|
|
2256
|
+
* Every file the panel invites a person to hand-edit is JSON, and `JSON.parse` refuses a
|
|
2257
|
+
* **byte-order mark**: PowerShell's `Set-Content -Encoding UTF8` (5.1) and `Out-File`/`>`
|
|
2258
|
+
* (UTF-16LE) both prepend one, and Notepad writes one for a "UTF-8 with BOM" save. The
|
|
2259
|
+
* refusal is a parse error naming an invisible character — `Unexpected token '\uFEFF'` — so the
|
|
2260
|
+
* person is told their JSON is broken when it is not, and is invited to
|
|
2261
|
+
* fix a file the editor will re-encode identically on the next save.
|
|
2262
|
+
*
|
|
2263
|
+
* Stripping the mark is not a silent coercion: a BOM is not content, and a file whose real
|
|
2264
|
+
* content is unchanged parses to the same object with or without it. UTF-16 is decoded rather
|
|
2265
|
+
* than refused because that is what `>` produces on Windows, and it is recognisable from its
|
|
2266
|
+
* own prefix — a wrong guess would still fail loudly on `JSON.parse`.
|
|
2267
|
+
*
|
|
2268
|
+
* Read as a `Buffer`, never with `'utf8'`: a `'utf8'` read of UTF-16LE text has already lost
|
|
2269
|
+
* the information this needs to tell them apart.
|
|
2270
|
+
*/
|
|
2271
|
+
function decodeStateFile(bytes) {
|
|
2272
|
+
if (bytes.length >= 2) {
|
|
2273
|
+
if (bytes[0] === 255 && bytes[1] === 254) return stripBom(bytes.subarray(2).toString("utf16le"));
|
|
2274
|
+
if (bytes[0] === 254 && bytes[1] === 255) {
|
|
2275
|
+
const swapped = Buffer$1.from(bytes.subarray(2));
|
|
2276
|
+
swapped.swap16();
|
|
2277
|
+
return stripBom(swapped.toString("utf16le"));
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return stripBom(bytes.toString("utf8"));
|
|
2281
|
+
}
|
|
2282
|
+
/** A UTF-8 BOM is three bytes; Node decodes it to the one `\uFEFF` character. */
|
|
2283
|
+
function stripBom(text) {
|
|
2284
|
+
return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
|
|
2285
|
+
}
|
|
2286
|
+
/** `decodeStateFile` for a path. Missing files still throw `ENOENT`, as a caller expects. */
|
|
2287
|
+
function readStateFile(file) {
|
|
2288
|
+
return decodeStateFile(fs.readFileSync(file));
|
|
2289
|
+
}
|
|
2290
|
+
var init_config_text = __esmMin((() => {}));
|
|
2291
|
+
//#endregion
|
|
2252
2292
|
//#region src/shared/shape.ts
|
|
2253
2293
|
/**
|
|
2254
2294
|
* A plain object, and nothing else: not `null`, and not an array.
|
|
@@ -2431,6 +2471,7 @@ function openDdns(accountId, sealed, key) {
|
|
|
2431
2471
|
var COST, KEYLEN, SALT_BYTES, LEGACY_TELEGRAM_ID, DDNS_KEYLEN, DDNS_IV_BYTES, DDNS_AAD_PREFIX, DDNS_SEALED_ALGO, API_TOKEN_BYTES, API_TOKEN_HINT_CHARS, SecretsStore;
|
|
2432
2472
|
var init_secrets = __esmMin((() => {
|
|
2433
2473
|
init_atomic();
|
|
2474
|
+
init_config_text();
|
|
2434
2475
|
init_logger();
|
|
2435
2476
|
init_error_message();
|
|
2436
2477
|
init_shape();
|
|
@@ -2693,7 +2734,7 @@ var init_secrets = __esmMin((() => {
|
|
|
2693
2734
|
if (!fs.existsSync(this.file)) return this.inScope(empty);
|
|
2694
2735
|
let text;
|
|
2695
2736
|
try {
|
|
2696
|
-
text =
|
|
2737
|
+
text = readStateFile(this.file);
|
|
2697
2738
|
} catch (error) {
|
|
2698
2739
|
this.error = `cannot read ${this.file}: ${errorMessage(error)}`;
|
|
2699
2740
|
return this.inScope(empty);
|
|
@@ -3987,6 +4028,7 @@ var workspacesFileSchema, WorkspaceError, seed, WorkspaceRegistry;
|
|
|
3987
4028
|
var init_workspaces = __esmMin((() => {
|
|
3988
4029
|
init_schema();
|
|
3989
4030
|
init_atomic();
|
|
4031
|
+
init_config_text();
|
|
3990
4032
|
init_paths();
|
|
3991
4033
|
init_version();
|
|
3992
4034
|
init_contracts();
|
|
@@ -4042,7 +4084,7 @@ var init_workspaces = __esmMin((() => {
|
|
|
4042
4084
|
load() {
|
|
4043
4085
|
let parsed;
|
|
4044
4086
|
try {
|
|
4045
|
-
parsed = JSON.parse(
|
|
4087
|
+
parsed = JSON.parse(readStateFile(this.file));
|
|
4046
4088
|
} catch (error) {
|
|
4047
4089
|
if (error.code === "ENOENT") {
|
|
4048
4090
|
this.commit(seed());
|
|
@@ -4840,6 +4882,7 @@ var init_settings$1 = __esmMin((() => {
|
|
|
4840
4882
|
init_schema();
|
|
4841
4883
|
init_seed();
|
|
4842
4884
|
init_atomic();
|
|
4885
|
+
init_config_text();
|
|
4843
4886
|
init_paths();
|
|
4844
4887
|
ConfigError = class extends Error {
|
|
4845
4888
|
name = "ConfigError";
|
|
@@ -4915,7 +4958,7 @@ var init_settings$1 = __esmMin((() => {
|
|
|
4915
4958
|
reloadFromDisk() {
|
|
4916
4959
|
let text;
|
|
4917
4960
|
try {
|
|
4918
|
-
text =
|
|
4961
|
+
text = readStateFile(this.file);
|
|
4919
4962
|
} catch {
|
|
4920
4963
|
this.error = `${path.basename(this.file)} is gone`;
|
|
4921
4964
|
return {
|
|
@@ -4956,7 +4999,7 @@ var init_settings$1 = __esmMin((() => {
|
|
|
4956
4999
|
let text;
|
|
4957
5000
|
let parsed;
|
|
4958
5001
|
try {
|
|
4959
|
-
text =
|
|
5002
|
+
text = readStateFile(this.file);
|
|
4960
5003
|
parsed = JSON.parse(text);
|
|
4961
5004
|
} catch (error) {
|
|
4962
5005
|
this.error = `cannot parse ${path.basename(this.file)}: ${error.message}`;
|
|
@@ -6729,7 +6772,7 @@ var init_webhook = __esmMin((() => {
|
|
|
6729
6772
|
function readFile(file) {
|
|
6730
6773
|
let text;
|
|
6731
6774
|
try {
|
|
6732
|
-
text =
|
|
6775
|
+
text = readStateFile(file);
|
|
6733
6776
|
} catch (error) {
|
|
6734
6777
|
if (error.code === "ENOENT") return {
|
|
6735
6778
|
text: null,
|
|
@@ -6769,6 +6812,7 @@ var init_store = __esmMin((() => {
|
|
|
6769
6812
|
init_seed();
|
|
6770
6813
|
init_settings$1();
|
|
6771
6814
|
init_atomic();
|
|
6815
|
+
init_config_text();
|
|
6772
6816
|
init_ddns$2();
|
|
6773
6817
|
init_webhook();
|
|
6774
6818
|
init_contracts();
|
|
@@ -6838,8 +6882,26 @@ var init_store = __esmMin((() => {
|
|
|
6838
6882
|
get configSchemaVersion() {
|
|
6839
6883
|
return Math.max(this.settingsSchemaVersion, this.serversSchemaVersion);
|
|
6840
6884
|
}
|
|
6885
|
+
/**
|
|
6886
|
+
* The steps a workspace's files need, counting **both** sides.
|
|
6887
|
+
*
|
|
6888
|
+
* The two files are stamped independently — a person may hand-write `servers.config.json`
|
|
6889
|
+
* (which is unstamped, and so reads as schema 1) beside a `settings.json` the panel wrote at
|
|
6890
|
+
* the current schema. `configSchemaVersion` answers `max()` because that is the shape *this
|
|
6891
|
+
* release* understands of the pair, but the migrations that have to run belong to the **older**
|
|
6892
|
+
* file: `planConfigMigrations` is monotonic, so the lower version is the one with steps.
|
|
6893
|
+
* Reading `max()` here reported *no* pending migration while the reader was refusing the file
|
|
6894
|
+
* for needing one, which left the startup branch that says `run migrate` unreachable and sent
|
|
6895
|
+
* the person to "fix or install" instead.
|
|
6896
|
+
*
|
|
6897
|
+
* A file that cannot be **parsed** is not a migration candidate, though: a schema number can only
|
|
6898
|
+
* be read from a file that is JSON, and `migrate` refuses one it cannot read rather than lifting
|
|
6899
|
+
* it. The startup guard prints this list as "run migrate", so a broken file must not appear
|
|
6900
|
+
* here — it belongs in `configError`'s "fix …" advice alone.
|
|
6901
|
+
*/
|
|
6841
6902
|
get pendingMigrations() {
|
|
6842
|
-
|
|
6903
|
+
if (this.settingsParseError !== null || this.serversParseError !== null) return [];
|
|
6904
|
+
return planConfigMigrations(Math.min(this.settingsSchemaVersion, this.serversSchemaVersion)).steps;
|
|
6843
6905
|
}
|
|
6844
6906
|
onChange(listener) {
|
|
6845
6907
|
this.listeners.add(listener);
|
|
@@ -8753,6 +8815,176 @@ var init_port = __esmMin((() => {
|
|
|
8753
8815
|
FILETIME_UNIX_OFFSET_MS = 0xa9730b66800;
|
|
8754
8816
|
}));
|
|
8755
8817
|
//#endregion
|
|
8818
|
+
//#region src/providers/process.ts
|
|
8819
|
+
/**
|
|
8820
|
+
* Resolves a bare command through the entry's own directory and the project's
|
|
8821
|
+
* `node_modules/.bin` first, so a server installed as a project dependency is
|
|
8822
|
+
* found even when the launcher's PATH has no pnpm-injected bin dir.
|
|
8823
|
+
*/
|
|
8824
|
+
function resolveCommand(command, ...searchDirs) {
|
|
8825
|
+
if (command.includes("/") || command.includes("\\")) return command;
|
|
8826
|
+
const candidates = process.platform === "win32" && path.extname(command) === "" ? WINDOWS_SHIM_EXTENSIONS.map((extension) => `${command}${extension}`) : [command];
|
|
8827
|
+
for (const dir of searchDirs) for (const candidate of candidates) {
|
|
8828
|
+
const local = path.join(dir, "node_modules", ".bin", candidate);
|
|
8829
|
+
if (fs.existsSync(local)) return local;
|
|
8830
|
+
}
|
|
8831
|
+
return command;
|
|
8832
|
+
}
|
|
8833
|
+
/**
|
|
8834
|
+
* Does this program exist where `spawn` would look it up, and where?
|
|
8835
|
+
*
|
|
8836
|
+
* Used only to tell a **pasted command line** apart from a missing program: `spawn` answers both
|
|
8837
|
+
* with the same `ENOENT`, and the two have opposite fixes. `null` means it was not found anywhere
|
|
8838
|
+
* this process would search.
|
|
8839
|
+
*
|
|
8840
|
+
* A bare name is searched on `PATH` (plus `.exe`/`.cmd`/`.bat` on Windows, because that is what
|
|
8841
|
+
* the OS appends); anything with a separator is a path and is stat'd as written.
|
|
8842
|
+
*/
|
|
8843
|
+
function findProgram(command, cwd = projectDir) {
|
|
8844
|
+
if (command.includes("/") || command.includes("\\")) {
|
|
8845
|
+
const resolved = path.resolve(cwd, command);
|
|
8846
|
+
return isExecutable(resolved) ? resolved : null;
|
|
8847
|
+
}
|
|
8848
|
+
const extensions = process.platform === "win32" ? ["", ...WINDOWS_SHIM_EXTENSIONS] : [""];
|
|
8849
|
+
const dirs = (process.env.PATH ?? "").split(path.delimiter).filter((dir) => dir.length > 0);
|
|
8850
|
+
for (const dir of dirs) for (const extension of extensions) {
|
|
8851
|
+
const candidate = path.join(dir, `${command}${extension}`);
|
|
8852
|
+
if (isExecutable(candidate)) return candidate;
|
|
8853
|
+
}
|
|
8854
|
+
return null;
|
|
8855
|
+
}
|
|
8856
|
+
/** A file this user may run. A directory named like a program is not one. */
|
|
8857
|
+
function isExecutable(file) {
|
|
8858
|
+
try {
|
|
8859
|
+
if (!fs.statSync(file).isFile()) return false;
|
|
8860
|
+
if (process.platform === "win32") return true;
|
|
8861
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
8862
|
+
return true;
|
|
8863
|
+
} catch {
|
|
8864
|
+
return false;
|
|
8865
|
+
}
|
|
8866
|
+
}
|
|
8867
|
+
/** Relative entry paths belong to the project that launched the panel. */
|
|
8868
|
+
function resolveCwd(cwd, base = projectDir) {
|
|
8869
|
+
return path.resolve(base, cwd);
|
|
8870
|
+
}
|
|
8871
|
+
/** Node cannot spawn a Windows `.cmd`/`.bat` shim without a shell (EINVAL). */
|
|
8872
|
+
function needsShell(command) {
|
|
8873
|
+
return process.platform === "win32" && /\.(?:cmd|bat)$/i.test(command);
|
|
8874
|
+
}
|
|
8875
|
+
function spawnManaged(spec, options = {}) {
|
|
8876
|
+
return spawn(spec.command, spec.args, {
|
|
8877
|
+
cwd: spec.cwd,
|
|
8878
|
+
env: {
|
|
8879
|
+
...process.env,
|
|
8880
|
+
...spec.env
|
|
8881
|
+
},
|
|
8882
|
+
detached: options.detached ?? true,
|
|
8883
|
+
stdio: [
|
|
8884
|
+
"ignore",
|
|
8885
|
+
"pipe",
|
|
8886
|
+
"pipe"
|
|
8887
|
+
],
|
|
8888
|
+
shell: needsShell(spec.command),
|
|
8889
|
+
windowsHide: true
|
|
8890
|
+
});
|
|
8891
|
+
}
|
|
8892
|
+
/** SIGTERM (default) to the child, escalating to SIGKILL after the grace period. */
|
|
8893
|
+
async function terminate(child, options) {
|
|
8894
|
+
if (child.exitCode !== null || child.signalCode !== null) return "exited";
|
|
8895
|
+
const exited = waitForExit$1(child, options.graceMs);
|
|
8896
|
+
signalChild(child, options.signal, options.killGroup);
|
|
8897
|
+
if (await exited) return "exited";
|
|
8898
|
+
signalChild(child, "SIGKILL", options.killGroup);
|
|
8899
|
+
await waitForExit$1(child, 2e3);
|
|
8900
|
+
return "force-killed";
|
|
8901
|
+
}
|
|
8902
|
+
/**
|
|
8903
|
+
* Windows has no process groups and no SIGTERM: `taskkill /T` walks the tree and
|
|
8904
|
+
* `/F` is the only reliable way to stop a console process.
|
|
8905
|
+
*/
|
|
8906
|
+
async function killTreeWindows(pid) {
|
|
8907
|
+
try {
|
|
8908
|
+
await execFileAsync$1("taskkill", [
|
|
8909
|
+
"/pid",
|
|
8910
|
+
String(pid),
|
|
8911
|
+
"/T",
|
|
8912
|
+
"/F"
|
|
8913
|
+
], { timeout: 5e3 });
|
|
8914
|
+
} catch {}
|
|
8915
|
+
}
|
|
8916
|
+
function signalChild(child, signal, killGroup) {
|
|
8917
|
+
const pid = child.pid;
|
|
8918
|
+
if (pid === void 0) return;
|
|
8919
|
+
signalPid(pid, signal, killGroup);
|
|
8920
|
+
}
|
|
8921
|
+
function signalPid(pid, signal, killGroup) {
|
|
8922
|
+
if (process.platform === "win32") {
|
|
8923
|
+
if (killGroup) killTreeWindows(pid);
|
|
8924
|
+
else try {
|
|
8925
|
+
process.kill(pid, signal);
|
|
8926
|
+
} catch {}
|
|
8927
|
+
return;
|
|
8928
|
+
}
|
|
8929
|
+
if (killGroup) try {
|
|
8930
|
+
process.kill(-pid, signal);
|
|
8931
|
+
return;
|
|
8932
|
+
} catch {}
|
|
8933
|
+
try {
|
|
8934
|
+
process.kill(pid, signal);
|
|
8935
|
+
} catch {}
|
|
8936
|
+
}
|
|
8937
|
+
/**
|
|
8938
|
+
* The same shutdown a supervised child gets, for a process we adopted instead of
|
|
8939
|
+
* spawned: a detached successor is not our child, so it is signalled by pid (and
|
|
8940
|
+
* by process group when asked) and its exit is polled rather than awaited.
|
|
8941
|
+
*
|
|
8942
|
+
* Liveness comes from `isProcessAlive`, never a local signal-0 copy: a second definition returned
|
|
8943
|
+
* `false` for `EPERM`, so a process that was there but not ours to signal read as "exited" and
|
|
8944
|
+
* `'force-killed'` was returned for one still running. One predicate, one answer.
|
|
8945
|
+
*/
|
|
8946
|
+
async function terminatePid(pid, options) {
|
|
8947
|
+
if (!isProcessAlive(pid)) return "exited";
|
|
8948
|
+
signalPid(pid, options.signal, options.killGroup);
|
|
8949
|
+
const deadline = Date.now() + Math.max(0, options.graceMs);
|
|
8950
|
+
while (Date.now() < deadline && isProcessAlive(pid)) await delay$1(50);
|
|
8951
|
+
if (!isProcessAlive(pid)) return "exited";
|
|
8952
|
+
signalPid(pid, "SIGKILL", options.killGroup);
|
|
8953
|
+
const hardDeadline = Date.now() + 2e3;
|
|
8954
|
+
while (Date.now() < hardDeadline && isProcessAlive(pid)) await delay$1(50);
|
|
8955
|
+
return "force-killed";
|
|
8956
|
+
}
|
|
8957
|
+
function delay$1(ms) {
|
|
8958
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8959
|
+
}
|
|
8960
|
+
function waitForExit$1(child, timeoutMs) {
|
|
8961
|
+
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
|
|
8962
|
+
if (timeoutMs <= 0) return Promise.resolve(false);
|
|
8963
|
+
return new Promise((resolve) => {
|
|
8964
|
+
const timer = setTimeout(() => {
|
|
8965
|
+
child.removeListener("exit", onExit);
|
|
8966
|
+
resolve(false);
|
|
8967
|
+
}, timeoutMs);
|
|
8968
|
+
function onExit() {
|
|
8969
|
+
clearTimeout(timer);
|
|
8970
|
+
resolve(true);
|
|
8971
|
+
}
|
|
8972
|
+
child.once("exit", onExit);
|
|
8973
|
+
});
|
|
8974
|
+
}
|
|
8975
|
+
var execFileAsync$1, WINDOWS_SHIM_EXTENSIONS;
|
|
8976
|
+
var init_process = __esmMin((() => {
|
|
8977
|
+
init_paths();
|
|
8978
|
+
init_port();
|
|
8979
|
+
execFileAsync$1 = promisify(execFile);
|
|
8980
|
+
WINDOWS_SHIM_EXTENSIONS = [
|
|
8981
|
+
".exe",
|
|
8982
|
+
".cmd",
|
|
8983
|
+
".bat",
|
|
8984
|
+
".ps1"
|
|
8985
|
+
];
|
|
8986
|
+
}));
|
|
8987
|
+
//#endregion
|
|
8756
8988
|
//#region src/providers/nanny.ts
|
|
8757
8989
|
var nanny_exports$2 = /* @__PURE__ */ __exportAll({
|
|
8758
8990
|
HEARTBEAT_STALE_MS: () => HEARTBEAT_STALE_MS,
|
|
@@ -8882,12 +9114,54 @@ function exitCodeHint(code) {
|
|
|
8882
9114
|
*
|
|
8883
9115
|
* `command` is the configured program, so the two cases can be told apart: if a bare name has no
|
|
8884
9116
|
* path separator, the shell would have searched `PATH` and this one did not.
|
|
9117
|
+
*
|
|
9118
|
+
* A **missing working directory** is the third cause of the same errno, and it is the one a
|
|
9119
|
+
* deployment hits: `spawn` resolves `cwd` before it looks for the program, so an entry whose `cwd`
|
|
9120
|
+
* does not exist *under this launch directory* fails exactly like an uninstalled program. That read
|
|
9121
|
+
* sent a person to `which node` while `node` was fine and only the relative path was wrong (a unit
|
|
9122
|
+
* file with no `WorkingDirectory=`, a container started from `/`). `cwd` is therefore checked first:
|
|
9123
|
+
* if it is not an existing directory, nothing else about the spawn could have worked.
|
|
8885
9124
|
*/
|
|
8886
|
-
function describeSpawnError(error, command) {
|
|
8887
|
-
|
|
9125
|
+
function describeSpawnError(error, command, cwd) {
|
|
9126
|
+
const missingDir = cwd === void 0 ? null : describeMissingDir(cwd);
|
|
9127
|
+
if (missingDir !== null && (error.code === "ENOENT" || error.code === "ENOTDIR")) return missingDir;
|
|
9128
|
+
if (error.code === "ENOENT") {
|
|
9129
|
+
const pasted = describePastedCommandLine(command, cwd);
|
|
9130
|
+
if (pasted !== null) return pasted;
|
|
9131
|
+
return command.includes("/") || command.includes("\\") ? `\`${command}\` does not exist — check the path, and any directory on the way to it` : `\`${command}\` was not found — is it installed, and is it on PATH for the user running the panel?`;
|
|
9132
|
+
}
|
|
8888
9133
|
if (error.code === "EACCES") return `\`${command}\` exists but is not executable — check its permissions (chmod +x)`;
|
|
8889
9134
|
return `${error.message} (while running \`${command}\`)`;
|
|
8890
9135
|
}
|
|
9136
|
+
/**
|
|
9137
|
+
* The first mistake the Add-server form invites: a whole command line typed into `Command`.
|
|
9138
|
+
*
|
|
9139
|
+
* `Command` is spawned **without a shell** and `Arguments` is a separate field, so `node server.js`
|
|
9140
|
+
* names a program called `node server.js`. The fix is to split it — and the sentence has to say so,
|
|
9141
|
+
* because the alternative reading ("node is not installed") is what sends someone to `which node`
|
|
9142
|
+
* while `node` is right there.
|
|
9143
|
+
*
|
|
9144
|
+
* Only claimed when the evidence is unambiguous: the field has whitespace, and the program it opens
|
|
9145
|
+
* with **does** resolve. So a genuinely missing program keeps the message about PATH, and a path with
|
|
9146
|
+
* a space in it is never split (it has no bare first word that resolves). See `findProgram`.
|
|
9147
|
+
*/
|
|
9148
|
+
function describePastedCommandLine(command, cwd) {
|
|
9149
|
+
const words = command.trim().split(/\s+/);
|
|
9150
|
+
if (words.length < 2) return null;
|
|
9151
|
+
const program = words[0];
|
|
9152
|
+
if (findProgram(program, cwd) === null) return null;
|
|
9153
|
+
return `\`${command}\` is a whole command line, but \`Command\` is spawned without a shell — this release looks for a program named \`${command}\`. Put \`${program}\` in \`Command\` and the rest in \`Arguments\`, one argument per line`;
|
|
9154
|
+
}
|
|
9155
|
+
/** Why a working directory cannot be used, in one sentence, or null when it can. */
|
|
9156
|
+
function describeMissingDir(cwd) {
|
|
9157
|
+
try {
|
|
9158
|
+
if (fs.statSync(cwd).isDirectory()) return null;
|
|
9159
|
+
return `the working directory \`${cwd}\` is not a directory — a relative \`cwd\` resolves against the directory the panel was started from`;
|
|
9160
|
+
} catch (error) {
|
|
9161
|
+
if (error.code === "ENOENT") return `the working directory \`${cwd}\` does not exist — a relative \`cwd\` resolves against the directory the panel was started from, so a service started from elsewhere (systemd, docker, a login shell) looks in a different place`;
|
|
9162
|
+
return `the working directory \`${cwd}\` cannot be read — check its permissions`;
|
|
9163
|
+
}
|
|
9164
|
+
}
|
|
8891
9165
|
/** `SIGKILL` for 9, or null when the number names nothing. */
|
|
8892
9166
|
function signalName(number) {
|
|
8893
9167
|
for (const [name, value] of Object.entries(os.constants.signals)) if (value === number) return name;
|
|
@@ -8913,6 +9187,7 @@ var init_nanny$2 = __esmMin((() => {
|
|
|
8913
9187
|
init_identity();
|
|
8914
9188
|
init_port();
|
|
8915
9189
|
init_proc();
|
|
9190
|
+
init_process();
|
|
8916
9191
|
init_contracts();
|
|
8917
9192
|
SPEC_MODE = 384;
|
|
8918
9193
|
SPEC_SUFFIX = ".spec.json";
|
|
@@ -13228,142 +13503,6 @@ var init_archive = __esmMin((() => {
|
|
|
13228
13503
|
];
|
|
13229
13504
|
}));
|
|
13230
13505
|
//#endregion
|
|
13231
|
-
//#region src/providers/process.ts
|
|
13232
|
-
/**
|
|
13233
|
-
* Resolves a bare command through the entry's own directory and the project's
|
|
13234
|
-
* `node_modules/.bin` first, so a server installed as a project dependency is
|
|
13235
|
-
* found even when the launcher's PATH has no pnpm-injected bin dir.
|
|
13236
|
-
*/
|
|
13237
|
-
function resolveCommand(command, ...searchDirs) {
|
|
13238
|
-
if (command.includes("/") || command.includes("\\")) return command;
|
|
13239
|
-
const candidates = process.platform === "win32" && path.extname(command) === "" ? [command, ...WINDOWS_SHIM_EXTENSIONS.map((extension) => `${command}${extension}`)] : [command];
|
|
13240
|
-
for (const dir of searchDirs) for (const candidate of candidates) {
|
|
13241
|
-
const local = path.join(dir, "node_modules", ".bin", candidate);
|
|
13242
|
-
if (fs.existsSync(local)) return local;
|
|
13243
|
-
}
|
|
13244
|
-
return command;
|
|
13245
|
-
}
|
|
13246
|
-
/** Relative entry paths belong to the project that launched the panel. */
|
|
13247
|
-
function resolveCwd(cwd, base = projectDir) {
|
|
13248
|
-
return path.resolve(base, cwd);
|
|
13249
|
-
}
|
|
13250
|
-
/** Node cannot spawn a Windows `.cmd`/`.bat` shim without a shell (EINVAL). */
|
|
13251
|
-
function needsShell(command) {
|
|
13252
|
-
return process.platform === "win32" && /\.(?:cmd|bat)$/i.test(command);
|
|
13253
|
-
}
|
|
13254
|
-
function spawnManaged(spec, options = {}) {
|
|
13255
|
-
return spawn(spec.command, spec.args, {
|
|
13256
|
-
cwd: spec.cwd,
|
|
13257
|
-
env: {
|
|
13258
|
-
...process.env,
|
|
13259
|
-
...spec.env
|
|
13260
|
-
},
|
|
13261
|
-
detached: options.detached ?? true,
|
|
13262
|
-
stdio: [
|
|
13263
|
-
"ignore",
|
|
13264
|
-
"pipe",
|
|
13265
|
-
"pipe"
|
|
13266
|
-
],
|
|
13267
|
-
shell: needsShell(spec.command),
|
|
13268
|
-
windowsHide: true
|
|
13269
|
-
});
|
|
13270
|
-
}
|
|
13271
|
-
/** SIGTERM (default) to the child, escalating to SIGKILL after the grace period. */
|
|
13272
|
-
async function terminate(child, options) {
|
|
13273
|
-
if (child.exitCode !== null || child.signalCode !== null) return "exited";
|
|
13274
|
-
const exited = waitForExit$1(child, options.graceMs);
|
|
13275
|
-
signalChild(child, options.signal, options.killGroup);
|
|
13276
|
-
if (await exited) return "exited";
|
|
13277
|
-
signalChild(child, "SIGKILL", options.killGroup);
|
|
13278
|
-
await waitForExit$1(child, 2e3);
|
|
13279
|
-
return "force-killed";
|
|
13280
|
-
}
|
|
13281
|
-
/**
|
|
13282
|
-
* Windows has no process groups and no SIGTERM: `taskkill /T` walks the tree and
|
|
13283
|
-
* `/F` is the only reliable way to stop a console process.
|
|
13284
|
-
*/
|
|
13285
|
-
async function killTreeWindows(pid) {
|
|
13286
|
-
try {
|
|
13287
|
-
await execFileAsync$1("taskkill", [
|
|
13288
|
-
"/pid",
|
|
13289
|
-
String(pid),
|
|
13290
|
-
"/T",
|
|
13291
|
-
"/F"
|
|
13292
|
-
], { timeout: 5e3 });
|
|
13293
|
-
} catch {}
|
|
13294
|
-
}
|
|
13295
|
-
function signalChild(child, signal, killGroup) {
|
|
13296
|
-
const pid = child.pid;
|
|
13297
|
-
if (pid === void 0) return;
|
|
13298
|
-
signalPid(pid, signal, killGroup);
|
|
13299
|
-
}
|
|
13300
|
-
function signalPid(pid, signal, killGroup) {
|
|
13301
|
-
if (process.platform === "win32") {
|
|
13302
|
-
if (killGroup) killTreeWindows(pid);
|
|
13303
|
-
else try {
|
|
13304
|
-
process.kill(pid, signal);
|
|
13305
|
-
} catch {}
|
|
13306
|
-
return;
|
|
13307
|
-
}
|
|
13308
|
-
if (killGroup) try {
|
|
13309
|
-
process.kill(-pid, signal);
|
|
13310
|
-
return;
|
|
13311
|
-
} catch {}
|
|
13312
|
-
try {
|
|
13313
|
-
process.kill(pid, signal);
|
|
13314
|
-
} catch {}
|
|
13315
|
-
}
|
|
13316
|
-
/**
|
|
13317
|
-
* The same shutdown a supervised child gets, for a process we adopted instead of
|
|
13318
|
-
* spawned: a detached successor is not our child, so it is signalled by pid (and
|
|
13319
|
-
* by process group when asked) and its exit is polled rather than awaited.
|
|
13320
|
-
*
|
|
13321
|
-
* Liveness comes from `isProcessAlive`, never a local signal-0 copy: a second definition returned
|
|
13322
|
-
* `false` for `EPERM`, so a process that was there but not ours to signal read as "exited" and
|
|
13323
|
-
* `'force-killed'` was returned for one still running. One predicate, one answer.
|
|
13324
|
-
*/
|
|
13325
|
-
async function terminatePid(pid, options) {
|
|
13326
|
-
if (!isProcessAlive(pid)) return "exited";
|
|
13327
|
-
signalPid(pid, options.signal, options.killGroup);
|
|
13328
|
-
const deadline = Date.now() + Math.max(0, options.graceMs);
|
|
13329
|
-
while (Date.now() < deadline && isProcessAlive(pid)) await delay$1(50);
|
|
13330
|
-
if (!isProcessAlive(pid)) return "exited";
|
|
13331
|
-
signalPid(pid, "SIGKILL", options.killGroup);
|
|
13332
|
-
const hardDeadline = Date.now() + 2e3;
|
|
13333
|
-
while (Date.now() < hardDeadline && isProcessAlive(pid)) await delay$1(50);
|
|
13334
|
-
return "force-killed";
|
|
13335
|
-
}
|
|
13336
|
-
function delay$1(ms) {
|
|
13337
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
13338
|
-
}
|
|
13339
|
-
function waitForExit$1(child, timeoutMs) {
|
|
13340
|
-
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
|
|
13341
|
-
if (timeoutMs <= 0) return Promise.resolve(false);
|
|
13342
|
-
return new Promise((resolve) => {
|
|
13343
|
-
const timer = setTimeout(() => {
|
|
13344
|
-
child.removeListener("exit", onExit);
|
|
13345
|
-
resolve(false);
|
|
13346
|
-
}, timeoutMs);
|
|
13347
|
-
function onExit() {
|
|
13348
|
-
clearTimeout(timer);
|
|
13349
|
-
resolve(true);
|
|
13350
|
-
}
|
|
13351
|
-
child.once("exit", onExit);
|
|
13352
|
-
});
|
|
13353
|
-
}
|
|
13354
|
-
var execFileAsync$1, WINDOWS_SHIM_EXTENSIONS;
|
|
13355
|
-
var init_process = __esmMin((() => {
|
|
13356
|
-
init_paths();
|
|
13357
|
-
init_port();
|
|
13358
|
-
execFileAsync$1 = promisify(execFile);
|
|
13359
|
-
WINDOWS_SHIM_EXTENSIONS = [
|
|
13360
|
-
".cmd",
|
|
13361
|
-
".exe",
|
|
13362
|
-
".bat",
|
|
13363
|
-
".ps1"
|
|
13364
|
-
];
|
|
13365
|
-
}));
|
|
13366
|
-
//#endregion
|
|
13367
13506
|
//#region src/helpers/backoff.ts
|
|
13368
13507
|
/** Exponential backoff: base * factor^(attempt - 1), capped at maxDelayMs. */
|
|
13369
13508
|
function computeBackoff(attempt, options) {
|
|
@@ -14178,8 +14317,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14178
14317
|
entry.restarts = 0;
|
|
14179
14318
|
if (entry.actor !== "policy") entry.healthRestarts = 0;
|
|
14180
14319
|
if (entry.actor !== "policy") entry.pendingRestart = null;
|
|
14181
|
-
entry
|
|
14182
|
-
entry.unhealthySince = null;
|
|
14320
|
+
this.resetHealth(entry);
|
|
14183
14321
|
this.persistEntryState(entry);
|
|
14184
14322
|
}
|
|
14185
14323
|
try {
|
|
@@ -14190,7 +14328,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14190
14328
|
};
|
|
14191
14329
|
entry.lastError = null;
|
|
14192
14330
|
entry.status = "starting";
|
|
14193
|
-
|
|
14331
|
+
this.resetHealth(entry);
|
|
14194
14332
|
this.publishServer(entry);
|
|
14195
14333
|
if (entry.config.persistent && await this.resumePersistent(entry)) return { ok: true };
|
|
14196
14334
|
if (!entry.config.persistent) {
|
|
@@ -14312,7 +14450,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14312
14450
|
port,
|
|
14313
14451
|
error: `server "${id}" is busy — try again in a moment`
|
|
14314
14452
|
};
|
|
14315
|
-
const { ours, foreign } = await this.portHolders(port);
|
|
14453
|
+
const { ours, foreign, siblings } = await this.portHolders(port);
|
|
14316
14454
|
if ([...ours, ...foreign].length === 0) {
|
|
14317
14455
|
const docker = await findDockerPortHolder(port);
|
|
14318
14456
|
if (docker !== null) {
|
|
@@ -14352,15 +14490,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
14352
14490
|
error: `nothing is listening on port ${port} any more`
|
|
14353
14491
|
};
|
|
14354
14492
|
}
|
|
14355
|
-
if (foreign.length === 0) {
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
skipped: ours
|
|
14362
|
-
};
|
|
14363
|
-
}
|
|
14493
|
+
if (foreign.length === 0) return {
|
|
14494
|
+
...empty,
|
|
14495
|
+
port,
|
|
14496
|
+
error: this.heldByOurs(port, ours, siblings),
|
|
14497
|
+
skipped: ours
|
|
14498
|
+
};
|
|
14364
14499
|
this.log(entry, "system", `freeing port ${port}: asking pid ${foreign.join(", ")} to stop`);
|
|
14365
14500
|
const { stopped, forced } = await terminatePids(foreign, { graceMs: entry.config.stop.graceMs });
|
|
14366
14501
|
if (forced.length > 0) this.log(entry, "system", `pid ${forced.join(", ")} ignored SIGTERM and was killed`);
|
|
@@ -14394,14 +14529,27 @@ var init_supervisor = __esmMin((() => {
|
|
|
14394
14529
|
* in an old banner from killing a recycled pid.
|
|
14395
14530
|
*/
|
|
14396
14531
|
async portHolders(port) {
|
|
14397
|
-
const supervised = await this.supervisedPids();
|
|
14532
|
+
const { pids: supervised, siblings } = await this.supervisedPids();
|
|
14398
14533
|
const holders = await listPortHolders(port);
|
|
14399
14534
|
return {
|
|
14400
14535
|
ours: holders.filter((pid) => supervised.has(pid)),
|
|
14401
|
-
foreign: holders.filter((pid) => !supervised.has(pid))
|
|
14536
|
+
foreign: holders.filter((pid) => !supervised.has(pid)),
|
|
14537
|
+
siblings
|
|
14402
14538
|
};
|
|
14403
14539
|
}
|
|
14404
14540
|
/**
|
|
14541
|
+
* The sentence a refused port prints: names the holder, and where it lives when that is another
|
|
14542
|
+
* workspace, because "stop that server instead" is not actionable from a page that cannot show it.
|
|
14543
|
+
*
|
|
14544
|
+
* A sibling whose pid is one we refused is matched by pid, the one fact both sides agree on — a
|
|
14545
|
+
* same-named entry in this workspace would have been a different pid.
|
|
14546
|
+
*/
|
|
14547
|
+
heldByOurs(port, ours, siblings) {
|
|
14548
|
+
const owners = siblings.filter((sibling) => ours.includes(sibling.pid));
|
|
14549
|
+
const place = owners.length === 0 ? "" : ` on ${[...new Set(owners.map((owner) => `${owner.workspaceId}/${owner.serverId}`))].join(", ")}`;
|
|
14550
|
+
return `port ${port} is held by pid ${ours.join(", ")}, which this panel supervises${place} — stop that server instead`;
|
|
14551
|
+
}
|
|
14552
|
+
/**
|
|
14405
14553
|
* Pids of the processes this panel owns, plus itself — the whole *tree* of every
|
|
14406
14554
|
* entry, not just the pid it recorded.
|
|
14407
14555
|
*
|
|
@@ -14418,9 +14566,14 @@ var init_supervisor = __esmMin((() => {
|
|
|
14418
14566
|
const roots = [];
|
|
14419
14567
|
for (const entry of this.entries.values()) if (entry.pid !== null) roots.push(entry.pid);
|
|
14420
14568
|
else if (entry.child?.pid !== void 0) roots.push(entry.child.pid);
|
|
14569
|
+
const siblings = [...await this.options.siblingServers?.() ?? []];
|
|
14570
|
+
roots.push(...siblings.map((sibling) => sibling.pid));
|
|
14421
14571
|
const pids = await processTreePids(roots);
|
|
14422
14572
|
pids.add(process.pid);
|
|
14423
|
-
return
|
|
14573
|
+
return {
|
|
14574
|
+
pids,
|
|
14575
|
+
siblings
|
|
14576
|
+
};
|
|
14424
14577
|
}
|
|
14425
14578
|
/** The port's own answer, with the same short recheck the preflight uses. */
|
|
14426
14579
|
async waitForPortRelease(entry, port) {
|
|
@@ -14529,7 +14682,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14529
14682
|
});
|
|
14530
14683
|
const { port, stop } = entry.config;
|
|
14531
14684
|
if (stop.killPortHolders && port !== null) {
|
|
14532
|
-
const leftover = await killPortHolders(port, await this.supervisedPids());
|
|
14685
|
+
const leftover = await killPortHolders(port, (await this.supervisedPids()).pids);
|
|
14533
14686
|
if (leftover.length > 0) this.log(entry, "system", `port ${port} was still held by pid ${leftover.join(", ")} — killed`);
|
|
14534
14687
|
}
|
|
14535
14688
|
const survivor = entry.config.persistent && entry.pid !== null && isProcessAlive(entry.pid) ? entry.pid : null;
|
|
@@ -14542,9 +14695,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
14542
14695
|
}
|
|
14543
14696
|
entry.stopping = false;
|
|
14544
14697
|
entry.child = null;
|
|
14545
|
-
entry
|
|
14546
|
-
entry.adopted = false;
|
|
14698
|
+
this.endProcessReadings(entry);
|
|
14547
14699
|
entry.nannyExit = null;
|
|
14700
|
+
this.endHealthStreak(entry);
|
|
14701
|
+
if (survivor === null || !entry.config.health.enabled) this.resetHealth(entry);
|
|
14548
14702
|
if (entry.lastChild !== null && !isProcessAlive(entry.lastChild.pid)) {
|
|
14549
14703
|
entry.lastChild = null;
|
|
14550
14704
|
this.persistEntryState(entry);
|
|
@@ -14558,6 +14712,56 @@ var init_supervisor = __esmMin((() => {
|
|
|
14558
14712
|
error: entry.lastError
|
|
14559
14713
|
};
|
|
14560
14714
|
}
|
|
14715
|
+
/**
|
|
14716
|
+
* The health state, together with the streak that produced it.
|
|
14717
|
+
*
|
|
14718
|
+
* `healthFailures` and `unhealthySince` describe one **process's** run: the failures since it
|
|
14719
|
+
* began, and the moment that streak turned unhealthy. They move with `health` for one reason —
|
|
14720
|
+
* a caller that set one and forgot the other left a duration counting up while nothing was
|
|
14721
|
+
* measured. Measured on the built panel: an entry that crashed while unhealthy reported
|
|
14722
|
+
* `status=crashed health=unknown` beside `Unhealthy for 3m 17s` and a `Not Probed` row, the
|
|
14723
|
+
* identical shape an explicit stop had before round 13 fixed that one path. Anything other
|
|
14724
|
+
* than `unhealthy` therefore ends the streak.
|
|
14725
|
+
*/
|
|
14726
|
+
setHealth(entry, health) {
|
|
14727
|
+
entry.health = health;
|
|
14728
|
+
if (health !== "unhealthy") this.endHealthStreak(entry);
|
|
14729
|
+
}
|
|
14730
|
+
/**
|
|
14731
|
+
* Forgets the streak without deciding the verdict.
|
|
14732
|
+
*
|
|
14733
|
+
* A refused stop is the one place the two differ: the process survived, so its `conflict`
|
|
14734
|
+
* outcome stays, while the duration that described the run cannot keep counting from a probe
|
|
14735
|
+
* that is no longer taken.
|
|
14736
|
+
*/
|
|
14737
|
+
endHealthStreak(entry) {
|
|
14738
|
+
entry.healthFailures = 0;
|
|
14739
|
+
entry.unhealthySince = null;
|
|
14740
|
+
}
|
|
14741
|
+
/** The health of an entry nothing is probing: `disabled` with the probe off, else `unknown`. */
|
|
14742
|
+
resetHealth(entry) {
|
|
14743
|
+
this.setHealth(entry, entry.config.health.enabled ? "unknown" : "disabled");
|
|
14744
|
+
}
|
|
14745
|
+
/**
|
|
14746
|
+
* The measurements one process produced, dropped when that process is gone.
|
|
14747
|
+
*
|
|
14748
|
+
* `pid`, `responseMs` and `resources` describe *one* run: the probe's last latency and the
|
|
14749
|
+
* sampler's last reading are that process's numbers, and nothing measured them again just
|
|
14750
|
+
* because the pid left. Both exit paths cleared them; an adopted entry has no exit event of its
|
|
14751
|
+
* own, so a stopped successor kept a live-looking CPU, RSS and probe beside `Status Stopped /
|
|
14752
|
+
* Health Not Probed` — and the sampler never corrects them, because it only visits entries with
|
|
14753
|
+
* a pid. The same numbers reached `/api/metrics`, where a stopped server published a real
|
|
14754
|
+
* `hh_server_cpu_percent` and `hh_server_rss_bytes`.
|
|
14755
|
+
*
|
|
14756
|
+
* `adopted` goes with them: it says *this pid* is a successor we took over, and there is no pid
|
|
14757
|
+
* left to say it of.
|
|
14758
|
+
*/
|
|
14759
|
+
endProcessReadings(entry) {
|
|
14760
|
+
entry.pid = null;
|
|
14761
|
+
entry.adopted = false;
|
|
14762
|
+
entry.responseMs = null;
|
|
14763
|
+
entry.resources = null;
|
|
14764
|
+
}
|
|
14561
14765
|
createEntry(config) {
|
|
14562
14766
|
const persisted = readEntryState(entryStatePath(this.options.nannyDir, config.id));
|
|
14563
14767
|
const lastPid = persisted?.lastPid ?? null;
|
|
@@ -14692,7 +14896,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14692
14896
|
}
|
|
14693
14897
|
entry.portState = free ? "free" : "in-use";
|
|
14694
14898
|
if (free) return { kind: "free" };
|
|
14695
|
-
const { ours, foreign } = await this.portHolders(port);
|
|
14899
|
+
const { ours, foreign, siblings } = await this.portHolders(port);
|
|
14696
14900
|
const holders = [...ours, ...foreign];
|
|
14697
14901
|
const own = await this.ownPortHolder(entry, foreign);
|
|
14698
14902
|
const docker = holders.length === 0 ? await findDockerPortHolder(port) : null;
|
|
@@ -14700,7 +14904,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14700
14904
|
if (entry.config.onPortConflict === "kill") {
|
|
14701
14905
|
if (ours.length > 0) {
|
|
14702
14906
|
entry.status = "conflict";
|
|
14703
|
-
entry.lastError =
|
|
14907
|
+
entry.lastError = this.heldByOurs(port, ours, siblings);
|
|
14704
14908
|
this.log(entry, "system", `${entry.lastError} — not starting (onPortConflict: kill)`);
|
|
14705
14909
|
this.publishServer(entry);
|
|
14706
14910
|
return {
|
|
@@ -14735,9 +14939,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
14735
14939
|
return await this.stopPortHolders(entry, [own], port, "replacing", freeOnAll);
|
|
14736
14940
|
}
|
|
14737
14941
|
const hint = own !== null ? ` — pid ${own} is a detached restart of this entry: set onPortConflict to "follow" to adopt it, "reclaim" to replace it with a supervised process, or "kill" to stop whatever holds the port` : docker === null ? "" : ` — it is published by a docker container, which \`kill\` stops through docker; \`block\` and \`warn\` leave it alone`;
|
|
14942
|
+
const blockedError = ours.length > 0 ? this.heldByOurs(port, ours, siblings) : `port ${port} is already in use${suffix}${hint}`;
|
|
14738
14943
|
if (entry.config.onPortConflict !== "warn") {
|
|
14739
14944
|
entry.status = "conflict";
|
|
14740
|
-
entry.lastError =
|
|
14945
|
+
entry.lastError = blockedError;
|
|
14741
14946
|
this.log(entry, "system", `${entry.lastError} — not starting (onPortConflict: ${entry.config.onPortConflict})`);
|
|
14742
14947
|
this.publishServer(entry);
|
|
14743
14948
|
return {
|
|
@@ -14745,7 +14950,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14745
14950
|
error: entry.lastError
|
|
14746
14951
|
};
|
|
14747
14952
|
}
|
|
14748
|
-
this.log(entry, "system", `warning:
|
|
14953
|
+
this.log(entry, "system", `warning: ${blockedError} — starting anyway`);
|
|
14749
14954
|
return { kind: "free" };
|
|
14750
14955
|
}
|
|
14751
14956
|
/**
|
|
@@ -14792,7 +14997,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14792
14997
|
entry.pid = pid;
|
|
14793
14998
|
entry.child = null;
|
|
14794
14999
|
entry.status = "running";
|
|
14795
|
-
|
|
15000
|
+
this.resetHealth(entry);
|
|
14796
15001
|
entry.startedAt = Date.now();
|
|
14797
15002
|
entry.lastError = null;
|
|
14798
15003
|
if (entry.config.persistent) this.followPersistent(entry, true);
|
|
@@ -14855,12 +15060,9 @@ var init_supervisor = __esmMin((() => {
|
|
|
14855
15060
|
const ranForMs = entry.nannyExit?.runtimeMs ?? (entry.startedAt === null ? 0 : Date.now() - entry.startedAt);
|
|
14856
15061
|
const detail = entry.nannyExit === null ? "adopted process exited" : describeNannyExit(entry.nannyExit);
|
|
14857
15062
|
entry.nannyExit = null;
|
|
14858
|
-
entry.adopted = false;
|
|
14859
|
-
entry.pid = null;
|
|
14860
15063
|
this.forgetRecordedChild(entry, adoptedPid);
|
|
14861
|
-
entry
|
|
14862
|
-
entry
|
|
14863
|
-
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
15064
|
+
this.endProcessReadings(entry);
|
|
15065
|
+
this.resetHealth(entry);
|
|
14864
15066
|
entry.exitCode = null;
|
|
14865
15067
|
entry.exitSignal = null;
|
|
14866
15068
|
if (!entry.removed) this.options.history.record(entry.config.id, {
|
|
@@ -14991,7 +15193,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14991
15193
|
const stderr = new LineSplitter((stream, text) => this.log(entry, stream, text));
|
|
14992
15194
|
child.stdout?.on("data", (chunk) => stdout.push("stdout", chunk));
|
|
14993
15195
|
child.stderr?.on("data", (chunk) => stderr.push("stderr", chunk));
|
|
14994
|
-
this.attachChild(entry, child, `${command} ${args.join(" ")}`.trim(), () => {
|
|
15196
|
+
this.attachChild(entry, child, `${command} ${args.join(" ")}`.trim(), cwd, () => {
|
|
14995
15197
|
stdout.flush("stdout");
|
|
14996
15198
|
stderr.flush("stderr");
|
|
14997
15199
|
});
|
|
@@ -15045,7 +15247,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15045
15247
|
return this.failSpawn(entry, error.message);
|
|
15046
15248
|
}
|
|
15047
15249
|
child.unref();
|
|
15048
|
-
this.attachChild(entry, child, `nanny → ${command} ${args.join(" ")}`.trim());
|
|
15250
|
+
this.attachChild(entry, child, `nanny → ${command} ${args.join(" ")}`.trim(), cwd);
|
|
15049
15251
|
this.followPersistent(entry);
|
|
15050
15252
|
return { ok: true };
|
|
15051
15253
|
}
|
|
@@ -15059,8 +15261,14 @@ var init_supervisor = __esmMin((() => {
|
|
|
15059
15261
|
error: message
|
|
15060
15262
|
};
|
|
15061
15263
|
}
|
|
15062
|
-
/**
|
|
15063
|
-
|
|
15264
|
+
/**
|
|
15265
|
+
* The bookkeeping every spawn shares, plus the exit events that end it.
|
|
15266
|
+
*
|
|
15267
|
+
* `cwd` is the directory the child was spawned in. A spawn that fails with `ENOENT` may have
|
|
15268
|
+
* failed because the *working directory* is missing rather than the program — `spawn` resolves
|
|
15269
|
+
* one before it looks for the other — so `describeSpawnError` needs it to name the real cause.
|
|
15270
|
+
*/
|
|
15271
|
+
attachChild(entry, child, detail, cwd, flush) {
|
|
15064
15272
|
entry.child = child;
|
|
15065
15273
|
entry.pid = child.pid ?? null;
|
|
15066
15274
|
entry.startedAt = Date.now();
|
|
@@ -15080,11 +15288,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
15080
15288
|
entry.exitSignal = null;
|
|
15081
15289
|
entry.nannyExit = null;
|
|
15082
15290
|
entry.lastProbeAt = 0;
|
|
15083
|
-
entry
|
|
15084
|
-
entry.unhealthySince = null;
|
|
15291
|
+
this.resetHealth(entry);
|
|
15085
15292
|
this.publishServer(entry);
|
|
15086
15293
|
child.once("error", (error) => {
|
|
15087
|
-
entry.lastError = describeSpawnError(error, entry.config.command);
|
|
15294
|
+
entry.lastError = describeSpawnError(error, entry.config.command, cwd);
|
|
15088
15295
|
this.log(entry, "system", `process error: ${entry.lastError}`);
|
|
15089
15296
|
flush?.();
|
|
15090
15297
|
this.handleExit(entry, child, null, null);
|
|
@@ -15156,7 +15363,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15156
15363
|
entry.pid = state.nannyPid;
|
|
15157
15364
|
entry.startedAt = state.startedAt;
|
|
15158
15365
|
entry.status = "running";
|
|
15159
|
-
|
|
15366
|
+
this.resetHealth(entry);
|
|
15160
15367
|
entry.portState = entry.config.port === null ? "unknown" : "in-use";
|
|
15161
15368
|
entry.lastError = null;
|
|
15162
15369
|
entry.nannyExit = null;
|
|
@@ -15239,7 +15446,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15239
15446
|
if (port === null) {
|
|
15240
15447
|
if (entry.child !== child || entry.status !== "starting") return;
|
|
15241
15448
|
entry.status = "running";
|
|
15242
|
-
entry
|
|
15449
|
+
this.setHealth(entry, health.enabled ? "unknown" : "disabled");
|
|
15243
15450
|
this.log(entry, "system", "running (no port configured; readiness assumed on spawn)");
|
|
15244
15451
|
this.settleRestart(entry, "it spawned and is running");
|
|
15245
15452
|
this.publishServer(entry);
|
|
@@ -15250,7 +15457,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15250
15457
|
if (entry.child !== child || entry.status !== "starting" || this.disposed) return;
|
|
15251
15458
|
if (await this.portAccepts(entry, port, Math.min(health.timeoutMs, 1e3))) {
|
|
15252
15459
|
entry.portState = "in-use";
|
|
15253
|
-
entry
|
|
15460
|
+
this.setHealth(entry, !health.enabled ? "disabled" : health.mode === "http" ? "unknown" : "healthy");
|
|
15254
15461
|
entry.status = "running";
|
|
15255
15462
|
entry.lastProbeAt = 0;
|
|
15256
15463
|
this.log(entry, "system", `accepting connections on port ${port}`);
|
|
@@ -15262,7 +15469,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15262
15469
|
}
|
|
15263
15470
|
if (entry.child === child && entry.status === "starting") {
|
|
15264
15471
|
entry.status = "running";
|
|
15265
|
-
entry
|
|
15472
|
+
this.setHealth(entry, "unhealthy");
|
|
15266
15473
|
entry.unhealthySince = Date.now();
|
|
15267
15474
|
this.log(entry, "system", `no connection on port ${port} after ${health.startTimeoutMs}ms — supervising anyway`);
|
|
15268
15475
|
this.publishServer(entry);
|
|
@@ -15275,11 +15482,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
15275
15482
|
const nannyExit = entry.nannyExit;
|
|
15276
15483
|
entry.nannyExit = null;
|
|
15277
15484
|
entry.child = null;
|
|
15278
|
-
entry
|
|
15279
|
-
entry
|
|
15280
|
-
entry.resources = null;
|
|
15281
|
-
entry.responseMs = null;
|
|
15282
|
-
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
15485
|
+
this.endProcessReadings(entry);
|
|
15486
|
+
this.resetHealth(entry);
|
|
15283
15487
|
entry.exitCode = code;
|
|
15284
15488
|
entry.exitSignal = signal;
|
|
15285
15489
|
this.forgetRecordedChild(entry, child.pid ?? null);
|
|
@@ -15406,9 +15610,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15406
15610
|
this.notify(entry, "recovered", probe.detail);
|
|
15407
15611
|
}
|
|
15408
15612
|
this.settleRestart(entry, `${probe.detail} (${probe.ms}ms)`);
|
|
15409
|
-
entry
|
|
15410
|
-
entry.healthFailures = 0;
|
|
15411
|
-
entry.unhealthySince = null;
|
|
15613
|
+
this.setHealth(entry, "healthy");
|
|
15412
15614
|
const servedForMs = entry.startedAt === null ? 0 : Date.now() - entry.startedAt;
|
|
15413
15615
|
if (entry.healthRestarts > 0 && servedForMs >= entry.config.restart.resetAfterMs) {
|
|
15414
15616
|
entry.healthRestarts = 0;
|
|
@@ -15427,7 +15629,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
15427
15629
|
});
|
|
15428
15630
|
this.notify(entry, "unhealthy", probe.detail);
|
|
15429
15631
|
}
|
|
15430
|
-
entry
|
|
15632
|
+
this.setHealth(entry, "unhealthy");
|
|
15431
15633
|
}
|
|
15432
15634
|
} finally {
|
|
15433
15635
|
entry.probing = false;
|
|
@@ -18879,6 +19081,21 @@ var init_panel = __esmMin((() => {
|
|
|
18879
19081
|
if (workspaceId !== void 0) return this.runtimes.get(workspaceId)?.supervisor.views() ?? [];
|
|
18880
19082
|
return this.workspaces().flatMap((runtime) => runtime.supervisor.views());
|
|
18881
19083
|
}
|
|
19084
|
+
/**
|
|
19085
|
+
* The running servers of every workspace *except* `except`, so one supervisor can recognize a
|
|
19086
|
+
* sibling workspace's process as one the panel owns rather than a stranger to signal — and can
|
|
19087
|
+
* name it when it refuses.
|
|
19088
|
+
*
|
|
19089
|
+
* Read from the live views rather than from nanny state: an adopted entry has no child record,
|
|
19090
|
+
* and a persistent one's pid is the nanny's, whose tree the supervisor walks itself.
|
|
19091
|
+
*/
|
|
19092
|
+
siblingServers(except) {
|
|
19093
|
+
return this.workspaces().filter((runtime) => runtime.id !== except).flatMap((runtime) => runtime.supervisor.views().filter((view) => view.pid !== null).map((view) => ({
|
|
19094
|
+
pid: view.pid,
|
|
19095
|
+
workspaceId: runtime.id,
|
|
19096
|
+
serverId: view.id
|
|
19097
|
+
})));
|
|
19098
|
+
}
|
|
18882
19099
|
getState() {
|
|
18883
19100
|
const proxy = this.options.proxy();
|
|
18884
19101
|
return {
|
|
@@ -19069,7 +19286,8 @@ var init_panel = __esmMin((() => {
|
|
|
19069
19286
|
logFiles,
|
|
19070
19287
|
notifications,
|
|
19071
19288
|
onStateChange: () => this.scheduleState(),
|
|
19072
|
-
nannyDir: workspaceStateDir(id)
|
|
19289
|
+
nannyDir: workspaceStateDir(id),
|
|
19290
|
+
siblingServers: async () => this.siblingServers(id)
|
|
19073
19291
|
});
|
|
19074
19292
|
const runtime = {
|
|
19075
19293
|
id,
|
|
@@ -19929,16 +20147,16 @@ async function runControlPlane(options) {
|
|
|
19929
20147
|
const settings = new GlobalSettingsStore();
|
|
19930
20148
|
settings.load();
|
|
19931
20149
|
settings.writeJsonSchema();
|
|
19932
|
-
if (settings.configError !== null) {
|
|
19933
|
-
logger.error(`refusing to start: ${settings.configError}`);
|
|
19934
|
-
logger.info(`fix ${settings.path}, or install the release that wrote it`);
|
|
19935
|
-
process.exit(1);
|
|
19936
|
-
}
|
|
19937
20150
|
if (settings.pendingMigrations.length > 0) {
|
|
19938
20151
|
logger.error(`refusing to start: ${settings.path} needs ${settings.pendingMigrations.length} migration(s) before ${appVersion()} can use it`);
|
|
19939
20152
|
logger.info("run `home-hosted migrate` to see and apply them");
|
|
19940
20153
|
process.exit(1);
|
|
19941
20154
|
}
|
|
20155
|
+
if (settings.configError !== null) {
|
|
20156
|
+
logger.error(`refusing to start: ${settings.configError}`);
|
|
20157
|
+
logger.info(`fix ${settings.path}, or install the release that wrote it`);
|
|
20158
|
+
process.exit(1);
|
|
20159
|
+
}
|
|
19942
20160
|
const registry = new WorkspaceRegistry();
|
|
19943
20161
|
registry.load();
|
|
19944
20162
|
if (registry.configError !== null) {
|
|
@@ -20093,6 +20311,11 @@ async function runControlPlane(options) {
|
|
|
20093
20311
|
});
|
|
20094
20312
|
for (const workspace of panel.workspaces()) {
|
|
20095
20313
|
const store = workspace.store;
|
|
20314
|
+
if (store.pendingMigrations.length > 0) {
|
|
20315
|
+
logger.error(`refusing to start: workspace "${workspace.id}" needs ${store.pendingMigrations.length} migration(s) before ${appVersion()} can use it`);
|
|
20316
|
+
logger.info("run `home-hosted migrate` to see and apply them");
|
|
20317
|
+
process.exit(1);
|
|
20318
|
+
}
|
|
20096
20319
|
if (store.configError !== null) {
|
|
20097
20320
|
logger.error(`refusing to start: workspace "${workspace.id}": ${store.configError}`);
|
|
20098
20321
|
logger.info(`fix ${store.path} and ${store.settingsPath}, or install the release that wrote them`);
|
|
@@ -20103,11 +20326,6 @@ async function runControlPlane(options) {
|
|
|
20103
20326
|
logger.info("fix or restore the file, or move it aside to start fresh — starting fresh discards it");
|
|
20104
20327
|
process.exit(1);
|
|
20105
20328
|
}
|
|
20106
|
-
if (store.pendingMigrations.length > 0) {
|
|
20107
|
-
logger.error(`refusing to start: workspace "${workspace.id}" needs ${store.pendingMigrations.length} migration(s) before ${appVersion()} can use it`);
|
|
20108
|
-
logger.info("run `home-hosted migrate` to see and apply them");
|
|
20109
|
-
process.exit(1);
|
|
20110
|
-
}
|
|
20111
20329
|
}
|
|
20112
20330
|
let shuttingDown = false;
|
|
20113
20331
|
const shutdown = async (reason) => {
|
|
@@ -20985,7 +21203,7 @@ function targets() {
|
|
|
20985
21203
|
validate: (raw) => {
|
|
20986
21204
|
let defaults = {};
|
|
20987
21205
|
try {
|
|
20988
|
-
const settingsRaw = JSON.parse(
|
|
21206
|
+
const settingsRaw = JSON.parse(readStateFile(workspaceSettingsPath(workspace.id)));
|
|
20989
21207
|
const meta = typeof settingsRaw.meta === "object" && settingsRaw.meta !== null ? settingsRaw.meta : {};
|
|
20990
21208
|
const from = typeof meta.schema === "number" ? meta.schema : 1;
|
|
20991
21209
|
defaults = (planConfigMigrations(from).steps.length > 0 ? applyConfigMigrations(settingsRaw, from).config : settingsRaw)?.defaults ?? {};
|
|
@@ -21004,7 +21222,7 @@ async function runMigrate(dryRun, yes) {
|
|
|
21004
21222
|
for (const target of existing) {
|
|
21005
21223
|
let raw;
|
|
21006
21224
|
try {
|
|
21007
|
-
raw = JSON.parse(
|
|
21225
|
+
raw = JSON.parse(readStateFile(target.file));
|
|
21008
21226
|
} catch (error) {
|
|
21009
21227
|
fail(`cannot read ${target.file}: ${errorMessage(error)}`);
|
|
21010
21228
|
}
|
|
@@ -21065,6 +21283,7 @@ var init_migrate = __esmMin((() => {
|
|
|
21065
21283
|
init_parse();
|
|
21066
21284
|
init_workspaces();
|
|
21067
21285
|
init_atomic();
|
|
21286
|
+
init_config_text();
|
|
21068
21287
|
init_paths();
|
|
21069
21288
|
init_version();
|
|
21070
21289
|
init_error_message();
|
|
@@ -21176,6 +21395,23 @@ function detectPackageManager(exists) {
|
|
|
21176
21395
|
function runCommand$1(pm, script) {
|
|
21177
21396
|
return pm === "npm" ? `npm run ${script}` : `${pm} run ${script}`;
|
|
21178
21397
|
}
|
|
21398
|
+
/**
|
|
21399
|
+
* The `cd` that reaches a scaffolded project, quoted for the shell it will be pasted into.
|
|
21400
|
+
*
|
|
21401
|
+
* The directory is the person's choice, and a space in it is ordinary — `C:\Users\Ann Lee`,
|
|
21402
|
+
* `/srv/my apps`, and the default `./my-servers` all sit under one on some machine. Unquoted,
|
|
21403
|
+
* the line `init` printed as its own "Next:" step was `cd my servers && npm run up`, which the
|
|
21404
|
+
* shell answers `cd: too many arguments` — an error naming a command the person did not
|
|
21405
|
+
* compose, on the one line the scaffold exists to hand them.
|
|
21406
|
+
*
|
|
21407
|
+
* POSIX gets single quotes, with an embedded quote closed and reopened (`'\''`), which is the
|
|
21408
|
+
* one form that is safe inside a single-quoted string. Windows' `cmd.exe` has no single-quote
|
|
21409
|
+
* quoting at all, so it gets double quotes: that is what it understands, and a path whose name
|
|
21410
|
+
* contains a `"` is not representable there either way.
|
|
21411
|
+
*/
|
|
21412
|
+
function cdCommand(where) {
|
|
21413
|
+
return `cd ${process.platform === "win32" ? `"${where}"` : `'${where.replace(/'/g, `'\\''`)}'`} && `;
|
|
21414
|
+
}
|
|
21179
21415
|
/** Install arguments for a scaffolded project (the manifest already lists the dependency). */
|
|
21180
21416
|
function installArgs(pm) {
|
|
21181
21417
|
return pm === "yarn" ? [] : ["install"];
|
|
@@ -21248,7 +21484,7 @@ async function runInit(options) {
|
|
|
21248
21484
|
}
|
|
21249
21485
|
const relative = path.relative(process.cwd(), target);
|
|
21250
21486
|
const where = relative.length === 0 || relative.startsWith("..") ? target : relative;
|
|
21251
|
-
const cd = relative.length === 0 ? "" :
|
|
21487
|
+
const cd = relative.length === 0 ? "" : cdCommand(where);
|
|
21252
21488
|
process.stdout.write(`\nNext:\n`);
|
|
21253
21489
|
process.stdout.write(` ${bold(`${cd}${runCommand$1(pm, "up")}`)} start the panel (default password \`hh\`)\n`);
|
|
21254
21490
|
process.stdout.write(` ${dim("then change that password under Settings → Authentication, and add your servers")}\n`);
|
|
@@ -22041,11 +22277,18 @@ function filterEntries(entries, scope, exclude) {
|
|
|
22041
22277
|
* An id that matches nothing is silently ignored by the service, which is right for an archive that
|
|
22042
22278
|
* simply does not carry something — and wrong for a typo: `--exclude global:secret` excludes nothing
|
|
22043
22279
|
* and says nothing, so the archive carries the credentials the person believed they had dropped.
|
|
22280
|
+
*
|
|
22281
|
+
* `action` decides the hint, because the two directions list their ids from different places: a
|
|
22282
|
+
* create plan lists what this host declares, a restore plan lists what the archive holds — and the
|
|
22283
|
+
* command that prints that one is a restore, not a create.
|
|
22044
22284
|
*/
|
|
22045
|
-
function assertKnown(ids, entries, flag) {
|
|
22285
|
+
function assertKnown(ids, entries, flag, action) {
|
|
22046
22286
|
if (ids === void 0) return;
|
|
22047
22287
|
const unknown = unknownBackupIds(ids, entries);
|
|
22048
|
-
if (unknown.length > 0)
|
|
22288
|
+
if (unknown.length > 0) {
|
|
22289
|
+
const hint = action === "create" ? `\`backup create\` with no flags lists the ids` : `\`backup restore <name>\` with no --include/--exclude lists the ids the archive holds`;
|
|
22290
|
+
fail(`${flag} names ${unknown.map((id) => `"${id}"`).join(", ")}, which ${unknown.length === 1 ? "is" : "are"} not in this plan — ${hint}`);
|
|
22291
|
+
}
|
|
22049
22292
|
}
|
|
22050
22293
|
/** `--exclude` parsed. An empty value is a mistake, not "exclude nothing". */
|
|
22051
22294
|
function parseExclude(raw) {
|
|
@@ -22202,8 +22445,8 @@ async function runBackupCreate(options) {
|
|
|
22202
22445
|
await service.warm();
|
|
22203
22446
|
return service.view().entries;
|
|
22204
22447
|
})();
|
|
22205
|
-
assertKnown(options.exclude, entries, "--exclude");
|
|
22206
|
-
assertKnown(scope.kind === "include" ? scope.ids : void 0, entries, "--include");
|
|
22448
|
+
assertKnown(options.exclude, entries, "--exclude", "create");
|
|
22449
|
+
assertKnown(scope.kind === "include" ? scope.ids : void 0, entries, "--include", "create");
|
|
22207
22450
|
const wanted = filterEntries(entries, scope, options.exclude);
|
|
22208
22451
|
if (!options.confirm) {
|
|
22209
22452
|
if (options.json) {
|
|
@@ -22270,6 +22513,32 @@ async function runBackupCreate(options) {
|
|
|
22270
22513
|
async function runningEntries() {
|
|
22271
22514
|
return (await offlineBackup()).runningNow();
|
|
22272
22515
|
}
|
|
22516
|
+
/**
|
|
22517
|
+
* Why a restore plan is not something to apply, or `null`.
|
|
22518
|
+
*
|
|
22519
|
+
* The service answers a plan for every archive, including ones it refuses to read: `error` carries
|
|
22520
|
+
* the refusal and `items` is empty. A caller that reads only `items` sees a tidy empty restore — and
|
|
22521
|
+
* on a blank host, `restored 0 items` printed with exit 0 is the worst possible answer, because
|
|
22522
|
+
* nothing distinguishes "this archive was empty" from "this archive could not be opened".
|
|
22523
|
+
*
|
|
22524
|
+
* `needsPassword` is its own case: it is the one refusal the person can fix from the same command.
|
|
22525
|
+
*/
|
|
22526
|
+
function planRefusal(plan) {
|
|
22527
|
+
if (plan === null) return null;
|
|
22528
|
+
if (plan.needsPassword === true) return `${plan.error ?? "this backup is password-protected"} — add \`--password <text>\` to unlock it`;
|
|
22529
|
+
if (plan.error !== void 0 && plan.error.length > 0) return plan.error;
|
|
22530
|
+
return null;
|
|
22531
|
+
}
|
|
22532
|
+
/**
|
|
22533
|
+
* The plan's refusals and per-item skips, as lines a person can act on.
|
|
22534
|
+
*
|
|
22535
|
+
* `skipped` is the same list the UI draws, and it is the only thing that says a piece of an
|
|
22536
|
+
* otherwise successful restore was left behind — an unreadable `servers.config.json`, a data path
|
|
22537
|
+
* whose declaration changed. Printing only the applied count reported such a restore as complete.
|
|
22538
|
+
*/
|
|
22539
|
+
function restoreNotes(plan) {
|
|
22540
|
+
return plan?.skipped ?? [];
|
|
22541
|
+
}
|
|
22273
22542
|
async function runBackupRestore(options) {
|
|
22274
22543
|
const scope = options.scope;
|
|
22275
22544
|
const service = await usesPanel() ? null : (await offlineBackup()).service;
|
|
@@ -22277,7 +22546,7 @@ async function runBackupRestore(options) {
|
|
|
22277
22546
|
const plan = await (async () => {
|
|
22278
22547
|
if (service !== null) {
|
|
22279
22548
|
const archive = service.resolve(options.name);
|
|
22280
|
-
if (archive === null) fail(`no backup named "${options.name}" — \`${invocation()} backup list\` shows
|
|
22549
|
+
if (archive === null) fail(`no backup named "${options.name}" in ${service.directory} — a restore takes the archive's file name, not a path; copy it there first (\`${invocation()} backup list\` shows what is there)`);
|
|
22281
22550
|
return await service.restore(archive, {
|
|
22282
22551
|
confirm: false,
|
|
22283
22552
|
password: options.password,
|
|
@@ -22287,33 +22556,43 @@ async function runBackupRestore(options) {
|
|
|
22287
22556
|
}
|
|
22288
22557
|
const runtime = await livePanel();
|
|
22289
22558
|
if (runtime === null) fail(`the control panel is not answering — try again once it is up`);
|
|
22290
|
-
const base =
|
|
22291
|
-
if (options.password !== void 0 && options.password.length > 0) base.set("password", options.password);
|
|
22292
|
-
if (scope.kind === "include") base.set("include", scope.ids.join(","));
|
|
22293
|
-
if (options.exclude !== void 0) base.set("exclude", options.exclude.join(","));
|
|
22559
|
+
const base = restoreQuery(options, scope);
|
|
22294
22560
|
const answer = await runtime.request(runtime, `/_hh/backups/restore${suffixOf(base)}`, 12e4);
|
|
22295
22561
|
if (answer === null) fail(`the control panel is not answering at ${runtime.probeUrl}`);
|
|
22296
22562
|
if (answer.status !== 200) refusal(answer);
|
|
22297
22563
|
return answer.body;
|
|
22298
22564
|
})();
|
|
22565
|
+
const refused = planRefusal(plan);
|
|
22566
|
+
if (refused !== null) {
|
|
22567
|
+
if (options.json) process.stdout.write(`${JSON.stringify({
|
|
22568
|
+
action: "restore",
|
|
22569
|
+
apply: false,
|
|
22570
|
+
name: options.name,
|
|
22571
|
+
error: refused
|
|
22572
|
+
}, null, 2)}\n`);
|
|
22573
|
+
fail(refused);
|
|
22574
|
+
}
|
|
22299
22575
|
const items = (plan?.items ?? []).filter((item) => item.selected !== false);
|
|
22576
|
+
const archiveItems = plan?.items ?? [];
|
|
22577
|
+
if (options.exclude !== void 0) assertKnown(options.exclude, archiveItems, "--exclude", "restore");
|
|
22578
|
+
if (scope.kind === "include") assertKnown(scope.ids, archiveItems, "--include", "restore");
|
|
22300
22579
|
if (options.json && !options.confirm) {
|
|
22301
22580
|
process.stdout.write(`${JSON.stringify({
|
|
22302
22581
|
action: "restore",
|
|
22303
22582
|
apply: false,
|
|
22304
22583
|
name: options.name,
|
|
22305
22584
|
items,
|
|
22306
|
-
|
|
22585
|
+
skipped: restoreNotes(plan)
|
|
22307
22586
|
}, null, 2)}\n`);
|
|
22308
22587
|
return;
|
|
22309
22588
|
}
|
|
22310
22589
|
if (!options.json) {
|
|
22311
|
-
process.stdout.write(`${bold("Plan")} for ${options.name} — nothing has been written yet\n`);
|
|
22590
|
+
process.stdout.write(options.confirm ? `${bold("Plan")} for ${options.name} — applying it now\n` : `${bold("Plan")} for ${options.name} — nothing has been written yet\n`);
|
|
22312
22591
|
printPlanTree(items.map((item) => ({
|
|
22313
22592
|
id: item.id,
|
|
22314
22593
|
note: item.note ?? null
|
|
22315
22594
|
})));
|
|
22316
|
-
for (const
|
|
22595
|
+
if (!options.confirm) for (const note of restoreNotes(plan)) process.stdout.write(` ${dim("!")} ${note}\n`);
|
|
22317
22596
|
if (items.length === 0) {
|
|
22318
22597
|
process.stdout.write(" (nothing to restore — check --include, or what this host declares)\n");
|
|
22319
22598
|
return;
|
|
@@ -22331,43 +22610,72 @@ async function runBackupRestore(options) {
|
|
|
22331
22610
|
exclude: options.exclude
|
|
22332
22611
|
});
|
|
22333
22612
|
return {
|
|
22334
|
-
|
|
22335
|
-
|
|
22613
|
+
...result,
|
|
22614
|
+
items: (result.items ?? []).filter((item) => item.selected !== false)
|
|
22336
22615
|
};
|
|
22337
22616
|
}
|
|
22338
22617
|
const runtime = await livePanel();
|
|
22339
22618
|
if (runtime === null) fail("the control panel stopped answering — nothing further was written");
|
|
22340
|
-
const base =
|
|
22341
|
-
if (options.password !== void 0 && options.password.length > 0) base.set("password", options.password);
|
|
22342
|
-
if (scope.kind === "include") base.set("include", scope.ids.join(","));
|
|
22343
|
-
if (options.exclude !== void 0) base.set("exclude", options.exclude.join(","));
|
|
22619
|
+
const base = restoreQuery(options, scope);
|
|
22344
22620
|
const answer = await runtime.request(runtime, `/_hh/backups/restore${withParam(suffixOf(base), "confirm", "true")}`, 6e5);
|
|
22345
22621
|
if (answer === null) fail(`the control panel is not answering at ${runtime.probeUrl}`);
|
|
22346
22622
|
if (answer.status !== 200) refusal(answer);
|
|
22347
22623
|
const result = answer.body;
|
|
22348
22624
|
return {
|
|
22625
|
+
...result,
|
|
22349
22626
|
items: (result?.items ?? plan?.items ?? []).filter((item) => item.selected !== false),
|
|
22350
|
-
|
|
22627
|
+
...result?.hooks === void 0 && plan?.hooks !== void 0 ? { hooks: plan.hooks } : {}
|
|
22351
22628
|
};
|
|
22352
22629
|
})();
|
|
22353
|
-
const
|
|
22630
|
+
const applyRefused = planRefusal(outcome);
|
|
22631
|
+
if (applyRefused !== null) {
|
|
22632
|
+
if (options.json) process.stdout.write(`${JSON.stringify({
|
|
22633
|
+
action: "restore",
|
|
22634
|
+
apply: true,
|
|
22635
|
+
name: options.name,
|
|
22636
|
+
error: applyRefused
|
|
22637
|
+
}, null, 2)}\n`);
|
|
22638
|
+
fail(applyRefused);
|
|
22639
|
+
}
|
|
22640
|
+
const applied = (outcome.items ?? []).filter((item) => item.selected !== false);
|
|
22641
|
+
const hooks = (outcome.hooks ?? []).filter((hook) => hook.action === "load");
|
|
22642
|
+
const notes = restoreNotes(plan);
|
|
22354
22643
|
if (options.json) {
|
|
22355
22644
|
process.stdout.write(`${JSON.stringify({
|
|
22356
22645
|
action: "restore",
|
|
22357
22646
|
apply: true,
|
|
22358
22647
|
name: options.name,
|
|
22359
22648
|
items: applied,
|
|
22360
|
-
hooks
|
|
22361
|
-
|
|
22649
|
+
hooks,
|
|
22650
|
+
skipped: notes,
|
|
22651
|
+
...outcome.restartRequired === true ? { restartRequired: true } : {},
|
|
22652
|
+
...(outcome.createdWorkspaces ?? []).length === 0 ? {} : { createdWorkspaces: outcome.createdWorkspaces },
|
|
22653
|
+
...(outcome.replacedUnderRunning ?? []).length === 0 ? {} : { replacedUnderRunning: outcome.replacedUnderRunning }
|
|
22362
22654
|
}, null, 2)}\n`);
|
|
22363
22655
|
return;
|
|
22364
22656
|
}
|
|
22365
|
-
process.stdout.write(`${green("restored")}
|
|
22366
|
-
|
|
22367
|
-
for (const
|
|
22657
|
+
if (applied.length === 0) process.stdout.write(`${green("restored")} nothing — the archive carried no item this host can take\n`);
|
|
22658
|
+
else process.stdout.write(`${green("restored")} ${applied.length} ${applied.length === 1 ? "item" : "items"} from ${options.name}\n`);
|
|
22659
|
+
for (const hook of hooks) process.stdout.write(` ${dim(`load ${hook.serverId}: ${hook.output ?? "staged"}`)}\n`);
|
|
22660
|
+
for (const note of notes) process.stdout.write(` ${dim("!")} ${note}\n`);
|
|
22661
|
+
if (outcome.restartRequired === true) process.stdout.write(` ${dim(`! the panel's listener changed — restart it so it binds where the archive says (\`${invocation()} restart\`)`)}\n`);
|
|
22662
|
+
if ((outcome.createdWorkspaces ?? []).length > 0) process.stdout.write(` ${dim(`! created ${outcome.createdWorkspaces.join(", ")}, which this host did not have`)}\n`);
|
|
22368
22663
|
if (service !== null) process.stdout.write(dim(`the panel is not running, so nothing was reloaded — the next \`${invocation()} up\` reads what was restored\n`));
|
|
22369
22664
|
}
|
|
22370
22665
|
}
|
|
22666
|
+
/**
|
|
22667
|
+
* The restore query both the plan and the apply send.
|
|
22668
|
+
*
|
|
22669
|
+
* One builder, because the two requests must agree: a password or a selection on the plan and not on
|
|
22670
|
+
* the apply made the apply answer about different items than the person approved.
|
|
22671
|
+
*/
|
|
22672
|
+
function restoreQuery(options, scope) {
|
|
22673
|
+
const base = new URLSearchParams({ name: options.name });
|
|
22674
|
+
if (options.password !== void 0 && options.password.length > 0) base.set("password", options.password);
|
|
22675
|
+
if (scope.kind === "include") base.set("include", scope.ids.join(","));
|
|
22676
|
+
if (options.exclude !== void 0) base.set("exclude", options.exclude.join(","));
|
|
22677
|
+
return base;
|
|
22678
|
+
}
|
|
22371
22679
|
var backupCommand;
|
|
22372
22680
|
var init_backup = __esmMin((() => {
|
|
22373
22681
|
init_backup_offline();
|
|
@@ -22548,7 +22856,7 @@ async function runNanny(spec, statePath) {
|
|
|
22548
22856
|
};
|
|
22549
22857
|
child.once("exit", (code, signal) => finish(code, signal, Date.now() - startedAt));
|
|
22550
22858
|
child.once("error", (error) => {
|
|
22551
|
-
finish(null, null, 0, `persistent: could not start the entry: ${error.
|
|
22859
|
+
finish(null, null, 0, `persistent: could not start the entry: ${describeSpawnError(error, spec.command, spec.cwd)}`);
|
|
22552
22860
|
});
|
|
22553
22861
|
});
|
|
22554
22862
|
process.exit(exitCode);
|