home-hosted 0.9.4 → 0.9.5
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/README.md +3 -1
- package/dist/cli.js +280 -29
- package/dist/cli.js.map +1 -1
- package/docs/RESTORE_DEMO.md +128 -0
- package/docs/UI_CREATION.md +1 -1
- package/docs/demo/blank-host-restore.sh +192 -0
- package/package.json +3 -1
- package/uis/stock/dist/ui.json +2 -2
package/README.md
CHANGED
|
@@ -84,7 +84,8 @@ environment you give it. A preset can fill that in for you, and you can change e
|
|
|
84
84
|
|
|
85
85
|
<sub>Manage them from the panel, `home-hosted start|stop <id>` from a shell, `home-hosted status --json`,
|
|
86
86
|
or `GET /api/state`; `GET /healthz` is the same status line for your own monitor, no session needed —
|
|
87
|
-
`503` when a server has crashed
|
|
87
|
+
`503` when a server has crashed, when the panel stopped one because it could not serve, or while
|
|
88
|
+
a running one is failing its health check.</sub>
|
|
88
89
|
|
|
89
90
|
---
|
|
90
91
|
|
|
@@ -355,6 +356,7 @@ restarts itself), and how hand-edits are validated: [SERVERS.md](./docs/SERVERS.
|
|
|
355
356
|
| `home-hosted stop <id>` | stop one server, nothing else (`--workspace <id>`) |
|
|
356
357
|
| `home-hosted restart <id>` | restart one server, nothing else (`--workspace <id>`) — the same as the panel's per-server Restart |
|
|
357
358
|
| `home-hosted logs` | read the panel's own console output — the file `up` redirects it into (`--lines`, `--follow`, `--json`) |
|
|
359
|
+
| `home-hosted backup` | list, create or restore an archive without a browser (`create`, `restore <name> --confirm`, `--password`, `--include`) — see [RESTORE_DEMO.md](./docs/RESTORE_DEMO.md) |
|
|
358
360
|
| `home-hosted set-password` | set the panel password without opening a browser; a running panel picks it up at once and signs every existing session out |
|
|
359
361
|
| `home-hosted set-token` | set the API token scripts and agents use (`--generate`, `--clear`) |
|
|
360
362
|
| `home-hosted migrate` | bring every config up to the schema this release understands (`--dry-run`, `--yes`) |
|
package/dist/cli.js
CHANGED
|
@@ -4057,6 +4057,77 @@ function createControlRoute(deps) {
|
|
|
4057
4057
|
assertLocalCall(c, "restart a server");
|
|
4058
4058
|
const result = await requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace).supervisor.restart(c.req.param("id"), { actor: "user" });
|
|
4059
4059
|
return c.json(result, statusForAction(result));
|
|
4060
|
+
}).get("/backups", describeRoute({
|
|
4061
|
+
tags: ["panel"],
|
|
4062
|
+
summary: "List the stored backup archives (local token required)",
|
|
4063
|
+
responses: {
|
|
4064
|
+
200: {
|
|
4065
|
+
description: "The archives",
|
|
4066
|
+
content: jsonBody(backupsViewSchema)
|
|
4067
|
+
},
|
|
4068
|
+
403: { description: "Bad token, or not a local caller" }
|
|
4069
|
+
}
|
|
4070
|
+
}), (c) => {
|
|
4071
|
+
assertLocalCall(c, "list backups");
|
|
4072
|
+
return c.json(buildBackupsView(deps.backups));
|
|
4073
|
+
}).post("/backups", describeRoute({
|
|
4074
|
+
tags: ["panel"],
|
|
4075
|
+
summary: "Create a backup archive (local token required)",
|
|
4076
|
+
responses: {
|
|
4077
|
+
200: {
|
|
4078
|
+
description: "Created",
|
|
4079
|
+
content: jsonBody(backupCreatedResponseSchema)
|
|
4080
|
+
},
|
|
4081
|
+
400: ERROR_RESPONSES[400],
|
|
4082
|
+
403: { description: "Bad token, or not a local caller" }
|
|
4083
|
+
}
|
|
4084
|
+
}), async (c) => {
|
|
4085
|
+
assertLocalCall(c, "create a backup");
|
|
4086
|
+
const password = c.req.query("password");
|
|
4087
|
+
const include = c.req.query("include")?.split(",").filter((part) => part.length > 0);
|
|
4088
|
+
const result = await deps.backups.create({
|
|
4089
|
+
password,
|
|
4090
|
+
include
|
|
4091
|
+
});
|
|
4092
|
+
if (!result.ok) throw new DetailedError(result.error ?? "the backup failed", {
|
|
4093
|
+
statusCode: 400,
|
|
4094
|
+
code: "BACKUP_FAILED"
|
|
4095
|
+
});
|
|
4096
|
+
return c.json({
|
|
4097
|
+
file: result.file,
|
|
4098
|
+
files: deps.backups.list()
|
|
4099
|
+
});
|
|
4100
|
+
}).post("/backups/restore", describeRoute({
|
|
4101
|
+
tags: ["panel"],
|
|
4102
|
+
summary: "Plan or apply a restore from a stored archive (local token required)",
|
|
4103
|
+
responses: {
|
|
4104
|
+
200: {
|
|
4105
|
+
description: "The plan",
|
|
4106
|
+
content: jsonBody(restorePlanSchema)
|
|
4107
|
+
},
|
|
4108
|
+
400: ERROR_RESPONSES[400],
|
|
4109
|
+
403: { description: "Bad token, or not a local caller" },
|
|
4110
|
+
404: ERROR_RESPONSES[404]
|
|
4111
|
+
}
|
|
4112
|
+
}), async (c) => {
|
|
4113
|
+
assertLocalCall(c, "restore a backup");
|
|
4114
|
+
const confirm = c.req.query("confirm") === "true";
|
|
4115
|
+
const name = c.req.query("name");
|
|
4116
|
+
if (name === void 0 || name.length === 0) throw new DetailedError("name is required", {
|
|
4117
|
+
statusCode: 400,
|
|
4118
|
+
code: "MISSING_NAME"
|
|
4119
|
+
});
|
|
4120
|
+
const archive = deps.backups.resolve(name);
|
|
4121
|
+
if (archive === null) throw new DetailedError(`no backup named "${name}"`, {
|
|
4122
|
+
statusCode: 404,
|
|
4123
|
+
code: "BACKUP_NOT_FOUND"
|
|
4124
|
+
});
|
|
4125
|
+
const include = c.req.query("include")?.split(",").filter((part) => part.length > 0);
|
|
4126
|
+
return c.json(await deps.backups.restore(archive, {
|
|
4127
|
+
confirm,
|
|
4128
|
+
password: c.req.query("password"),
|
|
4129
|
+
include
|
|
4130
|
+
}));
|
|
4060
4131
|
});
|
|
4061
4132
|
}
|
|
4062
4133
|
var init_control = __esmMin((() => {
|
|
@@ -4069,6 +4140,7 @@ var init_control = __esmMin((() => {
|
|
|
4069
4140
|
init_validator();
|
|
4070
4141
|
init_workspace();
|
|
4071
4142
|
init_loopback();
|
|
4143
|
+
init_state$1();
|
|
4072
4144
|
init_contracts();
|
|
4073
4145
|
}));
|
|
4074
4146
|
//#endregion
|
|
@@ -7094,9 +7166,9 @@ var init_events = __esmMin((() => {
|
|
|
7094
7166
|
//#region src/api/health.ts
|
|
7095
7167
|
/**
|
|
7096
7168
|
* Liveness for external monitors. Mounted outside `/api`, so it answers without a
|
|
7097
|
-
* session: it reports whether the panel itself is serving, and 503 when any server
|
|
7098
|
-
*
|
|
7099
|
-
* only included for an authenticated caller.
|
|
7169
|
+
* session: it reports whether the panel itself is serving, and 503 when any server has crashed,
|
|
7170
|
+
* when the panel stopped one because it could not serve, or while a running one is failing its own
|
|
7171
|
+
* health check. Server details are only included for an authenticated caller.
|
|
7100
7172
|
*/
|
|
7101
7173
|
function createHealthRoute(deps) {
|
|
7102
7174
|
return appFactory.createApp().get("/healthz", describeRoute({
|
|
@@ -7107,7 +7179,7 @@ function createHealthRoute(deps) {
|
|
|
7107
7179
|
description: "Serving",
|
|
7108
7180
|
content: jsonBody(healthResponseSchema)
|
|
7109
7181
|
},
|
|
7110
|
-
503: { description: "A server
|
|
7182
|
+
503: { description: "A server crashed, or the panel stopped one that could not serve, or a running one is unhealthy" }
|
|
7111
7183
|
}
|
|
7112
7184
|
}), (c) => {
|
|
7113
7185
|
const state = deps.panel.getState();
|
|
@@ -8616,18 +8688,6 @@ var init_proxy$2 = __esmMin((() => {
|
|
|
8616
8688
|
//#endregion
|
|
8617
8689
|
//#region src/services/proxy-config.ts
|
|
8618
8690
|
/**
|
|
8619
|
-
* The issuers for the public names: ACME with the account address, then the engine's
|
|
8620
|
-
* own CA as a last resort.
|
|
8621
|
-
*
|
|
8622
|
-
* The fallback is what keeps a missing certificate from being a dead connection: the
|
|
8623
|
-
* handshake completes with an untrusted certificate (the browser offers to continue),
|
|
8624
|
-
* instead of failing with a protocol error the visitor cannot read past. The engine
|
|
8625
|
-
* keeps trying ACME, and the panel reports which of the two is being served.
|
|
8626
|
-
*
|
|
8627
|
-
* ZeroSSL is deliberately absent: it needs an EAB key the panel does not collect, so
|
|
8628
|
-
* listing it only added a failing issuer and a second retry on every name.
|
|
8629
|
-
*/
|
|
8630
|
-
/**
|
|
8631
8691
|
* The DNS-01 challenge block, which names the panel as the one that answers it. The
|
|
8632
8692
|
* engine holds no DNS credentials: it asks the panel over the ACMEProxy protocol, and
|
|
8633
8693
|
* the panel writes the record through the workspace account the route names.
|
|
@@ -8643,6 +8703,18 @@ function challengeBlock(dns01) {
|
|
|
8643
8703
|
...dns01.resolvers.length > 0 ? { resolvers: dns01.resolvers } : {}
|
|
8644
8704
|
} } };
|
|
8645
8705
|
}
|
|
8706
|
+
/**
|
|
8707
|
+
* The issuers for the public names: ACME with the account address, then the engine's
|
|
8708
|
+
* own CA as a last resort.
|
|
8709
|
+
*
|
|
8710
|
+
* The fallback is what keeps a missing certificate from being a dead connection: the
|
|
8711
|
+
* handshake completes with an untrusted certificate (the browser offers to continue),
|
|
8712
|
+
* instead of failing with a protocol error the visitor cannot read past. The engine
|
|
8713
|
+
* keeps trying ACME, and the panel reports which of the two is being served.
|
|
8714
|
+
*
|
|
8715
|
+
* ZeroSSL is deliberately absent: it needs an EAB key the panel does not collect, so
|
|
8716
|
+
* listing it only added a failing issuer and a second retry on every name.
|
|
8717
|
+
*/
|
|
8646
8718
|
function acmeIssuers(acme, challenge = {}) {
|
|
8647
8719
|
return [{
|
|
8648
8720
|
module: "acme",
|
|
@@ -9793,7 +9865,6 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9793
9865
|
logger.error(`proxy: could not start: ${this.lastError}`);
|
|
9794
9866
|
}
|
|
9795
9867
|
}
|
|
9796
|
-
/** True when a nanny this panel would recognise still owns the engine. */
|
|
9797
9868
|
/**
|
|
9798
9869
|
* True while a process from the installed binary is alive, however the panel's view
|
|
9799
9870
|
* reads. `live()` additionally requires a fresh heartbeat, so a nanny that died and
|
|
@@ -9821,9 +9892,12 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9821
9892
|
};
|
|
9822
9893
|
if (!config.enabled) return base;
|
|
9823
9894
|
const applied = this.readApplied();
|
|
9824
|
-
const
|
|
9825
|
-
const
|
|
9826
|
-
const
|
|
9895
|
+
const boundPortsNow = (port, configured) => port === void 0 ? configured : port;
|
|
9896
|
+
const urls = [];
|
|
9897
|
+
const httpPort = boundPortsNow(applied === null ? void 0 : applied.httpPort, config.httpPort);
|
|
9898
|
+
if (httpPort !== null) urls.push(`http://127.0.0.1:${httpPort}`);
|
|
9899
|
+
const httpsPort = boundPortsNow(applied === null ? void 0 : applied.httpsPort, config.httpsPort);
|
|
9900
|
+
if (httpsPort !== null) urls.push(`https://127.0.0.1:${httpsPort}`);
|
|
9827
9901
|
const certExpiryDays = this.certificateExpiryDays();
|
|
9828
9902
|
if (!this.installed()) return {
|
|
9829
9903
|
...base,
|
|
@@ -9881,11 +9955,11 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9881
9955
|
lastError: this.lastError
|
|
9882
9956
|
};
|
|
9883
9957
|
}
|
|
9884
|
-
/** Records why the last start or apply failed, for the frame the page reads. */
|
|
9885
9958
|
/** Backoff for a failing `sync()` re-apply; see the retry notes there. */
|
|
9886
9959
|
nextSyncAttemptAt = 0;
|
|
9887
9960
|
syncFailures = 0;
|
|
9888
9961
|
lastSyncError = null;
|
|
9962
|
+
/** Records why the last start or apply failed, for the frame the page reads. */
|
|
9889
9963
|
recordError(message) {
|
|
9890
9964
|
this.lastError = message;
|
|
9891
9965
|
this.options.onStateChange();
|
|
@@ -9895,7 +9969,6 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9895
9969
|
this.options.onStateChange();
|
|
9896
9970
|
return config;
|
|
9897
9971
|
}
|
|
9898
|
-
/** Renders the current route table and applies it; the engine keeps serving on failure. */
|
|
9899
9972
|
/**
|
|
9900
9973
|
* Makes the engine ask the CA again for one name, without restarting it.
|
|
9901
9974
|
*
|
|
@@ -9955,6 +10028,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9955
10028
|
});
|
|
9956
10029
|
}
|
|
9957
10030
|
}
|
|
10031
|
+
/** Renders the current route table and applies it; the engine keeps serving on failure. */
|
|
9958
10032
|
async apply(options = {}) {
|
|
9959
10033
|
if (!this.config.enabled || !this.installed()) return;
|
|
9960
10034
|
await this.assertDns01Module();
|
|
@@ -9972,8 +10046,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9972
10046
|
await this.assertPortsFree(this.config.httpPort, this.config.httpsPort);
|
|
9973
10047
|
await this.postConfiguration(rendered);
|
|
9974
10048
|
this.rememberConfig(text);
|
|
9975
|
-
|
|
9976
|
-
this.rememberApplied(bound.includes(this.config.httpPort) ? this.config.httpPort : null, bound.includes(this.config.httpsPort) ? this.config.httpsPort : null);
|
|
10049
|
+
this.recordApplied(rendered);
|
|
9977
10050
|
const swept = this.sweepUnroutedCertificates();
|
|
9978
10051
|
if (swept > 0) logger.info(`proxy: dropped ${swept} certificate(s) for names no longer routed`);
|
|
9979
10052
|
this.lastError = null;
|
|
@@ -10062,6 +10135,19 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10062
10135
|
return null;
|
|
10063
10136
|
}
|
|
10064
10137
|
}
|
|
10138
|
+
/**
|
|
10139
|
+
* Records what the engine is now bound to, derived from the document it was given.
|
|
10140
|
+
*
|
|
10141
|
+
* One implementation for both write sites (`apply()` and `start()`): a `tls: 'off'`-only table
|
|
10142
|
+
* binds no HTTPS listener, and a table with nothing servable binds neither, so a configured port
|
|
10143
|
+
* the document did not bind is recorded as `null` rather than claimed. The preflight reads this
|
|
10144
|
+
* record as its witness, so a wrong number here admits a stranger standing on that port.
|
|
10145
|
+
*/
|
|
10146
|
+
recordApplied(rendered) {
|
|
10147
|
+
const bound = boundPorts(rendered);
|
|
10148
|
+
const config = this.config;
|
|
10149
|
+
this.rememberApplied(bound.includes(config.httpPort) ? config.httpPort : null, bound.includes(config.httpsPort) ? config.httpsPort : null);
|
|
10150
|
+
}
|
|
10065
10151
|
rememberApplied(httpPort, httpsPort) {
|
|
10066
10152
|
writeFileAtomic(path.join(this.options.stateDir, "applied.json"), `${JSON.stringify({
|
|
10067
10153
|
httpPort,
|
|
@@ -10124,8 +10210,10 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10124
10210
|
});
|
|
10125
10211
|
const current = fs.existsSync(this.options.configPath) ? fs.readFileSync(this.options.configPath, "utf8") : null;
|
|
10126
10212
|
const previous = fs.readFileSync(this.options.previousConfigPath, "utf8");
|
|
10127
|
-
|
|
10213
|
+
const restored = JSON.parse(previous);
|
|
10214
|
+
await this.postConfiguration(restored);
|
|
10128
10215
|
writeFileAtomic(this.options.configPath, previous, { mode: 384 });
|
|
10216
|
+
this.recordApplied(restored);
|
|
10129
10217
|
if (current === null) fs.rmSync(this.options.previousConfigPath, { force: true });
|
|
10130
10218
|
else writeFileAtomic(this.options.previousConfigPath, current, { mode: 384 });
|
|
10131
10219
|
this.lastError = null;
|
|
@@ -10634,7 +10722,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10634
10722
|
code: "ENGINE_NOT_READY"
|
|
10635
10723
|
});
|
|
10636
10724
|
}
|
|
10637
|
-
this.
|
|
10725
|
+
this.recordApplied(rendered);
|
|
10638
10726
|
this.lastError = null;
|
|
10639
10727
|
logger.info(`proxy: ${this.engine.info.label} serving on :${this.config.httpPort} and :${this.config.httpsPort}`);
|
|
10640
10728
|
this.options.onStateChange();
|
|
@@ -12234,8 +12322,8 @@ async function requestShutdown(runtime, timeoutMs = 4e3) {
|
|
|
12234
12322
|
* The wait is generous on purpose: a start may have to run a bootstrap, which has a
|
|
12235
12323
|
* 120s default timeout of its own. Past this it is a wedged panel, not a slow one.
|
|
12236
12324
|
*/
|
|
12237
|
-
async function requestControl(runtime, path, timeoutMs = 15e4) {
|
|
12238
|
-
const answer = await localCall(runtime, path,
|
|
12325
|
+
async function requestControl(runtime, path, timeoutMs = 15e4, method = "POST") {
|
|
12326
|
+
const answer = await localCall(runtime, path, method, runtime.token, timeoutMs);
|
|
12239
12327
|
if (answer === null) return null;
|
|
12240
12328
|
let body = null;
|
|
12241
12329
|
try {
|
|
@@ -13771,6 +13859,11 @@ var init_supervisor = __esmMin((() => {
|
|
|
13771
13859
|
error: `docker could not stop the container "${docker.container}" publishing port ${port} — check \`docker logs ${docker.container}\``
|
|
13772
13860
|
};
|
|
13773
13861
|
}
|
|
13862
|
+
if (!await this.waitForPortRelease(entry, port)) return {
|
|
13863
|
+
...empty,
|
|
13864
|
+
port,
|
|
13865
|
+
error: `port ${port} is still in use, but no listener could be attributed to it — this user cannot inspect that socket, so it cannot be freed from here`
|
|
13866
|
+
};
|
|
13774
13867
|
return {
|
|
13775
13868
|
...empty,
|
|
13776
13869
|
port,
|
|
@@ -20878,6 +20971,149 @@ var init_ui_revert = __esmMin((() => {
|
|
|
20878
20971
|
});
|
|
20879
20972
|
}));
|
|
20880
20973
|
//#endregion
|
|
20974
|
+
//#region src/cli/backup.ts
|
|
20975
|
+
var backup_exports = /* @__PURE__ */ __exportAll({
|
|
20976
|
+
backupCommand: () => backupCommand,
|
|
20977
|
+
runBackupCreate: () => runBackupCreate,
|
|
20978
|
+
runBackupList: () => runBackupList,
|
|
20979
|
+
runBackupRestore: () => runBackupRestore
|
|
20980
|
+
});
|
|
20981
|
+
function human(bytes) {
|
|
20982
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
20983
|
+
if (bytes < 1048576) return `${Math.round(bytes / 1024)} KB`;
|
|
20984
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
20985
|
+
}
|
|
20986
|
+
/** The running panel's record, or a message saying what to do instead. */
|
|
20987
|
+
async function livePanel() {
|
|
20988
|
+
const daemon = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
|
|
20989
|
+
const runtime = daemon.readRuntime();
|
|
20990
|
+
if (runtime === null || !await daemon.runtimeIsAlive(runtime)) {
|
|
20991
|
+
if (runtime !== null && await daemon.runtimeIsGone(runtime)) daemon.clearRuntime();
|
|
20992
|
+
fail(`home-hosted is not running — start it with \`${invocation()} up\`, then run this again`);
|
|
20993
|
+
}
|
|
20994
|
+
return Object.assign(runtime, { request: daemon.requestControl });
|
|
20995
|
+
}
|
|
20996
|
+
/** Turn a non-200 control answer into the panel's own message, or the status. */
|
|
20997
|
+
function refusal(answer) {
|
|
20998
|
+
const body = answer.body;
|
|
20999
|
+
if (body?.message !== void 0) fail(body.message);
|
|
21000
|
+
fail(`the panel answered ${answer.status}`);
|
|
21001
|
+
}
|
|
21002
|
+
async function runBackupList(json) {
|
|
21003
|
+
const runtime = await livePanel();
|
|
21004
|
+
const answer = await runtime.request(runtime, "/_hh/backups", 3e4, "GET");
|
|
21005
|
+
if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
|
|
21006
|
+
if (answer.status !== 200) refusal(answer);
|
|
21007
|
+
const view = answer.body;
|
|
21008
|
+
const files = view?.files ?? [];
|
|
21009
|
+
if (json) {
|
|
21010
|
+
process.stdout.write(`${JSON.stringify(view, null, 2)}\n`);
|
|
21011
|
+
return;
|
|
21012
|
+
}
|
|
21013
|
+
if (files.length === 0) {
|
|
21014
|
+
process.stdout.write(`no backups yet — \`${invocation()} backup create\` takes one\n`);
|
|
21015
|
+
return;
|
|
21016
|
+
}
|
|
21017
|
+
const noun = files.length === 1 ? "archive" : "archives";
|
|
21018
|
+
process.stdout.write(`${bold(String(files.length))} ${noun}${view?.dir === void 0 ? "" : ` in ${dim(view.dir)}`}\n`);
|
|
21019
|
+
for (const file of files) {
|
|
21020
|
+
const when = file.createdAt === null ? "" : new Date(file.createdAt).toISOString().replace("T", " ").slice(0, 16);
|
|
21021
|
+
process.stdout.write(` ${file.name.padEnd(36)} ${human(file.sizeBytes).padStart(8)} ${dim(when)}${file.automatic ? dim(" auto") : ""}\n`);
|
|
21022
|
+
}
|
|
21023
|
+
}
|
|
21024
|
+
async function runBackupCreate(options) {
|
|
21025
|
+
const runtime = await livePanel();
|
|
21026
|
+
const query = new URLSearchParams();
|
|
21027
|
+
if (options.password !== void 0 && options.password.length > 0) query.set("password", options.password);
|
|
21028
|
+
if (options.include !== void 0 && options.include.length > 0) query.set("include", options.include.join(","));
|
|
21029
|
+
const suffix = query.size === 0 ? "" : `?${query.toString()}`;
|
|
21030
|
+
const answer = await runtime.request(runtime, `/_hh/backups${suffix}`, 6e5);
|
|
21031
|
+
if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
|
|
21032
|
+
if (answer.status !== 200) refusal(answer);
|
|
21033
|
+
const file = answer.body?.file;
|
|
21034
|
+
if (file === void 0) fail("the panel reported success but named no archive");
|
|
21035
|
+
process.stdout.write(`${green("backup created")} ${file.name} ${dim(`(${human(file.sizeBytes)})`)}\n`);
|
|
21036
|
+
}
|
|
21037
|
+
async function runBackupRestore(options) {
|
|
21038
|
+
const runtime = await livePanel();
|
|
21039
|
+
const query = new URLSearchParams({ name: options.name });
|
|
21040
|
+
if (options.password !== void 0 && options.password.length > 0) query.set("password", options.password);
|
|
21041
|
+
if (options.include !== void 0 && options.include.length > 0) query.set("include", options.include.join(","));
|
|
21042
|
+
if (options.confirm) query.set("confirm", "true");
|
|
21043
|
+
const answer = await runtime.request(runtime, `/_hh/backups/restore?${query.toString()}`, 6e5);
|
|
21044
|
+
if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
|
|
21045
|
+
if (answer.status !== 200) refusal(answer);
|
|
21046
|
+
const plan = answer.body;
|
|
21047
|
+
const items = plan?.items ?? [];
|
|
21048
|
+
if (!options.confirm) {
|
|
21049
|
+
process.stdout.write(`${bold("Plan")} for ${options.name} — nothing has been written yet\n`);
|
|
21050
|
+
for (const item of items) process.stdout.write(` ${item.kind.padEnd(10)} ${item.id}\n`);
|
|
21051
|
+
for (const warning of plan?.warnings ?? []) process.stdout.write(` ${dim("!")} ${warning}\n`);
|
|
21052
|
+
process.stdout.write(`\napply it with \`${invocation()} backup restore ${options.name} --confirm\`\n`);
|
|
21053
|
+
return;
|
|
21054
|
+
}
|
|
21055
|
+
process.stdout.write(`${green("restored")} ${items.length} ${items.length === 1 ? "item" : "items"} from ${options.name}\n`);
|
|
21056
|
+
for (const warning of plan?.warnings ?? []) process.stdout.write(` ${dim("!")} ${warning}\n`);
|
|
21057
|
+
}
|
|
21058
|
+
var backupCommand;
|
|
21059
|
+
var init_backup = __esmMin((() => {
|
|
21060
|
+
init_io();
|
|
21061
|
+
init_error_message();
|
|
21062
|
+
backupCommand = defineCommand({
|
|
21063
|
+
meta: { name: "backup" },
|
|
21064
|
+
args: {
|
|
21065
|
+
action: {
|
|
21066
|
+
type: "positional",
|
|
21067
|
+
description: "list (default) | create | restore",
|
|
21068
|
+
required: false
|
|
21069
|
+
},
|
|
21070
|
+
target: {
|
|
21071
|
+
type: "positional",
|
|
21072
|
+
description: "the archive name, for restore",
|
|
21073
|
+
required: false
|
|
21074
|
+
},
|
|
21075
|
+
password: {
|
|
21076
|
+
type: "string",
|
|
21077
|
+
description: "encrypt the archive, or unlock it on restore"
|
|
21078
|
+
},
|
|
21079
|
+
include: {
|
|
21080
|
+
type: "string",
|
|
21081
|
+
description: "comma-separated item ids to capture, or to restore"
|
|
21082
|
+
},
|
|
21083
|
+
confirm: {
|
|
21084
|
+
type: "boolean",
|
|
21085
|
+
description: "apply a restore instead of only planning it"
|
|
21086
|
+
},
|
|
21087
|
+
json: {
|
|
21088
|
+
type: "boolean",
|
|
21089
|
+
description: "print machine-readable JSON (list)"
|
|
21090
|
+
}
|
|
21091
|
+
},
|
|
21092
|
+
async run({ args }) {
|
|
21093
|
+
try {
|
|
21094
|
+
const include = args.include === void 0 ? void 0 : args.include.split(",").filter((part) => part.length > 0);
|
|
21095
|
+
const action = args.action === void 0 || args.action.length === 0 ? "list" : args.action;
|
|
21096
|
+
if (action === "list") await runBackupList(args.json === true);
|
|
21097
|
+
else if (action === "create") await runBackupCreate({
|
|
21098
|
+
password: args.password,
|
|
21099
|
+
include
|
|
21100
|
+
});
|
|
21101
|
+
else if (action === "restore") {
|
|
21102
|
+
if (args.target === void 0 || args.target.length === 0) fail("restore needs the archive name — `backup list` shows them");
|
|
21103
|
+
await runBackupRestore({
|
|
21104
|
+
name: args.target,
|
|
21105
|
+
password: args.password,
|
|
21106
|
+
include,
|
|
21107
|
+
confirm: args.confirm === true
|
|
21108
|
+
});
|
|
21109
|
+
} else fail(`unknown action "${action}" — use list, create or restore`);
|
|
21110
|
+
} catch (error) {
|
|
21111
|
+
fail(errorMessage(error));
|
|
21112
|
+
}
|
|
21113
|
+
}
|
|
21114
|
+
});
|
|
21115
|
+
}));
|
|
21116
|
+
//#endregion
|
|
20881
21117
|
//#region src/services/nanny.ts
|
|
20882
21118
|
var nanny_exports$1 = /* @__PURE__ */ __exportAll({ runNanny: () => runNanny });
|
|
20883
21119
|
/**
|
|
@@ -21062,6 +21298,7 @@ var SYNOPSIS = {
|
|
|
21062
21298
|
"restart": "home-hosted restart [<id>] [options]",
|
|
21063
21299
|
"status": "home-hosted status [--json]",
|
|
21064
21300
|
"logs": "home-hosted logs [--lines <n>] [--follow] [--json]",
|
|
21301
|
+
"backup": "home-hosted backup [list|create|restore] [options]",
|
|
21065
21302
|
"start": "home-hosted start <id> [--workspace <id>]",
|
|
21066
21303
|
"stop": "home-hosted stop <id> [--workspace <id>]",
|
|
21067
21304
|
"set-password": "home-hosted set-password",
|
|
@@ -21078,6 +21315,7 @@ var SUMMARIES = {
|
|
|
21078
21315
|
"restart": "down then up — or one server, given an id",
|
|
21079
21316
|
"status": "is it running, where, and how to reach it",
|
|
21080
21317
|
"logs": "show the panel's own console output",
|
|
21318
|
+
"backup": "list, create or restore a backup archive",
|
|
21081
21319
|
"start": "start one server, leaving the panel up",
|
|
21082
21320
|
"stop": "stop one server, leaving the panel up",
|
|
21083
21321
|
"set-password": "set the panel password without the API",
|
|
@@ -21114,6 +21352,17 @@ var LOGS_SECTION = {
|
|
|
21114
21352
|
["--json", "print machine-readable JSON (one object per line with --follow)"]
|
|
21115
21353
|
]
|
|
21116
21354
|
};
|
|
21355
|
+
var BACKUP_SECTION = {
|
|
21356
|
+
heading: "Arguments for backup",
|
|
21357
|
+
lines: [
|
|
21358
|
+
["list | create | restore", "what to do (default: list)"],
|
|
21359
|
+
["<name>", "the archive, for restore — `backup list` shows them"],
|
|
21360
|
+
["--password <text>", "encrypt a new archive, or unlock one on restore"],
|
|
21361
|
+
["--include <ids>", "comma-separated item ids to capture, or to restore"],
|
|
21362
|
+
["--confirm", "apply a restore instead of only planning it"],
|
|
21363
|
+
["--json", "machine-readable output (list)"]
|
|
21364
|
+
]
|
|
21365
|
+
};
|
|
21117
21366
|
var SERVER_SECTION = {
|
|
21118
21367
|
heading: "Arguments for start/stop",
|
|
21119
21368
|
lines: [["<id>", "the server id from servers.config.json"], ["-w, --workspace <id>", "the workspace to act in (default: the default workspace)"]]
|
|
@@ -21257,6 +21506,7 @@ var UP_COMMANDS = /* @__PURE__ */ new Set(["up", "restart"]);
|
|
|
21257
21506
|
var SECTIONS = {
|
|
21258
21507
|
"status": STATUS_SECTION,
|
|
21259
21508
|
"logs": LOGS_SECTION,
|
|
21509
|
+
"backup": BACKUP_SECTION,
|
|
21260
21510
|
"restart": RESTART_SECTION,
|
|
21261
21511
|
"start": SERVER_SECTION,
|
|
21262
21512
|
"stop": SERVER_SECTION,
|
|
@@ -21308,7 +21558,8 @@ var COMMANDS = {
|
|
|
21308
21558
|
"init": () => Promise.resolve().then(() => (init_init(), init_exports)).then((module) => module.initCommand),
|
|
21309
21559
|
"ui-switch": () => Promise.resolve().then(() => (init_ui_switch(), ui_switch_exports)).then((module) => module.uiSwitchCommand),
|
|
21310
21560
|
"ui-update": () => Promise.resolve().then(() => (init_ui_update(), ui_update_exports)).then((module) => module.uiUpdateCommand),
|
|
21311
|
-
"ui-revert": () => Promise.resolve().then(() => (init_ui_revert(), ui_revert_exports)).then((module) => module.uiRevertCommand)
|
|
21561
|
+
"ui-revert": () => Promise.resolve().then(() => (init_ui_revert(), ui_revert_exports)).then((module) => module.uiRevertCommand),
|
|
21562
|
+
"backup": () => Promise.resolve().then(() => (init_backup(), backup_exports)).then((module) => module.backupCommand)
|
|
21312
21563
|
};
|
|
21313
21564
|
var rootCommand = defineCommand({
|
|
21314
21565
|
meta: {
|