home-hosted 0.9.3 → 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/AGENTS.md +27 -21
- package/README.md +109 -50
- package/dist/cli.js +1289 -172
- package/dist/cli.js.map +1 -1
- package/docs/DDNS.md +6 -8
- package/docs/NOTIFICATIONS.md +6 -0
- package/docs/RESTORE_DEMO.md +128 -0
- package/docs/REVERSE_PROXY.md +23 -12
- package/docs/SERVERS.md +50 -2
- package/docs/UI_CREATION.md +7 -7
- package/docs/demo/blank-host-restore.sh +192 -0
- package/package.json +3 -1
- package/uis/stock/dist/assets/de-DI7SS5ZM.js +1 -0
- package/uis/stock/dist/assets/es-DDPUYXdi.js +1 -0
- package/uis/stock/dist/assets/fr-Dpyr2qTp.js +1 -0
- package/uis/stock/dist/assets/index-BtE1z5wU.css +2 -0
- package/uis/stock/dist/assets/{index-DVmJrO-t.js → index-JBfH8bkX.js} +10 -8
- package/uis/stock/dist/assets/ja-CTGEGJ4n.js +1 -0
- package/uis/stock/dist/assets/ko-BSVsEsYY.js +1 -0
- package/uis/stock/dist/assets/ru-DvSoJlxX.js +1 -0
- package/uis/stock/dist/assets/vi-BTIQb_8V.js +1 -0
- package/uis/stock/dist/assets/zh-CN-D2-g9feN.js +1 -0
- package/uis/stock/dist/index.html +2 -2
- package/uis/stock/dist/ui.json +3 -3
- package/uis/stock/dist/assets/de-BVk31frd.js +0 -1
- package/uis/stock/dist/assets/es-BLevhZGM.js +0 -1
- package/uis/stock/dist/assets/fr-S3YXRHdG.js +0 -1
- package/uis/stock/dist/assets/index-GxTN2fYn.css +0 -2
- package/uis/stock/dist/assets/ja-BOB-E8_K.js +0 -1
- package/uis/stock/dist/assets/ko-Dc88YLt7.js +0 -1
- package/uis/stock/dist/assets/ru-BBxCT8MK.js +0 -1
- package/uis/stock/dist/assets/vi-CxubJ_Mw.js +0 -1
- package/uis/stock/dist/assets/zh-CN-BIvisZnl.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -278,6 +278,21 @@ var init_args = __esmMin((() => {
|
|
|
278
278
|
}));
|
|
279
279
|
//#endregion
|
|
280
280
|
//#region src/cli/io.ts
|
|
281
|
+
/**
|
|
282
|
+
* How this process was invoked, so a hint names a command the person can actually run.
|
|
283
|
+
*
|
|
284
|
+
* `npx home-hosted` leaves no `home-hosted` on `PATH`, so a hard-coded "run `home-hosted down`"
|
|
285
|
+
* fails with `command not found`. A package-manager cache path means npx/dlx; `cli.ts` means a
|
|
286
|
+
* source checkout. A string to print, not a parser. `HHOSTED_INVOCATION` overrides it.
|
|
287
|
+
*/
|
|
288
|
+
function invocation() {
|
|
289
|
+
const override = process.env.HHOSTED_INVOCATION?.trim();
|
|
290
|
+
if (override !== void 0 && override.length > 0) return override;
|
|
291
|
+
const entry = process.argv[1] ?? "";
|
|
292
|
+
if (/[\\/](?:_npx|dlx)[\\/]/.test(entry)) return "npx home-hosted";
|
|
293
|
+
if (/[\\/]cli\.ts$/.test(entry)) return "pnpm exec tsx src/cli.ts";
|
|
294
|
+
return "home-hosted";
|
|
295
|
+
}
|
|
281
296
|
/** One shape for every failure: a red `error <message>` on stderr and exit 1. */
|
|
282
297
|
function fail(message) {
|
|
283
298
|
process.stderr.write(`${paint("31", "error")} ${message}\n`);
|
|
@@ -724,7 +739,7 @@ function duplicateWebhookIds(targets) {
|
|
|
724
739
|
}
|
|
725
740
|
return [...duplicates];
|
|
726
741
|
}
|
|
727
|
-
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, backupFileSchema, backupEntrySchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, workspaceViewSchema, appStateSchema, logQuerySchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
742
|
+
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, backupFileSchema, backupEntrySchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, serverOrphanSchema, workspaceViewSchema, appStateSchema, logQuerySchema, actionResultSchema, deliveryResultSchema, passwordSetResponseSchema, tlsReviewResponseSchema, okResponseSchema, backupFilesResponseSchema, uiInstallResponseSchema, backupCreatedResponseSchema, logLinesResponseSchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
728
743
|
var init_contracts = __esmMin((() => {
|
|
729
744
|
bindSchema = type("\"local\" | \"lan\" | /^\\d{1,3}(?:\\.\\d{1,3}){3}$/");
|
|
730
745
|
workspaceIdSchema = type("/^[a-z0-9][a-z0-9_-]*$/");
|
|
@@ -1252,6 +1267,15 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1252
1267
|
entryStateSchema = type({
|
|
1253
1268
|
/** Attempts spent on the current crash sequence; reset once the process stays up. */
|
|
1254
1269
|
"restarts": "number.integer >= 0",
|
|
1270
|
+
/**
|
|
1271
|
+
* Force restarts spent on the current unhealthy sequence.
|
|
1272
|
+
*
|
|
1273
|
+
* Separate from `restarts` because the two are different failures — a process that keeps dying
|
|
1274
|
+
* and a process that stays up but cannot serve. Persisted for the same reason the crash counter
|
|
1275
|
+
* is: a budget that lives only in memory is handed back fresh by every panel restart, so a
|
|
1276
|
+
* health-storm that is restarted often enough never exhausts it.
|
|
1277
|
+
*/
|
|
1278
|
+
"healthRestarts?": "number.integer >= 0",
|
|
1255
1279
|
/** The `runOnce` bootstrap already ran for this entry. */
|
|
1256
1280
|
"bootstrapDone": "boolean",
|
|
1257
1281
|
/**
|
|
@@ -1652,6 +1676,17 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1652
1676
|
"schedule?": backupScheduleSchema,
|
|
1653
1677
|
/** When the last automatic archive was written; null until one has run. Optional for the same reason. */
|
|
1654
1678
|
"lastAutomaticAt?": "number | null",
|
|
1679
|
+
/**
|
|
1680
|
+
* Why the last scheduled pass failed, and when it tried.
|
|
1681
|
+
*
|
|
1682
|
+
* A failed pass wrote only a panel-console warning, so "enabled, zero archives" looked the same
|
|
1683
|
+
* as "failing every interval since the day it was enabled" — indistinguishable from the page,
|
|
1684
|
+
* which is the only place a person looks. Null once a pass succeeds.
|
|
1685
|
+
*/
|
|
1686
|
+
"scheduleError?": type({
|
|
1687
|
+
message: "string",
|
|
1688
|
+
at: "number"
|
|
1689
|
+
}),
|
|
1655
1690
|
/** Extra paths from the global config, in addition to each server's own. */
|
|
1656
1691
|
"includePaths": type("string[]"),
|
|
1657
1692
|
/** Every selectable entry, global first, then each workspace. */
|
|
@@ -1708,6 +1743,27 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1708
1743
|
"restartRequired": "boolean",
|
|
1709
1744
|
/** The panel re-read the restored config within this same restore. */
|
|
1710
1745
|
"reloaded": "boolean",
|
|
1746
|
+
/**
|
|
1747
|
+
* Servers that are **running now** and whose declared data path this restore overwrote.
|
|
1748
|
+
*
|
|
1749
|
+
* A data path is copied over while its owner keeps running, holding open handles to files
|
|
1750
|
+
* that were just replaced — the process keeps its old view and the archive's copy wins on
|
|
1751
|
+
* disk, so anything written since the archive was taken is gone. The plan has to say which
|
|
1752
|
+
* entries that happened to, because nothing else in the result mentions them.
|
|
1753
|
+
*
|
|
1754
|
+
* Optional: an older panel does not send it, and a plan that touched no running entry sends none.
|
|
1755
|
+
*/
|
|
1756
|
+
"replacedUnderRunning?": type({
|
|
1757
|
+
workspaceId: "string",
|
|
1758
|
+
serverId: "string",
|
|
1759
|
+
path: "string"
|
|
1760
|
+
}).array(),
|
|
1761
|
+
/**
|
|
1762
|
+
* Workspaces this restore created because the archive named them and the host did not
|
|
1763
|
+
* have them. Optional: an older panel never sends the row, and an archive written
|
|
1764
|
+
* before the registry was captured creates none.
|
|
1765
|
+
*/
|
|
1766
|
+
"createdWorkspaces?": type("string[]"),
|
|
1711
1767
|
"error": "string?"
|
|
1712
1768
|
});
|
|
1713
1769
|
backupCreateSchema = type({
|
|
@@ -1735,6 +1791,14 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1735
1791
|
"pid": "number | null",
|
|
1736
1792
|
/** True when the process serving this entry was adopted, not spawned by the panel. */
|
|
1737
1793
|
"adopted": "boolean?",
|
|
1794
|
+
/**
|
|
1795
|
+
* The panel stopped this entry because it could not serve, rather than someone asking.
|
|
1796
|
+
*
|
|
1797
|
+
* Optional, like every new field: an older panel does not send it. `/healthz` needs it because
|
|
1798
|
+
* the status alone cannot tell "the operator switched this off" (never a problem) from "the
|
|
1799
|
+
* panel gave up on it" (a broken service) — both are `stopped`.
|
|
1800
|
+
*/
|
|
1801
|
+
"stoppedByPanel?": "boolean",
|
|
1738
1802
|
"startedAt": "number | null",
|
|
1739
1803
|
"exitCode": "number | null",
|
|
1740
1804
|
"exitSignal": "string | null",
|
|
@@ -1799,6 +1863,13 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1799
1863
|
dir: "string",
|
|
1800
1864
|
meta: uiMetaSchema.or(type("null"))
|
|
1801
1865
|
});
|
|
1866
|
+
serverOrphanSchema = type({
|
|
1867
|
+
/** The id it was started as, which is also the key of the state file it was found in. */
|
|
1868
|
+
serverId: "string",
|
|
1869
|
+
pid: "number",
|
|
1870
|
+
/** When the panel spawned it; null when the record predates the stamp. */
|
|
1871
|
+
startedAt: "number | null"
|
|
1872
|
+
});
|
|
1802
1873
|
workspaceViewSchema = type({
|
|
1803
1874
|
"id": "string",
|
|
1804
1875
|
"label": "string",
|
|
@@ -1817,6 +1888,18 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1817
1888
|
"serverCount": "number",
|
|
1818
1889
|
"runningCount": "number",
|
|
1819
1890
|
"crashedCount": "number",
|
|
1891
|
+
/**
|
|
1892
|
+
* Processes this panel started that no current entry owns.
|
|
1893
|
+
*
|
|
1894
|
+
* A detached child outlives a hard panel death, and its handle is the entry-state file keyed by
|
|
1895
|
+
* the *id* it was started under. Rename the entry and nothing ever reads that file again; delete
|
|
1896
|
+
* the entry while the panel is down and the file is reclaimed, destroying the last handle. The
|
|
1897
|
+
* orphan then runs with no card, no `/healthz` line and no CLI action — for a queue consumer,
|
|
1898
|
+
* two consumers of the same queue. This is the view that makes it actionable.
|
|
1899
|
+
*
|
|
1900
|
+
* Optional: an older panel never sends it.
|
|
1901
|
+
*/
|
|
1902
|
+
"orphans?": serverOrphanSchema.array(),
|
|
1820
1903
|
"servers": serverViewSchema.array()
|
|
1821
1904
|
});
|
|
1822
1905
|
appStateSchema = type({
|
|
@@ -1844,6 +1927,51 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1844
1927
|
"lines": logLineSchema.array().optional()
|
|
1845
1928
|
});
|
|
1846
1929
|
logQuerySchema = type({ limit: "string?" });
|
|
1930
|
+
actionResultSchema = type({
|
|
1931
|
+
"ok": "boolean",
|
|
1932
|
+
"error?": "string",
|
|
1933
|
+
"code?": "string"
|
|
1934
|
+
});
|
|
1935
|
+
deliveryResultSchema = type({
|
|
1936
|
+
"ok": "boolean",
|
|
1937
|
+
"error?": "string"
|
|
1938
|
+
});
|
|
1939
|
+
passwordSetResponseSchema = type({
|
|
1940
|
+
ok: "boolean",
|
|
1941
|
+
enabled: "boolean",
|
|
1942
|
+
sessionsInvalidated: "boolean"
|
|
1943
|
+
});
|
|
1944
|
+
tlsReviewResponseSchema = type({
|
|
1945
|
+
control: controlViewSchema,
|
|
1946
|
+
rebinding: "boolean",
|
|
1947
|
+
targetUrl: "string"
|
|
1948
|
+
});
|
|
1949
|
+
okResponseSchema = type({ ok: "boolean" });
|
|
1950
|
+
backupFilesResponseSchema = type({
|
|
1951
|
+
ok: "boolean",
|
|
1952
|
+
files: backupFileSchema.array()
|
|
1953
|
+
});
|
|
1954
|
+
uiInstallResponseSchema = type({
|
|
1955
|
+
"ok": "boolean",
|
|
1956
|
+
"meta?": uiStatusSchema.get("meta"),
|
|
1957
|
+
"ui": uiStatusSchema,
|
|
1958
|
+
/** Revert only: whether there was a custom UI to remove. */
|
|
1959
|
+
"removed?": "boolean"
|
|
1960
|
+
});
|
|
1961
|
+
backupCreatedResponseSchema = type({
|
|
1962
|
+
file: backupFileSchema,
|
|
1963
|
+
files: backupFileSchema.array()
|
|
1964
|
+
});
|
|
1965
|
+
logLinesResponseSchema = type({
|
|
1966
|
+
serverId: "string",
|
|
1967
|
+
enabled: "boolean",
|
|
1968
|
+
sizeBytes: "number",
|
|
1969
|
+
/** The rotated files this entry has, newest first. */
|
|
1970
|
+
files: "string[]",
|
|
1971
|
+
/** The whole search window, or null when the request carried no `search`. */
|
|
1972
|
+
searched: logLineSchema.array().or(type("null")),
|
|
1973
|
+
lines: logLineSchema.array()
|
|
1974
|
+
});
|
|
1847
1975
|
freePortResultSchema = type({
|
|
1848
1976
|
ok: "boolean",
|
|
1849
1977
|
port: "number | null",
|
|
@@ -2634,6 +2762,10 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2634
2762
|
if (!token) return null;
|
|
2635
2763
|
const session = this.sessions.get(token);
|
|
2636
2764
|
if (!session) return null;
|
|
2765
|
+
if (session.passwordRevision !== this.secrets.passwordUpdatedAt) {
|
|
2766
|
+
this.sessions.delete(token);
|
|
2767
|
+
return null;
|
|
2768
|
+
}
|
|
2637
2769
|
const now = Date.now();
|
|
2638
2770
|
if (session.expiresAt <= now) {
|
|
2639
2771
|
this.sessions.delete(token);
|
|
@@ -2699,6 +2831,7 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2699
2831
|
const token = crypto.randomBytes(32).toString("base64url");
|
|
2700
2832
|
this.sessions.set(token, {
|
|
2701
2833
|
token,
|
|
2834
|
+
passwordRevision: this.secrets.passwordUpdatedAt,
|
|
2702
2835
|
expiresAt: now + config.sessionTtlMs,
|
|
2703
2836
|
lastSeenAt: now,
|
|
2704
2837
|
ip
|
|
@@ -2723,7 +2856,10 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2723
2856
|
*/
|
|
2724
2857
|
setPassword(password, options = {}) {
|
|
2725
2858
|
this.secrets.setPassword(password, options);
|
|
2726
|
-
|
|
2859
|
+
const keep = options.keepToken ?? null;
|
|
2860
|
+
this.logoutOthers(keep);
|
|
2861
|
+
const session = keep === null ? void 0 : this.sessions.get(keep);
|
|
2862
|
+
if (session !== void 0) session.passwordRevision = this.secrets.passwordUpdatedAt;
|
|
2727
2863
|
}
|
|
2728
2864
|
/** Drops every session except one, which is how a password change stays signed in. */
|
|
2729
2865
|
logoutOthers(keep) {
|
|
@@ -2982,7 +3118,10 @@ function createAuthRoute(deps) {
|
|
|
2982
3118
|
}).post("/auth/logout", describeRoute({
|
|
2983
3119
|
tags: ["auth"],
|
|
2984
3120
|
summary: "Drop the session cookie",
|
|
2985
|
-
responses: { 200: {
|
|
3121
|
+
responses: { 200: {
|
|
3122
|
+
description: "Signed out",
|
|
3123
|
+
content: jsonBody(okResponseSchema)
|
|
3124
|
+
} }
|
|
2986
3125
|
}), (c) => {
|
|
2987
3126
|
deps.auth.logout(deps.auth.tokenFromCookie(c.req.header("cookie")));
|
|
2988
3127
|
c.header("Set-Cookie", serializeCookie(SESSION_COOKIE, "", {
|
|
@@ -2996,7 +3135,10 @@ function createAuthRoute(deps) {
|
|
|
2996
3135
|
tags: ["auth"],
|
|
2997
3136
|
summary: "Set, change or enable the panel password",
|
|
2998
3137
|
responses: {
|
|
2999
|
-
200: {
|
|
3138
|
+
200: {
|
|
3139
|
+
description: "Updated",
|
|
3140
|
+
content: jsonBody(passwordSetResponseSchema)
|
|
3141
|
+
},
|
|
3000
3142
|
400: ERROR_RESPONSES[400],
|
|
3001
3143
|
401: ERROR_RESPONSES[401]
|
|
3002
3144
|
}
|
|
@@ -3034,7 +3176,10 @@ function createAuthRoute(deps) {
|
|
|
3034
3176
|
tags: ["auth"],
|
|
3035
3177
|
summary: "Clear the password and turn authentication off",
|
|
3036
3178
|
responses: {
|
|
3037
|
-
200: {
|
|
3179
|
+
200: {
|
|
3180
|
+
description: "Cleared",
|
|
3181
|
+
content: jsonBody(okResponseSchema)
|
|
3182
|
+
},
|
|
3038
3183
|
400: ERROR_RESPONSES[400],
|
|
3039
3184
|
401: ERROR_RESPONSES[401]
|
|
3040
3185
|
}
|
|
@@ -3295,6 +3440,7 @@ function buildWorkspaceView(source) {
|
|
|
3295
3440
|
serverCount: servers.length,
|
|
3296
3441
|
runningCount: servers.filter((server) => server.status === "running").length,
|
|
3297
3442
|
crashedCount: servers.filter((server) => server.status === "crashed").length,
|
|
3443
|
+
orphans: source.supervisor.orphans?.() ?? [],
|
|
3298
3444
|
servers
|
|
3299
3445
|
};
|
|
3300
3446
|
}
|
|
@@ -3323,7 +3469,10 @@ function createBackupsRoute(deps) {
|
|
|
3323
3469
|
tags: ["backups"],
|
|
3324
3470
|
summary: "Create a backup (optionally password-protected)",
|
|
3325
3471
|
responses: {
|
|
3326
|
-
200: {
|
|
3472
|
+
200: {
|
|
3473
|
+
description: "Created",
|
|
3474
|
+
content: jsonBody(backupCreatedResponseSchema)
|
|
3475
|
+
},
|
|
3327
3476
|
400: ERROR_RESPONSES[400]
|
|
3328
3477
|
}
|
|
3329
3478
|
}), validate("json", backupCreateSchema), async (c) => {
|
|
@@ -3360,7 +3509,10 @@ function createBackupsRoute(deps) {
|
|
|
3360
3509
|
tags: ["backups"],
|
|
3361
3510
|
summary: "Delete one archive",
|
|
3362
3511
|
responses: {
|
|
3363
|
-
200: {
|
|
3512
|
+
200: {
|
|
3513
|
+
description: "Removed",
|
|
3514
|
+
content: jsonBody(backupFilesResponseSchema)
|
|
3515
|
+
},
|
|
3364
3516
|
404: ERROR_RESPONSES[404]
|
|
3365
3517
|
}
|
|
3366
3518
|
}), validate("param", nameParam), (c) => {
|
|
@@ -3518,6 +3670,27 @@ function unknownServerError(id) {
|
|
|
3518
3670
|
code: "UNKNOWN_SERVER"
|
|
3519
3671
|
});
|
|
3520
3672
|
}
|
|
3673
|
+
/**
|
|
3674
|
+
* The stable code for a failed action, so a script branches on it rather than on English.
|
|
3675
|
+
*
|
|
3676
|
+
* Two values, not one per message: a missing id is what the caller must fix, and everything else
|
|
3677
|
+
* ("disabled", "stopping", "port in use") is the entry refusing right now. `code` is added beside
|
|
3678
|
+
* `ok`/`error` rather than replacing them, because an older UI reads those.
|
|
3679
|
+
*/
|
|
3680
|
+
function actionCode(result) {
|
|
3681
|
+
return result[UNKNOWN_SERVER] === true ? "UNKNOWN_SERVER" : "ACTION_FAILED";
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* What a lifecycle route puts on the wire: the result it already had, plus its code.
|
|
3685
|
+
*
|
|
3686
|
+
* A success carries no code — a code names a failure.
|
|
3687
|
+
*/
|
|
3688
|
+
function actionAnswer(result) {
|
|
3689
|
+
return result.ok ? { ...result } : {
|
|
3690
|
+
...result,
|
|
3691
|
+
code: actionCode(result)
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3521
3694
|
/** Unknown ids are 404; a server that exists but cannot act is a 409. */
|
|
3522
3695
|
function statusForAction(result) {
|
|
3523
3696
|
if (result.ok) return 200;
|
|
@@ -3829,7 +4002,10 @@ function createControlRoute(deps) {
|
|
|
3829
4002
|
tags: ["panel"],
|
|
3830
4003
|
summary: "Stop the panel and everything it supervises (local token required)",
|
|
3831
4004
|
responses: {
|
|
3832
|
-
200: {
|
|
4005
|
+
200: {
|
|
4006
|
+
description: "Stopping",
|
|
4007
|
+
content: jsonBody(okResponseSchema)
|
|
4008
|
+
},
|
|
3833
4009
|
403: { description: "Bad token, or not a local caller" }
|
|
3834
4010
|
}
|
|
3835
4011
|
}), (c) => {
|
|
@@ -3840,7 +4016,10 @@ function createControlRoute(deps) {
|
|
|
3840
4016
|
tags: ["panel"],
|
|
3841
4017
|
summary: "Start one server, without a session (local token required)",
|
|
3842
4018
|
responses: {
|
|
3843
|
-
200: {
|
|
4019
|
+
200: {
|
|
4020
|
+
description: "Started",
|
|
4021
|
+
content: jsonBody(okResponseSchema)
|
|
4022
|
+
},
|
|
3844
4023
|
403: { description: "Bad token, or not a local caller" },
|
|
3845
4024
|
404: { description: "No such server" }
|
|
3846
4025
|
}
|
|
@@ -3852,7 +4031,10 @@ function createControlRoute(deps) {
|
|
|
3852
4031
|
tags: ["panel"],
|
|
3853
4032
|
summary: "Stop one server, without a session (local token required)",
|
|
3854
4033
|
responses: {
|
|
3855
|
-
200: {
|
|
4034
|
+
200: {
|
|
4035
|
+
description: "Stopped",
|
|
4036
|
+
content: jsonBody(okResponseSchema)
|
|
4037
|
+
},
|
|
3856
4038
|
403: { description: "Bad token, or not a local caller" },
|
|
3857
4039
|
404: { description: "No such server" }
|
|
3858
4040
|
}
|
|
@@ -3864,7 +4046,10 @@ function createControlRoute(deps) {
|
|
|
3864
4046
|
tags: ["panel"],
|
|
3865
4047
|
summary: "Restart one server, without a session (local token required)",
|
|
3866
4048
|
responses: {
|
|
3867
|
-
200: {
|
|
4049
|
+
200: {
|
|
4050
|
+
description: "Restarted",
|
|
4051
|
+
content: jsonBody(okResponseSchema)
|
|
4052
|
+
},
|
|
3868
4053
|
403: { description: "Bad token, or not a local caller" },
|
|
3869
4054
|
404: { description: "No such server" }
|
|
3870
4055
|
}
|
|
@@ -3872,6 +4057,77 @@ function createControlRoute(deps) {
|
|
|
3872
4057
|
assertLocalCall(c, "restart a server");
|
|
3873
4058
|
const result = await requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace).supervisor.restart(c.req.param("id"), { actor: "user" });
|
|
3874
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
|
+
}));
|
|
3875
4131
|
});
|
|
3876
4132
|
}
|
|
3877
4133
|
var init_control = __esmMin((() => {
|
|
@@ -3879,10 +4135,13 @@ var init_control = __esmMin((() => {
|
|
|
3879
4135
|
init_deferred();
|
|
3880
4136
|
init_factory();
|
|
3881
4137
|
init_logger();
|
|
4138
|
+
init_openapi$1();
|
|
3882
4139
|
init_secret_compare();
|
|
3883
4140
|
init_validator();
|
|
3884
4141
|
init_workspace();
|
|
3885
4142
|
init_loopback();
|
|
4143
|
+
init_state$1();
|
|
4144
|
+
init_contracts();
|
|
3886
4145
|
}));
|
|
3887
4146
|
//#endregion
|
|
3888
4147
|
//#region src/config/migrations.ts
|
|
@@ -4229,6 +4488,12 @@ function validateCrossField(servers) {
|
|
|
4229
4488
|
settled.add(id);
|
|
4230
4489
|
};
|
|
4231
4490
|
for (const server of servers) walk(server.id);
|
|
4491
|
+
const byPort = /* @__PURE__ */ new Map();
|
|
4492
|
+
for (const server of servers) {
|
|
4493
|
+
if (server.port === null || !server.enabled) continue;
|
|
4494
|
+
byPort.set(server.port, [...byPort.get(server.port) ?? [], server.id]);
|
|
4495
|
+
}
|
|
4496
|
+
for (const [port, ids] of byPort) if (ids.length > 1) errors.push(`port ${port} is declared by ${ids.map((id) => `"${id}"`).join(", ")} — only one can bind it`);
|
|
4232
4497
|
return [...new Set(errors)];
|
|
4233
4498
|
}
|
|
4234
4499
|
/** Adds the stamp every write carries, so the next release can tell what wrote the file. */
|
|
@@ -6519,6 +6784,30 @@ var init_store = __esmMin((() => {
|
|
|
6519
6784
|
this.commitServers(draft);
|
|
6520
6785
|
return validated;
|
|
6521
6786
|
}
|
|
6787
|
+
/**
|
|
6788
|
+
* Creates the entry, or replaces a same-id one outright — "make it so".
|
|
6789
|
+
*
|
|
6790
|
+
* `addServer` refuses a duplicate and `updateServer` only patches an existing entry, so a config
|
|
6791
|
+
* management pass had to GET, diff, then POST or PATCH, and a re-run of an unchanged declaration
|
|
6792
|
+
* got `400 INVALID_SERVER` for its trouble. A replace is what a declarative caller means: the
|
|
6793
|
+
* body is the whole entry, not a patch.
|
|
6794
|
+
*
|
|
6795
|
+
* Returns whether it created or replaced, so the route can answer 201 or 200 honestly.
|
|
6796
|
+
*/
|
|
6797
|
+
putServer(input) {
|
|
6798
|
+
const draft = structuredClone(this.rawServers);
|
|
6799
|
+
const list = draft.servers ?? (draft.servers = []);
|
|
6800
|
+
const index = list.findIndex((entry) => entry.id === input.id);
|
|
6801
|
+
const created = index < 0;
|
|
6802
|
+
if (created) list.push(structuredClone(input));
|
|
6803
|
+
else list[index] = structuredClone(input);
|
|
6804
|
+
const validated = this.validateServer(list[created ? list.length - 1 : index], `servers[${created ? list.length - 1 : index}]`);
|
|
6805
|
+
this.commitServers(draft);
|
|
6806
|
+
return {
|
|
6807
|
+
server: validated,
|
|
6808
|
+
created
|
|
6809
|
+
};
|
|
6810
|
+
}
|
|
6522
6811
|
removeServer(id) {
|
|
6523
6812
|
const draft = structuredClone(this.rawServers);
|
|
6524
6813
|
const list = draft.servers ?? [];
|
|
@@ -6877,9 +7166,9 @@ var init_events = __esmMin((() => {
|
|
|
6877
7166
|
//#region src/api/health.ts
|
|
6878
7167
|
/**
|
|
6879
7168
|
* Liveness for external monitors. Mounted outside `/api`, so it answers without a
|
|
6880
|
-
* session: it reports whether the panel itself is serving, and 503 when
|
|
6881
|
-
*
|
|
6882
|
-
* Server details are 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.
|
|
6883
7172
|
*/
|
|
6884
7173
|
function createHealthRoute(deps) {
|
|
6885
7174
|
return appFactory.createApp().get("/healthz", describeRoute({
|
|
@@ -6890,12 +7179,12 @@ function createHealthRoute(deps) {
|
|
|
6890
7179
|
description: "Serving",
|
|
6891
7180
|
content: jsonBody(healthResponseSchema)
|
|
6892
7181
|
},
|
|
6893
|
-
503: { description: "
|
|
7182
|
+
503: { description: "A server crashed, or the panel stopped one that could not serve, or a running one is unhealthy" }
|
|
6894
7183
|
}
|
|
6895
7184
|
}), (c) => {
|
|
6896
7185
|
const state = deps.panel.getState();
|
|
6897
7186
|
const servers = state.workspaces.flatMap((workspace) => workspace.servers);
|
|
6898
|
-
const broken = servers.filter((server) => server.
|
|
7187
|
+
const broken = servers.filter((server) => server.status === "crashed" || server.stoppedByPanel === true || server.status === "running" && server.health === "unhealthy");
|
|
6899
7188
|
const authenticated = requestIdentity(c, deps.auth).authenticated;
|
|
6900
7189
|
return c.json({
|
|
6901
7190
|
status: broken.length > 0 ? "degraded" : "ok",
|
|
@@ -6940,7 +7229,10 @@ function createLogsRoute(deps) {
|
|
|
6940
7229
|
tags: ["logs"],
|
|
6941
7230
|
summary: "Persisted log lines, with search and a stream filter",
|
|
6942
7231
|
responses: {
|
|
6943
|
-
200: {
|
|
7232
|
+
200: {
|
|
7233
|
+
description: "Lines",
|
|
7234
|
+
content: jsonBody(logLinesResponseSchema)
|
|
7235
|
+
},
|
|
6944
7236
|
404: ERROR_RESPONSES[404]
|
|
6945
7237
|
}
|
|
6946
7238
|
}), validate("query", historyQuery), validate("param", idParam$2), (c) => {
|
|
@@ -7003,7 +7295,10 @@ function createLogsRoute(deps) {
|
|
|
7003
7295
|
tags: ["logs"],
|
|
7004
7296
|
summary: "Delete the persisted logs of one server",
|
|
7005
7297
|
responses: {
|
|
7006
|
-
200: {
|
|
7298
|
+
200: {
|
|
7299
|
+
description: "Cleared",
|
|
7300
|
+
content: jsonBody(okResponseSchema)
|
|
7301
|
+
},
|
|
7007
7302
|
404: ERROR_RESPONSES[404]
|
|
7008
7303
|
}
|
|
7009
7304
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$2), (c) => {
|
|
@@ -7102,12 +7397,12 @@ function getBot(token) {
|
|
|
7102
7397
|
function forgetBots() {
|
|
7103
7398
|
bots.clear();
|
|
7104
7399
|
}
|
|
7105
|
-
function escapeHtml(value) {
|
|
7400
|
+
function escapeHtml$1(value) {
|
|
7106
7401
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
7107
7402
|
}
|
|
7108
7403
|
function formatTelegramMessage(title, lines) {
|
|
7109
|
-
const body = lines.filter((line) => line.length > 0).map((line) => `• ${escapeHtml(line)}`).join("\n");
|
|
7110
|
-
return `<b>${escapeHtml(title)}</b>${body.length > 0 ? `\n${body}` : ""}`;
|
|
7404
|
+
const body = lines.filter((line) => line.length > 0).map((line) => `• ${escapeHtml$1(line)}`).join("\n");
|
|
7405
|
+
return `<b>${escapeHtml$1(title)}</b>${body.length > 0 ? `\n${body}` : ""}`;
|
|
7111
7406
|
}
|
|
7112
7407
|
/** Turns a grammY error into something worth showing in the settings page. */
|
|
7113
7408
|
function describeTelegramError(error) {
|
|
@@ -7202,7 +7497,10 @@ function createNotificationsRoute(deps) {
|
|
|
7202
7497
|
tags: ["notifications"],
|
|
7203
7498
|
summary: "Store a Telegram destination's bot token (verified first)",
|
|
7204
7499
|
responses: {
|
|
7205
|
-
200: {
|
|
7500
|
+
200: {
|
|
7501
|
+
description: "Stored",
|
|
7502
|
+
content: jsonBody(okResponseSchema)
|
|
7503
|
+
},
|
|
7206
7504
|
400: ERROR_RESPONSES[400]
|
|
7207
7505
|
}
|
|
7208
7506
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), validate("json", telegramTokenSchema), async (c) => {
|
|
@@ -7223,7 +7521,10 @@ function createNotificationsRoute(deps) {
|
|
|
7223
7521
|
}).delete("/notifications/destinations/:id/token", describeRoute({
|
|
7224
7522
|
tags: ["notifications"],
|
|
7225
7523
|
summary: "Forget a Telegram destination's bot token",
|
|
7226
|
-
responses: { 200: {
|
|
7524
|
+
responses: { 200: {
|
|
7525
|
+
description: "Removed",
|
|
7526
|
+
content: jsonBody(okResponseSchema)
|
|
7527
|
+
} }
|
|
7227
7528
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), (c) => {
|
|
7228
7529
|
runtimeFor(c.req.valid("query").workspace).secrets.setTelegramToken(c.req.valid("param").id, null);
|
|
7229
7530
|
forgetBots();
|
|
@@ -7232,7 +7533,10 @@ function createNotificationsRoute(deps) {
|
|
|
7232
7533
|
tags: ["notifications"],
|
|
7233
7534
|
summary: "Send a test message to one destination",
|
|
7234
7535
|
responses: {
|
|
7235
|
-
200: {
|
|
7536
|
+
200: {
|
|
7537
|
+
description: "Sent or refused",
|
|
7538
|
+
content: jsonBody(deliveryResultSchema)
|
|
7539
|
+
},
|
|
7236
7540
|
400: ERROR_RESPONSES[400]
|
|
7237
7541
|
}
|
|
7238
7542
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), validate("json", notificationActionSchema), async (c) => {
|
|
@@ -7246,7 +7550,10 @@ function createNotificationsRoute(deps) {
|
|
|
7246
7550
|
tags: ["notifications"],
|
|
7247
7551
|
summary: "Send a test to one webhook destination",
|
|
7248
7552
|
responses: {
|
|
7249
|
-
200: {
|
|
7553
|
+
200: {
|
|
7554
|
+
description: "Sent or refused",
|
|
7555
|
+
content: jsonBody(deliveryResultSchema)
|
|
7556
|
+
},
|
|
7250
7557
|
400: ERROR_RESPONSES[400]
|
|
7251
7558
|
}
|
|
7252
7559
|
}), validate("query", workspaceQuerySchema), validate("json", destinationTestSchema), async (c) => {
|
|
@@ -8049,6 +8356,44 @@ function parseNetstatListeners(output, port) {
|
|
|
8049
8356
|
}
|
|
8050
8357
|
return [...pids];
|
|
8051
8358
|
}
|
|
8359
|
+
async function findDockerPortHolder(port) {
|
|
8360
|
+
try {
|
|
8361
|
+
const { stdout } = await execFileAsync$2("docker", [
|
|
8362
|
+
"ps",
|
|
8363
|
+
"--filter",
|
|
8364
|
+
`publish=${port}`,
|
|
8365
|
+
"--format",
|
|
8366
|
+
"{{.Names}} {{.Label \"com.docker.compose.project.working_dir\"}}"
|
|
8367
|
+
], { timeout: 3e3 });
|
|
8368
|
+
const line = stdout.split("\n").find((entry) => entry.trim().length > 0);
|
|
8369
|
+
if (line === void 0) return null;
|
|
8370
|
+
const [container = "", composeDir = ""] = line.split(" ");
|
|
8371
|
+
if (container.trim().length === 0) return null;
|
|
8372
|
+
return {
|
|
8373
|
+
container: container.trim(),
|
|
8374
|
+
composeDir: composeDir.trim().length > 0 ? composeDir.trim() : null,
|
|
8375
|
+
port
|
|
8376
|
+
};
|
|
8377
|
+
} catch {
|
|
8378
|
+
return null;
|
|
8379
|
+
}
|
|
8380
|
+
}
|
|
8381
|
+
/**
|
|
8382
|
+
* Stops the container publishing a host port, which is how docker's port is freed.
|
|
8383
|
+
*
|
|
8384
|
+
* The socket belongs to a root-owned `docker-proxy`, so there is no pid this process may signal —
|
|
8385
|
+
* but the container is the panel's to stop through docker itself, which needs no privileges
|
|
8386
|
+
* beyond the socket the user already has. `docker stop` releases the published port and leaves the
|
|
8387
|
+
* stack's other services alone.
|
|
8388
|
+
*/
|
|
8389
|
+
async function releaseDockerPort(holder, timeoutMs = 2e4) {
|
|
8390
|
+
try {
|
|
8391
|
+
await execFileAsync$2("docker", ["stop", holder.container], { timeout: timeoutMs });
|
|
8392
|
+
return true;
|
|
8393
|
+
} catch {
|
|
8394
|
+
return false;
|
|
8395
|
+
}
|
|
8396
|
+
}
|
|
8052
8397
|
async function listPortHolders(port) {
|
|
8053
8398
|
if (process.platform === "win32") try {
|
|
8054
8399
|
const { stdout } = await execFileAsync$2("netstat", [
|
|
@@ -8101,6 +8446,7 @@ var nanny_exports$2 = /* @__PURE__ */ __exportAll({
|
|
|
8101
8446
|
clearNannySpec: () => clearNannySpec,
|
|
8102
8447
|
clearNannyState: () => clearNannyState,
|
|
8103
8448
|
describeNannyExit: () => describeNannyExit,
|
|
8449
|
+
describeSpawnError: () => describeSpawnError,
|
|
8104
8450
|
nannyEntryPoint: () => nannyEntryPoint,
|
|
8105
8451
|
nannyIsAlive: () => nannyIsAlive,
|
|
8106
8452
|
nannyLogFile: () => nannyLogFile,
|
|
@@ -8211,6 +8557,22 @@ function exitCodeHint(code) {
|
|
|
8211
8557
|
if (signal === null) return null;
|
|
8212
8558
|
return code === 137 ? `${signal} — which the kernel sends when memory runs out` : `${signal}, if the shell reported the kill`;
|
|
8213
8559
|
}
|
|
8560
|
+
/**
|
|
8561
|
+
* A spawn failure in words a person can act on.
|
|
8562
|
+
*
|
|
8563
|
+
* Node reports a missing program as `spawn <cmd> ENOENT` — the same errno as a missing *file*, and
|
|
8564
|
+
* the same wording whichever of the two it is. A user who pasted `java -jar server.jar` into
|
|
8565
|
+
* `command` saw exactly that and had nothing to go on: the message names the whole line, so it
|
|
8566
|
+
* reads as "the program is missing" even when the program is fine and only the argument is wrong.
|
|
8567
|
+
*
|
|
8568
|
+
* `command` is the configured program, so the two cases can be told apart: if a bare name has no
|
|
8569
|
+
* path separator, the shell would have searched `PATH` and this one did not.
|
|
8570
|
+
*/
|
|
8571
|
+
function describeSpawnError(error, command) {
|
|
8572
|
+
if (error.code === "ENOENT") 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?`;
|
|
8573
|
+
if (error.code === "EACCES") return `\`${command}\` exists but is not executable — check its permissions (chmod +x)`;
|
|
8574
|
+
return `${error.message} (while running \`${command}\`)`;
|
|
8575
|
+
}
|
|
8214
8576
|
/** `SIGKILL` for 9, or null when the number names nothing. */
|
|
8215
8577
|
function signalName(number) {
|
|
8216
8578
|
for (const [name, value] of Object.entries(os.constants.signals)) if (value === number) return name;
|
|
@@ -8326,18 +8688,6 @@ var init_proxy$2 = __esmMin((() => {
|
|
|
8326
8688
|
//#endregion
|
|
8327
8689
|
//#region src/services/proxy-config.ts
|
|
8328
8690
|
/**
|
|
8329
|
-
* The issuers for the public names: ACME with the account address, then the engine's
|
|
8330
|
-
* own CA as a last resort.
|
|
8331
|
-
*
|
|
8332
|
-
* The fallback is what keeps a missing certificate from being a dead connection: the
|
|
8333
|
-
* handshake completes with an untrusted certificate (the browser offers to continue),
|
|
8334
|
-
* instead of failing with a protocol error the visitor cannot read past. The engine
|
|
8335
|
-
* keeps trying ACME, and the panel reports which of the two is being served.
|
|
8336
|
-
*
|
|
8337
|
-
* ZeroSSL is deliberately absent: it needs an EAB key the panel does not collect, so
|
|
8338
|
-
* listing it only added a failing issuer and a second retry on every name.
|
|
8339
|
-
*/
|
|
8340
|
-
/**
|
|
8341
8691
|
* The DNS-01 challenge block, which names the panel as the one that answers it. The
|
|
8342
8692
|
* engine holds no DNS credentials: it asks the panel over the ACMEProxy protocol, and
|
|
8343
8693
|
* the panel writes the record through the workspace account the route names.
|
|
@@ -8353,6 +8703,18 @@ function challengeBlock(dns01) {
|
|
|
8353
8703
|
...dns01.resolvers.length > 0 ? { resolvers: dns01.resolvers } : {}
|
|
8354
8704
|
} } };
|
|
8355
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
|
+
*/
|
|
8356
8718
|
function acmeIssuers(acme, challenge = {}) {
|
|
8357
8719
|
return [{
|
|
8358
8720
|
module: "acme",
|
|
@@ -8362,6 +8724,16 @@ function acmeIssuers(acme, challenge = {}) {
|
|
|
8362
8724
|
}, { module: "internal" }];
|
|
8363
8725
|
}
|
|
8364
8726
|
/**
|
|
8727
|
+
* HTML-escape a value interpolated into a page.
|
|
8728
|
+
*
|
|
8729
|
+
* The notice page interpolates a routed hostname — configuration, but a config file may be
|
|
8730
|
+
* hand-edited, so it is not trusted markup. Escaped here rather than left to the engine's
|
|
8731
|
+
* authority parser, so correct encoding does not depend on what sits in front of it.
|
|
8732
|
+
*/
|
|
8733
|
+
function escapeHtml(value) {
|
|
8734
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
8735
|
+
}
|
|
8736
|
+
/**
|
|
8365
8737
|
* The one page shell both visitor-facing pages use. They are the same document with
|
|
8366
8738
|
* different words, and the stylesheet has to stay identical — a page the engine serves
|
|
8367
8739
|
* on a port a person reaches by hand is a page that has to look like this panel.
|
|
@@ -8391,8 +8763,8 @@ ${body}
|
|
|
8391
8763
|
* that cannot finish.
|
|
8392
8764
|
*/
|
|
8393
8765
|
function notConfiguredPage() {
|
|
8394
|
-
return htmlPage("No route for this hostname", "This route is not configured for any target yet", ` <p>No route in <strong>home-hosted</strong>'s reverse proxy claims the hostname
|
|
8395
|
-
|
|
8766
|
+
return htmlPage("No route for this hostname", "This route is not configured for any target yet", ` <p>No route in <strong>home-hosted</strong>'s reverse proxy claims the hostname you
|
|
8767
|
+
reached, so there is nothing here to serve.</p>
|
|
8396
8768
|
<p>Add a route for it under <strong>Others → Reverse Proxy</strong>, or check that you
|
|
8397
8769
|
reached the hostname you meant to.</p>
|
|
8398
8770
|
<footer>home-hosted reverse proxy</footer>`);
|
|
@@ -8402,18 +8774,23 @@ function notConfiguredRoute() {
|
|
|
8402
8774
|
return { handle: [{
|
|
8403
8775
|
handler: "static_response",
|
|
8404
8776
|
status_code: 404,
|
|
8405
|
-
headers: {
|
|
8777
|
+
headers: {
|
|
8778
|
+
"content-type": ["text/html; charset=utf-8"],
|
|
8779
|
+
"cache-control": ["no-store"],
|
|
8780
|
+
"vary": ["Host"]
|
|
8781
|
+
},
|
|
8406
8782
|
body: notConfiguredPage()
|
|
8407
8783
|
}] };
|
|
8408
8784
|
}
|
|
8409
8785
|
/** The page a visitor gets when a name has no certificate yet and HTTPS cannot work. */
|
|
8410
8786
|
function noticePage(host, httpPort, httpsPort) {
|
|
8411
|
-
|
|
8787
|
+
const safeHost = escapeHtml(host);
|
|
8788
|
+
return htmlPage(escapeHtml(`Certificate not ready — ${host}`), escapeHtml(`No certificate yet for ${host}`), ` <p>This hostname is routed, but the certificate authority has not issued a certificate
|
|
8412
8789
|
for it yet, so HTTPS cannot complete a handshake. The engine keeps trying in the
|
|
8413
8790
|
background and will serve the name as soon as it succeeds.</p>
|
|
8414
8791
|
<p>The usual cause is that the CA cannot reach this machine: with the proxy on
|
|
8415
8792
|
<code>${httpPort}</code>/<code>${httpsPort}</code>, forward <code>80 → ${httpPort}</code>
|
|
8416
|
-
and <code>443 → ${httpsPort}</code> on your router. Otherwise <code>http://${
|
|
8793
|
+
and <code>443 → ${httpsPort}</code> on your router. Otherwise <code>http://${safeHost}</code>
|
|
8417
8794
|
will keep landing here.</p>
|
|
8418
8795
|
<footer>Details, and the engine's own reason, are in the panel: Others → Reverse Proxy.</footer>`);
|
|
8419
8796
|
}
|
|
@@ -8461,6 +8838,18 @@ function proxyHandler(route) {
|
|
|
8461
8838
|
};
|
|
8462
8839
|
}
|
|
8463
8840
|
/**
|
|
8841
|
+
* The ports a rendered configuration listens on.
|
|
8842
|
+
*
|
|
8843
|
+
* The one derivation: `httpPort`/`httpsPort` are what was *asked for*, not what is bound — a
|
|
8844
|
+
* `tls: 'off'`-only table binds no HTTPS listener, and a table with no servable route binds nothing.
|
|
8845
|
+
* Both the applied record and the port preflight read this, so they cannot disagree.
|
|
8846
|
+
*/
|
|
8847
|
+
function boundPorts(rendered) {
|
|
8848
|
+
const servers = rendered.apps?.http?.servers;
|
|
8849
|
+
if (servers === void 0) return [];
|
|
8850
|
+
return Object.values(servers).flatMap((server) => server.listen ?? []).map((listen) => Number.parseInt(listen.replace(/^.*:/, ""), 10)).filter((port) => Number.isInteger(port));
|
|
8851
|
+
}
|
|
8852
|
+
/**
|
|
8464
8853
|
* The whole engine configuration, generated from the panel's route table.
|
|
8465
8854
|
*
|
|
8466
8855
|
* Two servers on purpose: one terminates TLS for the names that ask for it, the
|
|
@@ -8516,7 +8905,11 @@ function renderCaddyConfig(input) {
|
|
|
8516
8905
|
handle: [{
|
|
8517
8906
|
handler: "static_response",
|
|
8518
8907
|
status_code: 503,
|
|
8519
|
-
headers: {
|
|
8908
|
+
headers: {
|
|
8909
|
+
"content-type": ["text/html; charset=utf-8"],
|
|
8910
|
+
"cache-control": ["no-store"],
|
|
8911
|
+
"vary": ["Host"]
|
|
8912
|
+
},
|
|
8520
8913
|
body: noticePage(host, config.httpPort, config.httpsPort)
|
|
8521
8914
|
}]
|
|
8522
8915
|
})),
|
|
@@ -8902,7 +9295,7 @@ function engineMessage(body) {
|
|
|
8902
9295
|
return body.trim().length > 0 ? body.trim().slice(0, 400) : null;
|
|
8903
9296
|
}
|
|
8904
9297
|
}
|
|
8905
|
-
var PROXY_ID, ADMIN_TIMEOUT_MS, READY_TIMEOUT_MS, READY_POLL_MS, DOWNLOAD_TIMEOUT_MS$1, ENGINE_COMMAND_TIMEOUT_MS, DNS01_MODULE, engineRecordSchema, challengeAuthSchema, appliedRecordSchema, adminRecordSchema, ProxyService;
|
|
9298
|
+
var PROXY_ID, SYNC_RETRY_BASE_MS, SYNC_RETRY_MAX_MS, SYNC_MAX_FAILURES, ADMIN_TIMEOUT_MS, READY_TIMEOUT_MS, READY_POLL_MS, DOWNLOAD_TIMEOUT_MS$1, ENGINE_COMMAND_TIMEOUT_MS, DNS01_MODULE, engineRecordSchema, challengeAuthSchema, appliedRecordSchema, adminRecordSchema, ProxyService;
|
|
8906
9299
|
var init_proxy$1 = __esmMin((() => {
|
|
8907
9300
|
init_atomic();
|
|
8908
9301
|
init_logger();
|
|
@@ -8919,6 +9312,9 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
8919
9312
|
init_error_message();
|
|
8920
9313
|
init_proxy_form();
|
|
8921
9314
|
PROXY_ID = "proxy";
|
|
9315
|
+
SYNC_RETRY_BASE_MS = 2e3;
|
|
9316
|
+
SYNC_RETRY_MAX_MS = 3e5;
|
|
9317
|
+
SYNC_MAX_FAILURES = 8;
|
|
8922
9318
|
ADMIN_TIMEOUT_MS = 5e3;
|
|
8923
9319
|
READY_TIMEOUT_MS = 2e4;
|
|
8924
9320
|
READY_POLL_MS = 250;
|
|
@@ -8938,8 +9334,8 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
8938
9334
|
password: "string >= 1"
|
|
8939
9335
|
}).onUndeclaredKey("reject");
|
|
8940
9336
|
appliedRecordSchema = type({
|
|
8941
|
-
httpPort: "1 <= number.integer <= 65535",
|
|
8942
|
-
httpsPort: "1 <= number.integer <= 65535",
|
|
9337
|
+
httpPort: "1 <= number.integer <= 65535 | null",
|
|
9338
|
+
httpsPort: "1 <= number.integer <= 65535 | null",
|
|
8943
9339
|
at: "number"
|
|
8944
9340
|
}).onUndeclaredKey("reject");
|
|
8945
9341
|
adminRecordSchema = type({
|
|
@@ -9469,7 +9865,6 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9469
9865
|
logger.error(`proxy: could not start: ${this.lastError}`);
|
|
9470
9866
|
}
|
|
9471
9867
|
}
|
|
9472
|
-
/** True when a nanny this panel would recognise still owns the engine. */
|
|
9473
9868
|
/**
|
|
9474
9869
|
* True while a process from the installed binary is alive, however the panel's view
|
|
9475
9870
|
* reads. `live()` additionally requires a fresh heartbeat, so a nanny that died and
|
|
@@ -9497,9 +9892,12 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9497
9892
|
};
|
|
9498
9893
|
if (!config.enabled) return base;
|
|
9499
9894
|
const applied = this.readApplied();
|
|
9500
|
-
const
|
|
9501
|
-
const
|
|
9502
|
-
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}`);
|
|
9503
9901
|
const certExpiryDays = this.certificateExpiryDays();
|
|
9504
9902
|
if (!this.installed()) return {
|
|
9505
9903
|
...base,
|
|
@@ -9557,6 +9955,10 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9557
9955
|
lastError: this.lastError
|
|
9558
9956
|
};
|
|
9559
9957
|
}
|
|
9958
|
+
/** Backoff for a failing `sync()` re-apply; see the retry notes there. */
|
|
9959
|
+
nextSyncAttemptAt = 0;
|
|
9960
|
+
syncFailures = 0;
|
|
9961
|
+
lastSyncError = null;
|
|
9560
9962
|
/** Records why the last start or apply failed, for the frame the page reads. */
|
|
9561
9963
|
recordError(message) {
|
|
9562
9964
|
this.lastError = message;
|
|
@@ -9567,7 +9969,6 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9567
9969
|
this.options.onStateChange();
|
|
9568
9970
|
return config;
|
|
9569
9971
|
}
|
|
9570
|
-
/** Renders the current route table and applies it; the engine keeps serving on failure. */
|
|
9571
9972
|
/**
|
|
9572
9973
|
* Makes the engine ask the CA again for one name, without restarting it.
|
|
9573
9974
|
*
|
|
@@ -9600,7 +10001,12 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9600
10001
|
await this.apply({ force: true });
|
|
9601
10002
|
return;
|
|
9602
10003
|
}
|
|
9603
|
-
|
|
10004
|
+
const staged = this.render(/* @__PURE__ */ new Set([route.id]));
|
|
10005
|
+
if (boundPorts(staged).length === 0) throw new DetailedError(`making the engine forget its certificate for "${route.host}" would leave nothing served — add another working route first`, {
|
|
10006
|
+
statusCode: 409,
|
|
10007
|
+
code: "PROXY_CERT_RETRY_LAST_ROUTE"
|
|
10008
|
+
});
|
|
10009
|
+
await this.loadIntoEngine(staged);
|
|
9604
10010
|
this.forgetCertificates(route.host);
|
|
9605
10011
|
await this.apply({ force: true });
|
|
9606
10012
|
}
|
|
@@ -9622,6 +10028,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9622
10028
|
});
|
|
9623
10029
|
}
|
|
9624
10030
|
}
|
|
10031
|
+
/** Renders the current route table and applies it; the engine keeps serving on failure. */
|
|
9625
10032
|
async apply(options = {}) {
|
|
9626
10033
|
if (!this.config.enabled || !this.installed()) return;
|
|
9627
10034
|
await this.assertDns01Module();
|
|
@@ -9639,7 +10046,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9639
10046
|
await this.assertPortsFree(this.config.httpPort, this.config.httpsPort);
|
|
9640
10047
|
await this.postConfiguration(rendered);
|
|
9641
10048
|
this.rememberConfig(text);
|
|
9642
|
-
this.
|
|
10049
|
+
this.recordApplied(rendered);
|
|
9643
10050
|
const swept = this.sweepUnroutedCertificates();
|
|
9644
10051
|
if (swept > 0) logger.info(`proxy: dropped ${swept} certificate(s) for names no longer routed`);
|
|
9645
10052
|
this.lastError = null;
|
|
@@ -9716,18 +10123,31 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9716
10123
|
if (fs.existsSync(this.options.configPath)) writeFileAtomic(this.options.previousConfigPath, fs.readFileSync(this.options.configPath, "utf8"), { mode: 384 });
|
|
9717
10124
|
writeFileAtomic(this.options.configPath, text, { mode: 384 });
|
|
9718
10125
|
}
|
|
9719
|
-
/** The ports the engine last bound. */
|
|
10126
|
+
/** The ports the engine last bound — `null` for a configured port the document did not bind. */
|
|
9720
10127
|
readApplied() {
|
|
9721
10128
|
try {
|
|
9722
10129
|
const parsed = appliedRecordSchema(JSON.parse(fs.readFileSync(path.join(this.options.stateDir, "applied.json"), "utf8")));
|
|
9723
10130
|
return parsed instanceof type.errors ? null : {
|
|
9724
|
-
httpPort: parsed.httpPort,
|
|
9725
|
-
httpsPort: parsed.httpsPort
|
|
10131
|
+
httpPort: parsed.httpPort ?? null,
|
|
10132
|
+
httpsPort: parsed.httpsPort ?? null
|
|
9726
10133
|
};
|
|
9727
10134
|
} catch {
|
|
9728
10135
|
return null;
|
|
9729
10136
|
}
|
|
9730
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
|
+
}
|
|
9731
10151
|
rememberApplied(httpPort, httpsPort) {
|
|
9732
10152
|
writeFileAtomic(path.join(this.options.stateDir, "applied.json"), `${JSON.stringify({
|
|
9733
10153
|
httpPort,
|
|
@@ -9757,12 +10177,27 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9757
10177
|
if (this.status().state !== "running") return;
|
|
9758
10178
|
const signature = this.routeViews().map((view) => `${view.route.id}:${view.certificate?.state ?? ""}`).join("|");
|
|
9759
10179
|
if (signature === this.certificateSignature) return;
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
10180
|
+
if (this.certificateSignature === null) {
|
|
10181
|
+
this.certificateSignature = signature;
|
|
10182
|
+
return;
|
|
10183
|
+
}
|
|
10184
|
+
if (Date.now() < this.nextSyncAttemptAt) return;
|
|
10185
|
+
try {
|
|
10186
|
+
await this.apply();
|
|
10187
|
+
this.certificateSignature = signature;
|
|
10188
|
+
this.syncFailures = 0;
|
|
10189
|
+
this.nextSyncAttemptAt = 0;
|
|
10190
|
+
} catch (error) {
|
|
10191
|
+
const message = errorMessage(error);
|
|
10192
|
+
this.syncFailures += 1;
|
|
10193
|
+
this.nextSyncAttemptAt = Date.now() + Math.min(SYNC_RETRY_MAX_MS, SYNC_RETRY_BASE_MS * 2 ** (this.syncFailures - 1));
|
|
10194
|
+
if (message !== this.lastSyncError) {
|
|
10195
|
+
this.lastSyncError = message;
|
|
10196
|
+
logger.warn(`proxy: could not re-apply after a certificate change: ${message}`);
|
|
10197
|
+
}
|
|
10198
|
+
if (this.lastError !== message) this.recordError(message);
|
|
10199
|
+
if (this.syncFailures >= SYNC_MAX_FAILURES) this.certificateSignature = signature;
|
|
10200
|
+
}
|
|
9766
10201
|
}
|
|
9767
10202
|
/**
|
|
9768
10203
|
* Puts the last configuration that applied back, and keeps the rejected one as
|
|
@@ -9775,8 +10210,10 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9775
10210
|
});
|
|
9776
10211
|
const current = fs.existsSync(this.options.configPath) ? fs.readFileSync(this.options.configPath, "utf8") : null;
|
|
9777
10212
|
const previous = fs.readFileSync(this.options.previousConfigPath, "utf8");
|
|
9778
|
-
|
|
10213
|
+
const restored = JSON.parse(previous);
|
|
10214
|
+
await this.postConfiguration(restored);
|
|
9779
10215
|
writeFileAtomic(this.options.configPath, previous, { mode: 384 });
|
|
10216
|
+
this.recordApplied(restored);
|
|
9780
10217
|
if (current === null) fs.rmSync(this.options.previousConfigPath, { force: true });
|
|
9781
10218
|
else writeFileAtomic(this.options.previousConfigPath, current, { mode: 384 });
|
|
9782
10219
|
this.lastError = null;
|
|
@@ -10285,7 +10722,7 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10285
10722
|
code: "ENGINE_NOT_READY"
|
|
10286
10723
|
});
|
|
10287
10724
|
}
|
|
10288
|
-
this.
|
|
10725
|
+
this.recordApplied(rendered);
|
|
10289
10726
|
this.lastError = null;
|
|
10290
10727
|
logger.info(`proxy: ${this.engine.info.label} serving on :${this.config.httpPort} and :${this.config.httpsPort}`);
|
|
10291
10728
|
this.options.onStateChange();
|
|
@@ -10334,13 +10771,43 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10334
10771
|
if (this.nanny !== null) this.nanny.unref();
|
|
10335
10772
|
this.nanny = null;
|
|
10336
10773
|
}
|
|
10774
|
+
/**
|
|
10775
|
+
* "May we bind these ports" — a **start** question, asked before handing the engine a
|
|
10776
|
+
* configuration it would fail to serve.
|
|
10777
|
+
*
|
|
10778
|
+
* A busy port is not automatically a problem: on a re-apply the engine is already bound to it,
|
|
10779
|
+
* which is the normal case. Pid attribution cannot tell the difference — the engine carries
|
|
10780
|
+
* `cap_net_bind_service`, which makes it non-dumpable, so `listPortHolders` returns an empty list
|
|
10781
|
+
* for the very port it serves on, and the old code read that as "nothing there" and then threw.
|
|
10782
|
+
*
|
|
10783
|
+
* What makes a port ours is the engine being live *and this configuration binding it*, both
|
|
10784
|
+
* answerable without inspecting anything: the nanny state's heartbeat, and the rendered config.
|
|
10785
|
+
* Note the two are not `httpPort`/`httpsPort` — a `tls: 'off'`-only config binds no HTTPS
|
|
10786
|
+
* listener, so claiming that port would admit a stranger standing on it.
|
|
10787
|
+
*
|
|
10788
|
+
* An attributable pid that is neither the nanny nor the engine is always foreign, whatever the
|
|
10789
|
+
* records say.
|
|
10790
|
+
*/
|
|
10337
10791
|
async assertPortsFree(httpPort, httpsPort) {
|
|
10792
|
+
const state = readNannyState(nannyStatePath(this.options.stateDir, PROXY_ID));
|
|
10793
|
+
const live = state !== null && await nannyIsAlive(state, PROXY_ID);
|
|
10794
|
+
const applied = this.readApplied();
|
|
10795
|
+
const binds = new Set([applied?.httpPort ?? null, applied?.httpsPort ?? null].filter((port) => port !== null));
|
|
10796
|
+
const enginePids = state === null ? [] : [state.nannyPid, state.childPid].filter((pid) => pid !== null);
|
|
10338
10797
|
for (const port of [httpPort, httpsPort]) {
|
|
10339
10798
|
if (await isPortFree(port)) continue;
|
|
10340
10799
|
const holders = await listPortHolders(port);
|
|
10341
|
-
|
|
10342
|
-
if (
|
|
10343
|
-
|
|
10800
|
+
if (holders.some((pid) => enginePids.includes(pid))) continue;
|
|
10801
|
+
if (holders.length > 0) throw new DetailedError(`port ${port} is already in use${this.describeHolders(port, holders)} — stop what holds it, or set another port in the reverse proxy settings`, {
|
|
10802
|
+
statusCode: 409,
|
|
10803
|
+
code: "PROXY_PORT_IN_USE",
|
|
10804
|
+
detail: {
|
|
10805
|
+
port,
|
|
10806
|
+
holders
|
|
10807
|
+
}
|
|
10808
|
+
});
|
|
10809
|
+
if (live && binds.has(port)) continue;
|
|
10810
|
+
throw new DetailedError(`port ${port} is already in use${this.describeHolders(port, holders)} — stop what holds it, or set another port in the reverse proxy settings`, {
|
|
10344
10811
|
statusCode: 409,
|
|
10345
10812
|
code: "PROXY_PORT_IN_USE",
|
|
10346
10813
|
detail: {
|
|
@@ -10350,6 +10817,23 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10350
10817
|
});
|
|
10351
10818
|
}
|
|
10352
10819
|
}
|
|
10820
|
+
/**
|
|
10821
|
+
* Who holds a busy port, in the most specific terms available.
|
|
10822
|
+
*
|
|
10823
|
+
* An empty holder list is not "nothing is listening": for a capped engine it is the normal
|
|
10824
|
+
* reading, and for a docker-published port it is a root-owned proxy this user may not inspect.
|
|
10825
|
+
* Say which engine it is when it is our own, and say plainly that the socket is uninspectable
|
|
10826
|
+
* rather than implying the port is idle.
|
|
10827
|
+
*/
|
|
10828
|
+
describeHolders(port, holders) {
|
|
10829
|
+
if (holders.length > 0) return ` (pid ${holders.join(", ")})`;
|
|
10830
|
+
if (readNannyState(nannyStatePath(this.options.stateDir, PROXY_ID)) !== null) {
|
|
10831
|
+
const applied = this.readApplied();
|
|
10832
|
+
const bound = [applied?.httpPort ?? null, applied?.httpsPort ?? null].filter((port) => port !== null);
|
|
10833
|
+
return bound.length === 0 ? " — the listener cannot be identified by this user (a process carrying cap_net_bind_service is non-dumpable), and the engine has no applied ports to match it against" : ` — the listener cannot be identified by this user (a process carrying cap_net_bind_service is non-dumpable), and the panel's engine binds :${bound.join("/")}, not this port`;
|
|
10834
|
+
}
|
|
10835
|
+
return " — the socket cannot be inspected by this user, so the holder cannot be named";
|
|
10836
|
+
}
|
|
10353
10837
|
unixAdmin() {
|
|
10354
10838
|
return {
|
|
10355
10839
|
kind: "unix",
|
|
@@ -10715,6 +11199,61 @@ function createServersRoute(deps) {
|
|
|
10715
11199
|
});
|
|
10716
11200
|
throw error;
|
|
10717
11201
|
}
|
|
11202
|
+
}).put("/:id", describeRoute({
|
|
11203
|
+
tags: ["servers"],
|
|
11204
|
+
summary: "Create or replace one entry (idempotent)",
|
|
11205
|
+
responses: {
|
|
11206
|
+
200: {
|
|
11207
|
+
description: "Replaced",
|
|
11208
|
+
content: jsonBody(storedServerResponse)
|
|
11209
|
+
},
|
|
11210
|
+
201: {
|
|
11211
|
+
description: "Created",
|
|
11212
|
+
content: jsonBody(storedServerResponse)
|
|
11213
|
+
},
|
|
11214
|
+
400: ERROR_RESPONSES[400]
|
|
11215
|
+
}
|
|
11216
|
+
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), validate("json", serverCreateSchema), (c) => {
|
|
11217
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11218
|
+
const { id } = c.req.valid("param");
|
|
11219
|
+
const body = c.req.valid("json");
|
|
11220
|
+
if (body.id !== id) throw new DetailedError(`the body's id "${body.id}" does not match the path id "${id}"`, {
|
|
11221
|
+
statusCode: 400,
|
|
11222
|
+
code: "ID_MISMATCH"
|
|
11223
|
+
});
|
|
11224
|
+
try {
|
|
11225
|
+
const result = runtime.store.putServer(body);
|
|
11226
|
+
return c.json({ server: result.server }, result.created ? 201 : 200);
|
|
11227
|
+
} catch (error) {
|
|
11228
|
+
if (error instanceof ConfigError) throw new DetailedError(error.message, {
|
|
11229
|
+
statusCode: 400,
|
|
11230
|
+
code: "INVALID_SERVER"
|
|
11231
|
+
});
|
|
11232
|
+
throw error;
|
|
11233
|
+
}
|
|
11234
|
+
}).post("/orphans/:id/stop", describeRoute({
|
|
11235
|
+
tags: ["servers"],
|
|
11236
|
+
summary: "Stop an orphaned process this panel started",
|
|
11237
|
+
responses: {
|
|
11238
|
+
200: {
|
|
11239
|
+
description: "Stopped",
|
|
11240
|
+
content: jsonBody(okResponseSchema)
|
|
11241
|
+
},
|
|
11242
|
+
404: ERROR_RESPONSES[404],
|
|
11243
|
+
409: { description: "The process survived the stop" }
|
|
11244
|
+
}
|
|
11245
|
+
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
11246
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11247
|
+
const id = c.req.valid("param").id;
|
|
11248
|
+
const result = await runtime.supervisor.stopOrphan(id);
|
|
11249
|
+
if (!result.ok) {
|
|
11250
|
+
const survived = result.error?.includes("survived the stop") === true;
|
|
11251
|
+
throw new DetailedError(result.error ?? `could not stop the orphaned process "${id}"`, {
|
|
11252
|
+
statusCode: survived ? 409 : 404,
|
|
11253
|
+
code: survived ? "ORPHAN_SURVIVED" : "UNKNOWN_ORPHAN"
|
|
11254
|
+
});
|
|
11255
|
+
}
|
|
11256
|
+
return c.json({ ok: true });
|
|
10718
11257
|
}).post("/start-all", describeRoute({
|
|
10719
11258
|
tags: ["servers"],
|
|
10720
11259
|
summary: "Start every enabled server in a workspace",
|
|
@@ -10757,7 +11296,10 @@ function createServersRoute(deps) {
|
|
|
10757
11296
|
tags: ["servers"],
|
|
10758
11297
|
summary: "Buffered log lines from memory",
|
|
10759
11298
|
responses: {
|
|
10760
|
-
200: {
|
|
11299
|
+
200: {
|
|
11300
|
+
description: "Lines",
|
|
11301
|
+
content: jsonBody(logLinesResponseSchema)
|
|
11302
|
+
},
|
|
10761
11303
|
404: ERROR_RESPONSES[404]
|
|
10762
11304
|
}
|
|
10763
11305
|
}), validate("query", bufferedLogsQuery), validate("param", idParam$1), (c) => {
|
|
@@ -10831,41 +11373,56 @@ function createServersRoute(deps) {
|
|
|
10831
11373
|
tags: ["servers"],
|
|
10832
11374
|
summary: "Start a server",
|
|
10833
11375
|
responses: {
|
|
10834
|
-
200: {
|
|
10835
|
-
|
|
11376
|
+
200: {
|
|
11377
|
+
description: "Result",
|
|
11378
|
+
content: jsonBody(actionResultSchema)
|
|
11379
|
+
},
|
|
11380
|
+
404: ERROR_RESPONSES[404],
|
|
11381
|
+
409: { description: "The entry cannot act right now" }
|
|
10836
11382
|
}
|
|
10837
11383
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10838
11384
|
const result = await requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace).supervisor.start(c.req.valid("param").id, { actor: requestActor(c, deps.auth) });
|
|
10839
|
-
return c.json(result, statusForAction(result));
|
|
11385
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10840
11386
|
}).post("/:id/stop", describeRoute({
|
|
10841
11387
|
tags: ["servers"],
|
|
10842
11388
|
summary: "Stop a server",
|
|
10843
11389
|
responses: {
|
|
10844
|
-
200: {
|
|
10845
|
-
|
|
11390
|
+
200: {
|
|
11391
|
+
description: "Result",
|
|
11392
|
+
content: jsonBody(actionResultSchema)
|
|
11393
|
+
},
|
|
11394
|
+
404: ERROR_RESPONSES[404],
|
|
11395
|
+
409: { description: "The entry cannot act right now" }
|
|
10846
11396
|
}
|
|
10847
11397
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10848
11398
|
const result = await requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace).supervisor.stop(c.req.valid("param").id);
|
|
10849
|
-
return c.json(result, result
|
|
11399
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10850
11400
|
}).post("/:id/restart", describeRoute({
|
|
10851
11401
|
tags: ["servers"],
|
|
10852
11402
|
summary: "Restart a server",
|
|
10853
11403
|
responses: {
|
|
10854
|
-
200: {
|
|
10855
|
-
|
|
11404
|
+
200: {
|
|
11405
|
+
description: "Result",
|
|
11406
|
+
content: jsonBody(actionResultSchema)
|
|
11407
|
+
},
|
|
11408
|
+
404: ERROR_RESPONSES[404],
|
|
11409
|
+
409: { description: "The entry cannot act right now" }
|
|
10856
11410
|
}
|
|
10857
11411
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10858
11412
|
const result = await requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace).supervisor.restart(c.req.valid("param").id, { actor: requestActor(c, deps.auth) });
|
|
10859
|
-
return c.json(result, statusForAction(result));
|
|
11413
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10860
11414
|
}).post("/:id/clear-logs", describeRoute({
|
|
10861
11415
|
tags: ["servers"],
|
|
10862
11416
|
summary: "Forget the buffered log lines",
|
|
10863
11417
|
responses: { 200: {
|
|
10864
11418
|
description: "Cleared",
|
|
10865
|
-
content: jsonBody(
|
|
11419
|
+
content: jsonBody(okResponseSchema)
|
|
10866
11420
|
} }
|
|
10867
11421
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), (c) => {
|
|
10868
|
-
requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace)
|
|
11422
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11423
|
+
const { id } = c.req.valid("param");
|
|
11424
|
+
if (!runtime.store.getServer(id)) throw unknownServerError(id);
|
|
11425
|
+
runtime.supervisor.clearLogs(id);
|
|
10869
11426
|
return c.json({ ok: true });
|
|
10870
11427
|
}).post("/:id/free-port", describeRoute({
|
|
10871
11428
|
tags: ["servers"],
|
|
@@ -10884,7 +11441,7 @@ function createServersRoute(deps) {
|
|
|
10884
11441
|
const result = await runtime.supervisor.freePort(id);
|
|
10885
11442
|
if (!result.ok) throw new DetailedError(result.error ?? `could not free the port for "${id}"`, {
|
|
10886
11443
|
statusCode: statusForAction(result),
|
|
10887
|
-
code: "FREE_PORT_FAILED"
|
|
11444
|
+
code: actionCode(result) === "UNKNOWN_SERVER" ? "UNKNOWN_SERVER" : "FREE_PORT_FAILED"
|
|
10888
11445
|
});
|
|
10889
11446
|
return c.json(result);
|
|
10890
11447
|
}).patch("/:id", describeRoute({
|
|
@@ -10918,7 +11475,7 @@ function createServersRoute(deps) {
|
|
|
10918
11475
|
responses: {
|
|
10919
11476
|
200: {
|
|
10920
11477
|
description: "Removed",
|
|
10921
|
-
content: jsonBody(
|
|
11478
|
+
content: jsonBody(okResponseSchema)
|
|
10922
11479
|
},
|
|
10923
11480
|
404: ERROR_RESPONSES[404]
|
|
10924
11481
|
}
|
|
@@ -10935,7 +11492,7 @@ function createServersRoute(deps) {
|
|
|
10935
11492
|
}
|
|
10936
11493
|
});
|
|
10937
11494
|
}
|
|
10938
|
-
var idParam$1, MAX_PENDING_WRITES, serverResponse, serversResponse, storedServerResponse,
|
|
11495
|
+
var idParam$1, MAX_PENDING_WRITES, serverResponse, serversResponse, storedServerResponse, bufferedLogsQuery;
|
|
10939
11496
|
var init_$_routes$1 = __esmMin((() => {
|
|
10940
11497
|
init_store();
|
|
10941
11498
|
init_action_result();
|
|
@@ -10951,7 +11508,6 @@ var init_$_routes$1 = __esmMin((() => {
|
|
|
10951
11508
|
serverResponse = type({ server: serverViewSchema });
|
|
10952
11509
|
serversResponse = type({ servers: serverViewSchema.array() });
|
|
10953
11510
|
storedServerResponse = type({ server: serverSchema });
|
|
10954
|
-
okResponse = type({ ok: "boolean" });
|
|
10955
11511
|
bufferedLogsQuery = logQuerySchema.merge(workspaceQuerySchema);
|
|
10956
11512
|
}));
|
|
10957
11513
|
//#endregion
|
|
@@ -11075,7 +11631,10 @@ function createSettingsRoute(deps) {
|
|
|
11075
11631
|
tags: ["panel"],
|
|
11076
11632
|
summary: "Replace the panel UI with an uploaded static build",
|
|
11077
11633
|
responses: {
|
|
11078
|
-
200: {
|
|
11634
|
+
200: {
|
|
11635
|
+
description: "Installed",
|
|
11636
|
+
content: jsonBody(uiInstallResponseSchema)
|
|
11637
|
+
},
|
|
11079
11638
|
400: ERROR_RESPONSES[400],
|
|
11080
11639
|
413: ERROR_RESPONSES[413]
|
|
11081
11640
|
}
|
|
@@ -11131,7 +11690,10 @@ function createSettingsRoute(deps) {
|
|
|
11131
11690
|
).delete("/settings/ui", describeRoute({
|
|
11132
11691
|
tags: ["panel"],
|
|
11133
11692
|
summary: "Go back to the stock UI",
|
|
11134
|
-
responses: { 200: {
|
|
11693
|
+
responses: { 200: {
|
|
11694
|
+
description: "Reverted",
|
|
11695
|
+
content: jsonBody(uiInstallResponseSchema)
|
|
11696
|
+
} }
|
|
11135
11697
|
}), (c) => {
|
|
11136
11698
|
const removed = deps.ui.revert();
|
|
11137
11699
|
logger.info(removed ? "custom UI removed — the stock panel is back" : "no custom UI was installed");
|
|
@@ -11227,6 +11789,10 @@ function createStaticRoute(options) {
|
|
|
11227
11789
|
const root = currentRoot();
|
|
11228
11790
|
const pathname = safeDecode(new URL(c.req.url).pathname);
|
|
11229
11791
|
if (pathname === null) return c.text("bad path", 400);
|
|
11792
|
+
if (isApiPath(pathname)) return c.json({
|
|
11793
|
+
message: `no route for ${c.req.method} ${pathname}`,
|
|
11794
|
+
code: "NOT_FOUND"
|
|
11795
|
+
}, 404);
|
|
11230
11796
|
const file = resolveWithin(root, pathname);
|
|
11231
11797
|
if (file !== null) {
|
|
11232
11798
|
const response = await serveFile(c, file, pathname);
|
|
@@ -11241,6 +11807,10 @@ function createStaticRoute(options) {
|
|
|
11241
11807
|
});
|
|
11242
11808
|
return route;
|
|
11243
11809
|
}
|
|
11810
|
+
/** `/api` itself and everything under it is the JSON surface, never a UI route. */
|
|
11811
|
+
function isApiPath(pathname) {
|
|
11812
|
+
return pathname === "/api" || pathname.startsWith("/api/");
|
|
11813
|
+
}
|
|
11244
11814
|
function safeDecode(value) {
|
|
11245
11815
|
try {
|
|
11246
11816
|
return decodeURIComponent(value);
|
|
@@ -11312,7 +11882,10 @@ function createTlsRoute(deps) {
|
|
|
11312
11882
|
tags: ["tls"],
|
|
11313
11883
|
summary: "Upload the certificate and key the panel should serve",
|
|
11314
11884
|
responses: {
|
|
11315
|
-
200: {
|
|
11885
|
+
200: {
|
|
11886
|
+
description: "Stored; the panel may be moving to https",
|
|
11887
|
+
content: jsonBody(tlsReviewResponseSchema)
|
|
11888
|
+
},
|
|
11316
11889
|
400: ERROR_RESPONSES[400]
|
|
11317
11890
|
}
|
|
11318
11891
|
}), validate("json", tlsUploadSchema), (c) => {
|
|
@@ -11331,7 +11904,10 @@ function createTlsRoute(deps) {
|
|
|
11331
11904
|
}).delete("/settings/tls", describeRoute({
|
|
11332
11905
|
tags: ["tls"],
|
|
11333
11906
|
summary: "Remove the certificate pair",
|
|
11334
|
-
responses: { 200: {
|
|
11907
|
+
responses: { 200: {
|
|
11908
|
+
description: "Removed",
|
|
11909
|
+
content: jsonBody(tlsReviewResponseSchema)
|
|
11910
|
+
} }
|
|
11335
11911
|
}), (c) => {
|
|
11336
11912
|
deps.tls.clear();
|
|
11337
11913
|
if (deps.panel.settings.control.tls.enabled) afterResponse(async () => {
|
|
@@ -11520,6 +12096,10 @@ function setupOpenAPI(app) {
|
|
|
11520
12096
|
name: "logs",
|
|
11521
12097
|
description: "Live and persisted logs"
|
|
11522
12098
|
},
|
|
12099
|
+
{
|
|
12100
|
+
name: "workspaces",
|
|
12101
|
+
description: "The ownership boundary: one scope per setup"
|
|
12102
|
+
},
|
|
11523
12103
|
{
|
|
11524
12104
|
name: "backups",
|
|
11525
12105
|
description: "Archives of config, secrets, TLS and data paths"
|
|
@@ -11530,13 +12110,40 @@ function setupOpenAPI(app) {
|
|
|
11530
12110
|
},
|
|
11531
12111
|
{
|
|
11532
12112
|
name: "notifications",
|
|
11533
|
-
description: "Telegram delivery"
|
|
12113
|
+
description: "Telegram delivery and webhook destinations"
|
|
12114
|
+
},
|
|
12115
|
+
{
|
|
12116
|
+
name: "ddns",
|
|
12117
|
+
description: "Dynamic DNS accounts and hostnames"
|
|
12118
|
+
},
|
|
12119
|
+
{
|
|
12120
|
+
name: "proxy",
|
|
12121
|
+
description: "The reverse proxy: engine, routes and certificates"
|
|
11534
12122
|
},
|
|
11535
12123
|
{
|
|
11536
12124
|
name: "tls",
|
|
11537
12125
|
description: "The panel certificate"
|
|
11538
12126
|
}
|
|
11539
|
-
]
|
|
12127
|
+
],
|
|
12128
|
+
/**
|
|
12129
|
+
* The auth scheme, so a generated client can be told how to send a credential.
|
|
12130
|
+
*
|
|
12131
|
+
* Every `/api` route takes `Authorization: Bearer hh_…`, and the spec said nothing
|
|
12132
|
+
* about it: openapi-typescript, openapi-generator and Scalar's "try it" all produced
|
|
12133
|
+
* clients with no auth hook, and the README tells an agent this document *is* the API
|
|
12134
|
+
* it may call. Two lines here are the difference between generating a client and
|
|
12135
|
+
* hand-writing one.
|
|
12136
|
+
*/
|
|
12137
|
+
components: { securitySchemes: { bearerAuth: {
|
|
12138
|
+
type: "http",
|
|
12139
|
+
scheme: "bearer",
|
|
12140
|
+
description: "An API token from `home-hosted set-token --generate`. A cookie session works too, but is not part of this scheme."
|
|
12141
|
+
} } },
|
|
12142
|
+
security: [{ bearerAuth: [] }],
|
|
12143
|
+
servers: [{
|
|
12144
|
+
url: "/",
|
|
12145
|
+
description: "This panel"
|
|
12146
|
+
}]
|
|
11540
12147
|
} })).get(`${PREFIX}/ui`, Scalar({
|
|
11541
12148
|
theme: "deepSpace",
|
|
11542
12149
|
url: `${PREFIX}/spec.json`
|
|
@@ -11715,8 +12322,8 @@ async function requestShutdown(runtime, timeoutMs = 4e3) {
|
|
|
11715
12322
|
* The wait is generous on purpose: a start may have to run a bootstrap, which has a
|
|
11716
12323
|
* 120s default timeout of its own. Past this it is a wedged panel, not a slow one.
|
|
11717
12324
|
*/
|
|
11718
|
-
async function requestControl(runtime, path, timeoutMs = 15e4) {
|
|
11719
|
-
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);
|
|
11720
12327
|
if (answer === null) return null;
|
|
11721
12328
|
let body = null;
|
|
11722
12329
|
try {
|
|
@@ -12597,18 +13204,28 @@ function dependentsOf(server, servers) {
|
|
|
12597
13204
|
var init_dependencies = __esmMin((() => {}));
|
|
12598
13205
|
//#endregion
|
|
12599
13206
|
//#region src/services/log-buffer.ts
|
|
12600
|
-
var MAX_PENDING_CHARS, LogBuffer, LineSplitter;
|
|
13207
|
+
var MAX_PENDING_CHARS, MAX_TOTAL_CHARS, LogBuffer, LineSplitter;
|
|
12601
13208
|
var init_log_buffer = __esmMin((() => {
|
|
12602
13209
|
MAX_PENDING_CHARS = 65536;
|
|
13210
|
+
MAX_TOTAL_CHARS = 4194304;
|
|
12603
13211
|
LogBuffer = class {
|
|
12604
13212
|
capacity;
|
|
12605
13213
|
lines = [];
|
|
13214
|
+
/** Characters held, so the byte ceiling never needs a rescan. */
|
|
13215
|
+
chars = 0;
|
|
12606
13216
|
constructor(capacity) {
|
|
12607
13217
|
this.capacity = capacity;
|
|
12608
13218
|
}
|
|
12609
13219
|
push(line) {
|
|
12610
13220
|
this.lines.push(line);
|
|
12611
|
-
|
|
13221
|
+
this.chars += line.text.length;
|
|
13222
|
+
if (this.lines.length > this.capacity) this.dropOldest(this.lines.length - this.capacity);
|
|
13223
|
+
while (this.chars > MAX_TOTAL_CHARS && this.lines.length > 1) this.dropOldest(1);
|
|
13224
|
+
}
|
|
13225
|
+
/** Removes the oldest `count` lines and keeps `chars` in step with them. */
|
|
13226
|
+
dropOldest(count) {
|
|
13227
|
+
const dropped = this.lines.splice(0, count);
|
|
13228
|
+
for (const line of dropped) this.chars -= line.text.length;
|
|
12612
13229
|
}
|
|
12613
13230
|
extend(lines) {
|
|
12614
13231
|
for (const line of lines) this.push(line);
|
|
@@ -12619,6 +13236,7 @@ var init_log_buffer = __esmMin((() => {
|
|
|
12619
13236
|
}
|
|
12620
13237
|
clear() {
|
|
12621
13238
|
this.lines = [];
|
|
13239
|
+
this.chars = 0;
|
|
12622
13240
|
}
|
|
12623
13241
|
get size() {
|
|
12624
13242
|
return this.lines.length;
|
|
@@ -12970,6 +13588,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
12970
13588
|
*/
|
|
12971
13589
|
relay = new LogRelay({ onLines: (serverId, lines) => this.ingestExternalLines(serverId, lines) });
|
|
12972
13590
|
entries = /* @__PURE__ */ new Map();
|
|
13591
|
+
/** Processes no entry owns, refreshed by the tick; read synchronously by the state frame. */
|
|
13592
|
+
orphanCache = [];
|
|
12973
13593
|
tickTimer;
|
|
12974
13594
|
/** Detaches this supervisor from the store's listener set in `dispose()`. */
|
|
12975
13595
|
storeUnsubscribe;
|
|
@@ -12990,6 +13610,82 @@ var init_supervisor = __esmMin((() => {
|
|
|
12990
13610
|
views() {
|
|
12991
13611
|
return [...this.entries.values()].map((entry) => this.view(entry));
|
|
12992
13612
|
}
|
|
13613
|
+
/**
|
|
13614
|
+
* Processes this panel started that no configured entry claims any more.
|
|
13615
|
+
*
|
|
13616
|
+
* A detached child outlives a hard panel death, and the only handle is the entry-state file
|
|
13617
|
+
* keyed by the id it was started under. Rename the entry and no code path reads that file again;
|
|
13618
|
+
* remove the entry while the panel is down and `sync` reclaims it, destroying the last handle.
|
|
13619
|
+
* The orphan then runs with no card, no `/healthz` line and no CLI action — for a queue consumer
|
|
13620
|
+
* that is two consumers of one queue, which is the most damaging duplicate this tool can create.
|
|
13621
|
+
*
|
|
13622
|
+
* Read from the state directory rather than from a list, so a file left by an *earlier* panel is
|
|
13623
|
+
* found too. Reported, never touched: a pid here is one whose identity the platform may not be
|
|
13624
|
+
* able to confirm, and killing on a guess is exactly what the rest of this file refuses to do.
|
|
13625
|
+
*/
|
|
13626
|
+
orphans() {
|
|
13627
|
+
return [...this.orphanCache];
|
|
13628
|
+
}
|
|
13629
|
+
/**
|
|
13630
|
+
* Re-reads the state directory for processes no entry owns.
|
|
13631
|
+
*
|
|
13632
|
+
* Async (it asks the platform for a birth time per pid) and therefore driven by the tick, not by
|
|
13633
|
+
* the state frame: the view is built on every publish, and a `readdirSync` plus an async birth
|
|
13634
|
+
* check there would either block or force the whole frame async.
|
|
13635
|
+
*/
|
|
13636
|
+
async refreshOrphans() {
|
|
13637
|
+
let names;
|
|
13638
|
+
try {
|
|
13639
|
+
names = fs.readdirSync(this.options.nannyDir);
|
|
13640
|
+
} catch {
|
|
13641
|
+
this.orphanCache = [];
|
|
13642
|
+
return;
|
|
13643
|
+
}
|
|
13644
|
+
const found = [];
|
|
13645
|
+
for (const name of names) {
|
|
13646
|
+
if (!name.endsWith(".run.json")) continue;
|
|
13647
|
+
const id = name.slice(0, -9);
|
|
13648
|
+
if (this.entries.has(id)) continue;
|
|
13649
|
+
const state = readEntryState(path.join(this.options.nannyDir, name));
|
|
13650
|
+
const pid = state?.lastPid ?? null;
|
|
13651
|
+
if (pid === null || pid === process.pid) continue;
|
|
13652
|
+
const startedAt = state?.lastStartedAt ?? 0;
|
|
13653
|
+
const liveness = startedAt > 0 ? await processLiveness(pid, startedAt) : isProcessAlive(pid) ? "unknown" : "gone";
|
|
13654
|
+
if (liveness === "gone" || liveness === "recycled") continue;
|
|
13655
|
+
found.push({
|
|
13656
|
+
serverId: id,
|
|
13657
|
+
pid,
|
|
13658
|
+
startedAt: startedAt > 0 ? startedAt : null
|
|
13659
|
+
});
|
|
13660
|
+
}
|
|
13661
|
+
this.orphanCache = found;
|
|
13662
|
+
}
|
|
13663
|
+
/**
|
|
13664
|
+
* Stops one reported orphan and reclaims its record.
|
|
13665
|
+
*
|
|
13666
|
+
* Reporting without acting is a dead end: the alternative was `ps` + `kill` in a shell, which is
|
|
13667
|
+
* the thing this panel exists to avoid. The record is cleared only once the pid is gone — a pid
|
|
13668
|
+
* that survived SIGKILL keeps its file, so the next boot can still find it.
|
|
13669
|
+
*/
|
|
13670
|
+
async stopOrphan(serverId) {
|
|
13671
|
+
await this.refreshOrphans();
|
|
13672
|
+
const orphan = this.orphans().find((entry) => entry.serverId === serverId);
|
|
13673
|
+
if (orphan === void 0) return {
|
|
13674
|
+
ok: false,
|
|
13675
|
+
error: `no orphaned process is running as "${serverId}"`
|
|
13676
|
+
};
|
|
13677
|
+
const { forced } = await terminatePids([orphan.pid], { graceMs: 5e3 });
|
|
13678
|
+
const statePath = entryStatePath(this.options.nannyDir, serverId);
|
|
13679
|
+
if (isProcessAlive(orphan.pid)) return {
|
|
13680
|
+
ok: false,
|
|
13681
|
+
error: `pid ${orphan.pid} survived the stop — kill it from a shell, its record is kept`
|
|
13682
|
+
};
|
|
13683
|
+
clearEntryState(statePath);
|
|
13684
|
+
await this.refreshOrphans();
|
|
13685
|
+
logger.info(`stopped the orphaned process ${orphan.pid} (was "${serverId}")${forced.length > 0 ? ", force-killed" : ""}`);
|
|
13686
|
+
this.publishState();
|
|
13687
|
+
return { ok: true };
|
|
13688
|
+
}
|
|
12993
13689
|
logLines(id, limit) {
|
|
12994
13690
|
return this.entries.get(id)?.logs.list(limit) ?? [];
|
|
12995
13691
|
}
|
|
@@ -13041,9 +13737,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
13041
13737
|
};
|
|
13042
13738
|
entry.starting = true;
|
|
13043
13739
|
entry.actor = options.retry ? "policy" : options.actor ?? "policy";
|
|
13740
|
+
entry.stoppedByPanel = false;
|
|
13044
13741
|
this.clearRetry(entry);
|
|
13045
13742
|
if (!options.retry) {
|
|
13046
13743
|
entry.restarts = 0;
|
|
13744
|
+
if (entry.actor !== "policy") entry.healthRestarts = 0;
|
|
13745
|
+
if (entry.actor !== "policy") entry.pendingRestart = null;
|
|
13047
13746
|
entry.healthFailures = 0;
|
|
13048
13747
|
entry.unhealthySince = null;
|
|
13049
13748
|
this.persistEntryState(entry);
|
|
@@ -13093,7 +13792,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
13093
13792
|
return this.stopEntry(entry);
|
|
13094
13793
|
}
|
|
13095
13794
|
async restart(id, options = {}) {
|
|
13795
|
+
const owed = this.entries.get(id)?.pendingRestart ?? null;
|
|
13096
13796
|
await this.stop(id);
|
|
13797
|
+
const entry = this.entries.get(id);
|
|
13798
|
+
if (entry !== void 0 && owed !== null && entry.pendingRestart === null) entry.pendingRestart = owed;
|
|
13097
13799
|
return this.start(id, options);
|
|
13098
13800
|
}
|
|
13099
13801
|
/**
|
|
@@ -13129,11 +13831,45 @@ var init_supervisor = __esmMin((() => {
|
|
|
13129
13831
|
error: `server "${id}" is busy — try again in a moment`
|
|
13130
13832
|
};
|
|
13131
13833
|
const { ours, foreign } = await this.portHolders(port);
|
|
13132
|
-
if ([...ours, ...foreign].length === 0)
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
13834
|
+
if ([...ours, ...foreign].length === 0) {
|
|
13835
|
+
const docker = await findDockerPortHolder(port);
|
|
13836
|
+
if (docker !== null) {
|
|
13837
|
+
this.log(entry, "system", `freeing port ${port}: stopping the docker container "${docker.container}"`);
|
|
13838
|
+
if (await releaseDockerPort(docker) && await this.waitForPortRelease(entry, port)) {
|
|
13839
|
+
if (entry.status === "conflict") {
|
|
13840
|
+
entry.status = "stopped";
|
|
13841
|
+
entry.lastError = null;
|
|
13842
|
+
}
|
|
13843
|
+
entry.portState = "free";
|
|
13844
|
+
this.log(entry, "system", `port ${port} is free (stopped the docker container "${docker.container}")`);
|
|
13845
|
+
this.publishServer(entry);
|
|
13846
|
+
return {
|
|
13847
|
+
...empty,
|
|
13848
|
+
ok: true,
|
|
13849
|
+
port,
|
|
13850
|
+
terminated: [],
|
|
13851
|
+
forced: [],
|
|
13852
|
+
skipped: [],
|
|
13853
|
+
free: true
|
|
13854
|
+
};
|
|
13855
|
+
}
|
|
13856
|
+
return {
|
|
13857
|
+
...empty,
|
|
13858
|
+
port,
|
|
13859
|
+
error: `docker could not stop the container "${docker.container}" publishing port ${port} — check \`docker logs ${docker.container}\``
|
|
13860
|
+
};
|
|
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
|
+
};
|
|
13867
|
+
return {
|
|
13868
|
+
...empty,
|
|
13869
|
+
port,
|
|
13870
|
+
error: `nothing is listening on port ${port} any more`
|
|
13871
|
+
};
|
|
13872
|
+
}
|
|
13137
13873
|
if (foreign.length === 0) {
|
|
13138
13874
|
const reason = `port ${port} is held by pid ${ours.join(", ")}, which this panel supervises — stop that server instead`;
|
|
13139
13875
|
return {
|
|
@@ -13237,13 +13973,14 @@ var init_supervisor = __esmMin((() => {
|
|
|
13237
13973
|
for (const dependency of dependenciesOf(entry.config, this.store.servers)) {
|
|
13238
13974
|
const target = this.entries.get(dependency.id);
|
|
13239
13975
|
if (!target || !dependency.enabled) continue;
|
|
13240
|
-
if (target.status
|
|
13241
|
-
|
|
13242
|
-
|
|
13976
|
+
if (target.status !== "running" && target.child === null) {
|
|
13977
|
+
this.log(entry, "system", `starting dependency "${dependency.id}" first`);
|
|
13978
|
+
await this.start(dependency.id);
|
|
13979
|
+
}
|
|
13243
13980
|
const deadline = Date.now() + dependency.health.startTimeoutMs;
|
|
13244
13981
|
const isReady = () => {
|
|
13245
13982
|
if (this.statusOf(target) !== "running") return false;
|
|
13246
|
-
return target.health
|
|
13983
|
+
return target.health === "healthy" || target.health === "disabled";
|
|
13247
13984
|
};
|
|
13248
13985
|
while (!isReady() && Date.now() < deadline) await delay(250);
|
|
13249
13986
|
if (!isReady()) {
|
|
@@ -13357,15 +14094,18 @@ var init_supervisor = __esmMin((() => {
|
|
|
13357
14094
|
exitCode: null,
|
|
13358
14095
|
exitSignal: null,
|
|
13359
14096
|
restarts: persisted?.restarts ?? 0,
|
|
14097
|
+
healthRestarts: persisted?.healthRestarts ?? 0,
|
|
13360
14098
|
lastError: null,
|
|
13361
14099
|
nextRetryAt: null,
|
|
13362
14100
|
retryTimer: null,
|
|
13363
14101
|
healthFailures: 0,
|
|
13364
14102
|
unhealthySince: null,
|
|
14103
|
+
pendingRestart: null,
|
|
13365
14104
|
lastProbeAt: 0,
|
|
13366
14105
|
lastOccupancyProbeAt: 0,
|
|
13367
14106
|
probing: false,
|
|
13368
14107
|
adopted: false,
|
|
14108
|
+
stoppedByPanel: false,
|
|
13369
14109
|
nannyExit: null,
|
|
13370
14110
|
starting: false,
|
|
13371
14111
|
stopping: false,
|
|
@@ -13471,7 +14211,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
13471
14211
|
const { ours, foreign } = await this.portHolders(port);
|
|
13472
14212
|
const holders = [...ours, ...foreign];
|
|
13473
14213
|
const own = await this.ownPortHolder(entry, foreign);
|
|
13474
|
-
const
|
|
14214
|
+
const docker = holders.length === 0 ? await findDockerPortHolder(port) : null;
|
|
14215
|
+
const suffix = holders.length > 0 ? ` (pid ${holders.join(", ")})` : docker === null ? "" : ` (published by the docker container "${docker.container}")`;
|
|
13475
14216
|
if (entry.config.onPortConflict === "kill") {
|
|
13476
14217
|
if (ours.length > 0) {
|
|
13477
14218
|
entry.status = "conflict";
|
|
@@ -13484,6 +14225,17 @@ var init_supervisor = __esmMin((() => {
|
|
|
13484
14225
|
};
|
|
13485
14226
|
}
|
|
13486
14227
|
if (foreign.length === 0) {
|
|
14228
|
+
if (docker !== null) {
|
|
14229
|
+
this.log(entry, "system", `port ${port} is published by the docker container "${docker.container}" — onPortConflict: kill, stopping it`);
|
|
14230
|
+
if (await releaseDockerPort(docker) && await this.waitForPortRelease(entry, port)) return { kind: "free" };
|
|
14231
|
+
entry.status = "conflict";
|
|
14232
|
+
entry.lastError = `docker could not stop the container "${docker.container}" publishing port ${port}`;
|
|
14233
|
+
this.publishServer(entry);
|
|
14234
|
+
return {
|
|
14235
|
+
kind: "blocked",
|
|
14236
|
+
error: entry.lastError
|
|
14237
|
+
};
|
|
14238
|
+
}
|
|
13487
14239
|
this.log(entry, "system", `port ${port} looks busy but no listener could be found — starting anyway`);
|
|
13488
14240
|
return { kind: "free" };
|
|
13489
14241
|
}
|
|
@@ -13498,7 +14250,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13498
14250
|
this.log(entry, "system", `port ${port} is held by pid ${own}, a detached restart of this entry — replacing it with a supervised process`);
|
|
13499
14251
|
return await this.stopPortHolders(entry, [own], port, "replacing", freeOnAll);
|
|
13500
14252
|
}
|
|
13501
|
-
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` : "";
|
|
14253
|
+
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`;
|
|
13502
14254
|
if (entry.config.onPortConflict !== "warn") {
|
|
13503
14255
|
entry.status = "conflict";
|
|
13504
14256
|
entry.lastError = `port ${port} is already in use${suffix}${hint}`;
|
|
@@ -13624,6 +14376,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13624
14376
|
this.forgetRecordedChild(entry, adoptedPid);
|
|
13625
14377
|
entry.resources = null;
|
|
13626
14378
|
entry.responseMs = null;
|
|
14379
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
13627
14380
|
entry.exitCode = null;
|
|
13628
14381
|
entry.exitSignal = null;
|
|
13629
14382
|
if (!entry.removed) this.options.history.record(entry.config.id, {
|
|
@@ -13847,7 +14600,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13847
14600
|
entry.unhealthySince = null;
|
|
13848
14601
|
this.publishServer(entry);
|
|
13849
14602
|
child.once("error", (error) => {
|
|
13850
|
-
entry.lastError = error.
|
|
14603
|
+
entry.lastError = describeSpawnError(error, entry.config.command);
|
|
13851
14604
|
this.log(entry, "system", `process error: ${entry.lastError}`);
|
|
13852
14605
|
flush?.();
|
|
13853
14606
|
this.handleExit(entry, child, null, null);
|
|
@@ -13966,6 +14719,21 @@ var init_supervisor = __esmMin((() => {
|
|
|
13966
14719
|
clearNannyState(statePath);
|
|
13967
14720
|
this.drainRelay(entry);
|
|
13968
14721
|
}
|
|
14722
|
+
/**
|
|
14723
|
+
* Announces the outcome of a force restart, once, the first moment the entry is serving.
|
|
14724
|
+
*
|
|
14725
|
+
* Every "it is up again" path calls this — spawn with no port, readiness accepted, and the
|
|
14726
|
+
* first healthy probe — and the pending flag makes it idempotent, so whichever happens
|
|
14727
|
+
* first is the one that reports.
|
|
14728
|
+
*/
|
|
14729
|
+
settleRestart(entry, detail) {
|
|
14730
|
+
const pending = entry.pendingRestart;
|
|
14731
|
+
if (pending === null) return;
|
|
14732
|
+
entry.pendingRestart = null;
|
|
14733
|
+
const message = `after ${pending.cause}: ${detail}`;
|
|
14734
|
+
this.log(entry, "system", `restarted, and it is serving again — ${message}`);
|
|
14735
|
+
this.notify(entry, "restart-ok", message);
|
|
14736
|
+
}
|
|
13969
14737
|
/** One probe using the configured mode (TCP or HTTP), with timing. */
|
|
13970
14738
|
async probeEntryHealth(entry) {
|
|
13971
14739
|
const { port, health } = entry.config;
|
|
@@ -13989,6 +14757,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13989
14757
|
entry.status = "running";
|
|
13990
14758
|
entry.health = health.enabled ? "unknown" : "disabled";
|
|
13991
14759
|
this.log(entry, "system", "running (no port configured; readiness assumed on spawn)");
|
|
14760
|
+
this.settleRestart(entry, "it spawned and is running");
|
|
13992
14761
|
this.publishServer(entry);
|
|
13993
14762
|
return;
|
|
13994
14763
|
}
|
|
@@ -13997,10 +14766,11 @@ var init_supervisor = __esmMin((() => {
|
|
|
13997
14766
|
if (entry.child !== child || entry.status !== "starting" || this.disposed) return;
|
|
13998
14767
|
if (await this.portAccepts(entry, port, Math.min(health.timeoutMs, 1e3))) {
|
|
13999
14768
|
entry.portState = "in-use";
|
|
14000
|
-
entry.health = health.enabled ? "
|
|
14769
|
+
entry.health = !health.enabled ? "disabled" : health.mode === "http" ? "unknown" : "healthy";
|
|
14001
14770
|
entry.status = "running";
|
|
14002
|
-
entry.lastProbeAt =
|
|
14771
|
+
entry.lastProbeAt = 0;
|
|
14003
14772
|
this.log(entry, "system", `accepting connections on port ${port}`);
|
|
14773
|
+
if (health.mode !== "http") this.settleRestart(entry, `accepting connections on port ${port}`);
|
|
14004
14774
|
this.publishServer(entry);
|
|
14005
14775
|
return;
|
|
14006
14776
|
}
|
|
@@ -14025,6 +14795,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14025
14795
|
entry.adopted = false;
|
|
14026
14796
|
entry.resources = null;
|
|
14027
14797
|
entry.responseMs = null;
|
|
14798
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
14028
14799
|
entry.exitCode = code;
|
|
14029
14800
|
entry.exitSignal = signal;
|
|
14030
14801
|
this.forgetRecordedChild(entry, child.pid ?? null);
|
|
@@ -14076,6 +14847,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14076
14847
|
} else {
|
|
14077
14848
|
entry.status = "crashed";
|
|
14078
14849
|
entry.nextRetryAt = null;
|
|
14850
|
+
entry.pendingRestart = null;
|
|
14079
14851
|
entry.lastError = restart.enabled ? `gave up after ${restart.maxRetries} retries (${detail})` : `${detail} (automatic restart disabled)`;
|
|
14080
14852
|
this.log(entry, "system", entry.lastError);
|
|
14081
14853
|
this.options.history.record(entry.config.id, {
|
|
@@ -14091,6 +14863,9 @@ var init_supervisor = __esmMin((() => {
|
|
|
14091
14863
|
if (this.disposed) return;
|
|
14092
14864
|
const now = Date.now();
|
|
14093
14865
|
await this.sampleResources(now);
|
|
14866
|
+
await this.refreshOrphans().catch((error) => {
|
|
14867
|
+
logger.warn("could not refresh the orphaned-process list", error);
|
|
14868
|
+
});
|
|
14094
14869
|
await Promise.allSettled([...this.entries.values()].map((entry) => this.probeEntry(entry, now)));
|
|
14095
14870
|
for (const entry of this.entries.values()) {
|
|
14096
14871
|
if (entry.adopted && entry.pid !== null && !isProcessAlive(entry.pid)) {
|
|
@@ -14098,6 +14873,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
14098
14873
|
continue;
|
|
14099
14874
|
}
|
|
14100
14875
|
if (await this.enforceMemoryLimit(entry)) continue;
|
|
14876
|
+
if (this.healthBudgetSpent(entry)) {
|
|
14877
|
+
await this.giveUpOnHealth(entry);
|
|
14878
|
+
continue;
|
|
14879
|
+
}
|
|
14101
14880
|
if (this.shouldForceRestart(entry, now)) {
|
|
14102
14881
|
await this.restart(entry.config.id);
|
|
14103
14882
|
continue;
|
|
@@ -14142,9 +14921,15 @@ var init_supervisor = __esmMin((() => {
|
|
|
14142
14921
|
});
|
|
14143
14922
|
this.notify(entry, "recovered", probe.detail);
|
|
14144
14923
|
}
|
|
14924
|
+
this.settleRestart(entry, `${probe.detail} (${probe.ms}ms)`);
|
|
14145
14925
|
entry.health = "healthy";
|
|
14146
14926
|
entry.healthFailures = 0;
|
|
14147
14927
|
entry.unhealthySince = null;
|
|
14928
|
+
const servedForMs = entry.startedAt === null ? 0 : Date.now() - entry.startedAt;
|
|
14929
|
+
if (entry.healthRestarts > 0 && servedForMs >= entry.config.restart.resetAfterMs) {
|
|
14930
|
+
entry.healthRestarts = 0;
|
|
14931
|
+
this.persistEntryState(entry);
|
|
14932
|
+
}
|
|
14148
14933
|
return;
|
|
14149
14934
|
}
|
|
14150
14935
|
entry.healthFailures += 1;
|
|
@@ -14175,22 +14960,58 @@ var init_supervisor = __esmMin((() => {
|
|
|
14175
14960
|
detail
|
|
14176
14961
|
});
|
|
14177
14962
|
this.notify(entry, "rss", detail);
|
|
14963
|
+
entry.pendingRestart = { cause: "exceeding its memory limit" };
|
|
14178
14964
|
await this.restart(entry.config.id);
|
|
14179
14965
|
return true;
|
|
14180
14966
|
}
|
|
14181
14967
|
shouldForceRestart(entry, now) {
|
|
14182
|
-
const { port, health } = entry.config;
|
|
14968
|
+
const { port, health, restart } = entry.config;
|
|
14183
14969
|
if (port === null || entry.status !== "running" || entry.health !== "unhealthy") return false;
|
|
14184
14970
|
if (entry.unhealthySince === null || health.forceRestartAfterMs <= 0) return false;
|
|
14185
14971
|
if (now - entry.unhealthySince < health.forceRestartAfterMs) return false;
|
|
14186
|
-
|
|
14972
|
+
if (!restart.enabled || entry.healthRestarts >= restart.maxRetries) return false;
|
|
14973
|
+
entry.healthRestarts += 1;
|
|
14974
|
+
this.persistEntryState(entry);
|
|
14975
|
+
this.log(entry, "system", `unhealthy for ${health.forceRestartAfterMs}ms — forcing a restart (${entry.healthRestarts}/${restart.maxRetries})`);
|
|
14187
14976
|
this.options.history.record(entry.config.id, {
|
|
14188
14977
|
type: "forced-restart",
|
|
14189
14978
|
detail: `health check stayed unhealthy`
|
|
14190
14979
|
});
|
|
14191
14980
|
this.notify(entry, "forced-restart", `unhealthy for ${Math.round(health.forceRestartAfterMs / 1e3)}s`);
|
|
14981
|
+
entry.pendingRestart = { cause: "staying unhealthy through its health check" };
|
|
14192
14982
|
return true;
|
|
14193
14983
|
}
|
|
14984
|
+
/** Whether this entry's health budget is spent, so the tick should stop it. */
|
|
14985
|
+
healthBudgetSpent(entry) {
|
|
14986
|
+
const { port, health, restart } = entry.config;
|
|
14987
|
+
if (port === null || entry.status !== "running" || entry.health !== "unhealthy") return false;
|
|
14988
|
+
if (entry.unhealthySince === null || health.forceRestartAfterMs <= 0) return false;
|
|
14989
|
+
return !restart.enabled || entry.healthRestarts >= restart.maxRetries;
|
|
14990
|
+
}
|
|
14991
|
+
/**
|
|
14992
|
+
* Stops an entry that cannot pass its own health check, once the restart budget is spent.
|
|
14993
|
+
*
|
|
14994
|
+
* `stopped` because the process really is stopped; the reason stays on `lastError`, so the card
|
|
14995
|
+
* and the notification still say why. Marking it `crashed` while leaving it running would report
|
|
14996
|
+
* a live pid and a serving port as down.
|
|
14997
|
+
*/
|
|
14998
|
+
async giveUpOnHealth(entry) {
|
|
14999
|
+
const detail = entry.config.restart.enabled ? `stopped after ${entry.config.restart.maxRetries} health restarts (the health check kept failing)` : "stopped because health restarts are disabled and the health check is failing";
|
|
15000
|
+
entry.pendingRestart = null;
|
|
15001
|
+
entry.healthRestarts = 0;
|
|
15002
|
+
entry.stoppedByPanel = true;
|
|
15003
|
+
this.log(entry, "system", detail);
|
|
15004
|
+
this.options.history.record(entry.config.id, {
|
|
15005
|
+
type: "crash",
|
|
15006
|
+
detail
|
|
15007
|
+
});
|
|
15008
|
+
this.notify(entry, "crash", detail);
|
|
15009
|
+
await this.stopEntry(entry);
|
|
15010
|
+
if (!entry.removed) {
|
|
15011
|
+
entry.lastError = detail;
|
|
15012
|
+
this.publishServer(entry);
|
|
15013
|
+
}
|
|
15014
|
+
}
|
|
14194
15015
|
clearRetry(entry) {
|
|
14195
15016
|
if (entry.retryTimer !== null) {
|
|
14196
15017
|
clearTimeout(entry.retryTimer);
|
|
@@ -14202,6 +15023,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14202
15023
|
if (entry.removed) return;
|
|
14203
15024
|
writeEntryState(entryStatePath(this.options.nannyDir, entry.config.id), {
|
|
14204
15025
|
restarts: entry.restarts,
|
|
15026
|
+
healthRestarts: entry.healthRestarts,
|
|
14205
15027
|
bootstrapDone: entry.bootstrapDone,
|
|
14206
15028
|
lastPid: entry.config.persistent ? null : entry.lastChild?.pid ?? null,
|
|
14207
15029
|
lastStartedAt: entry.config.persistent ? null : entry.lastChild?.startedAt ?? null
|
|
@@ -14224,6 +15046,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14224
15046
|
portState: entry.portState,
|
|
14225
15047
|
pid: entry.pid,
|
|
14226
15048
|
...entry.adopted ? { adopted: true } : {},
|
|
15049
|
+
...entry.stoppedByPanel ? { stoppedByPanel: true } : {},
|
|
14227
15050
|
startedAt: entry.startedAt,
|
|
14228
15051
|
exitCode: entry.exitCode,
|
|
14229
15052
|
exitSignal: entry.exitSignal,
|
|
@@ -14461,6 +15284,39 @@ function readableGlobalSettings(text) {
|
|
|
14461
15284
|
}
|
|
14462
15285
|
}
|
|
14463
15286
|
/**
|
|
15287
|
+
* The workspaces an archive's registry names.
|
|
15288
|
+
*
|
|
15289
|
+
* Tolerant on purpose: an archive written before the registry was captured has no such
|
|
15290
|
+
* file, and a damaged one must not fail a restore whose leaves are perfectly readable.
|
|
15291
|
+
* The registry only contributes labels, so anything unreadable is simply dropped.
|
|
15292
|
+
*/
|
|
15293
|
+
function readArchivedRegistry(file) {
|
|
15294
|
+
const text = readText(file);
|
|
15295
|
+
if (text === null) return [];
|
|
15296
|
+
try {
|
|
15297
|
+
const parsed = workspacesFileSchema(JSON.parse(text));
|
|
15298
|
+
if (parsed instanceof type.errors) return [];
|
|
15299
|
+
return parsed.workspaces;
|
|
15300
|
+
} catch {
|
|
15301
|
+
return [];
|
|
15302
|
+
}
|
|
15303
|
+
}
|
|
15304
|
+
/**
|
|
15305
|
+
* Where a workspace created by a restore keeps its three leaves.
|
|
15306
|
+
*
|
|
15307
|
+
* Derived from the service's own `dataRoot` (the `.hh` directory the panel passes) rather
|
|
15308
|
+
* than the module-level path helpers, so a restore writes under the state root of the panel
|
|
15309
|
+
* running it — not under whatever `HHOSTED_HOME` resolves to at import time.
|
|
15310
|
+
*/
|
|
15311
|
+
function workspacePathsFor(dataRoot, id) {
|
|
15312
|
+
const dir = path.join(dataRoot, id);
|
|
15313
|
+
return {
|
|
15314
|
+
settingsPath: path.join(dir, "settings.json"),
|
|
15315
|
+
serversPath: path.join(dir, "servers.config.json"),
|
|
15316
|
+
secretsPath: path.join(dir, ".secrets.json")
|
|
15317
|
+
};
|
|
15318
|
+
}
|
|
15319
|
+
/**
|
|
14464
15320
|
* The manifest is written by us, but an uploaded archive's copy is attacker
|
|
14465
15321
|
* controlled: never join an unvalidated slug into a path.
|
|
14466
15322
|
*/
|
|
@@ -14536,11 +15392,12 @@ function readableWorkspaceSettings(text) {
|
|
|
14536
15392
|
return false;
|
|
14537
15393
|
}
|
|
14538
15394
|
}
|
|
14539
|
-
var MANIFEST, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
15395
|
+
var MANIFEST, REGISTRY, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
14540
15396
|
var init_backups = __esmMin((() => {
|
|
14541
15397
|
init_migrations();
|
|
14542
15398
|
init_parse();
|
|
14543
15399
|
init_secret_parts();
|
|
15400
|
+
init_workspaces();
|
|
14544
15401
|
init_atomic();
|
|
14545
15402
|
init_env_file();
|
|
14546
15403
|
init_logger();
|
|
@@ -14549,10 +15406,12 @@ var init_backups = __esmMin((() => {
|
|
|
14549
15406
|
init_version();
|
|
14550
15407
|
init_archive();
|
|
14551
15408
|
init_supervisor();
|
|
15409
|
+
init_contracts();
|
|
14552
15410
|
init_error_message();
|
|
14553
15411
|
init_generated();
|
|
14554
15412
|
init_shape();
|
|
14555
15413
|
MANIFEST = "manifest.json";
|
|
15414
|
+
REGISTRY = "workspaces.json";
|
|
14556
15415
|
ALLOWED_ROOTS = /* @__PURE__ */ new Set([
|
|
14557
15416
|
"global",
|
|
14558
15417
|
"workspaces",
|
|
@@ -14599,6 +15458,8 @@ var init_backups = __esmMin((() => {
|
|
|
14599
15458
|
* long as the failure lasts. This is the in-memory backstop for that case.
|
|
14600
15459
|
*/
|
|
14601
15460
|
lastAttemptAt = null;
|
|
15461
|
+
/** Why the most recent scheduled pass failed, cleared by the next that works. */
|
|
15462
|
+
scheduleError = null;
|
|
14602
15463
|
constructor(options) {
|
|
14603
15464
|
this.options = options;
|
|
14604
15465
|
}
|
|
@@ -14622,6 +15483,7 @@ var init_backups = __esmMin((() => {
|
|
|
14622
15483
|
keep: config.keep,
|
|
14623
15484
|
schedule: { ...config.schedule },
|
|
14624
15485
|
lastAutomaticAt: this.lastAutomatic(),
|
|
15486
|
+
...this.scheduleError === null ? {} : { scheduleError: { ...this.scheduleError } },
|
|
14625
15487
|
includePaths: [...sources.includePaths],
|
|
14626
15488
|
entries: this.entries(sources),
|
|
14627
15489
|
files: this.list()
|
|
@@ -14714,6 +15576,7 @@ var init_backups = __esmMin((() => {
|
|
|
14714
15576
|
if (capturesGlobal("global:settings")) copy("global/settings.json", sources.globalSettingsPath);
|
|
14715
15577
|
if (capturesSecrets("global:secrets")) copySecrets("global/secrets.json", sources.globalSecretsPath, "global:secrets", "global");
|
|
14716
15578
|
if (capturesGlobal("global:tls")) copy("global/tls", sources.tlsDir);
|
|
15579
|
+
this.copyInto(staging, `global/${REGISTRY}`, sources.registryPath);
|
|
14717
15580
|
const data = [];
|
|
14718
15581
|
for (const workspace of sources.workspaces) {
|
|
14719
15582
|
const root = `workspaces/${workspace.id}`;
|
|
@@ -14812,7 +15675,9 @@ var init_backups = __esmMin((() => {
|
|
|
14812
15675
|
skipped: [],
|
|
14813
15676
|
skippedItems: [],
|
|
14814
15677
|
restartRequired: false,
|
|
14815
|
-
reloaded: false
|
|
15678
|
+
reloaded: false,
|
|
15679
|
+
createdWorkspaces: [],
|
|
15680
|
+
replacedUnderRunning: []
|
|
14816
15681
|
};
|
|
14817
15682
|
if (!isZipArchive(archivePath)) return {
|
|
14818
15683
|
...plan,
|
|
@@ -14971,54 +15836,47 @@ var init_backups = __esmMin((() => {
|
|
|
14971
15836
|
}
|
|
14972
15837
|
}, ["tls"]);
|
|
14973
15838
|
}
|
|
15839
|
+
/**
|
|
15840
|
+
* The workspaces the archive names, from its registry file.
|
|
15841
|
+
*
|
|
15842
|
+
* Optional: an archive written before the registry was captured carries none, and
|
|
15843
|
+
* then every archived workspace is still restorable under its own id — the label is
|
|
15844
|
+
* the only thing the registry adds.
|
|
15845
|
+
*/
|
|
15846
|
+
const archivedWorkspaces = /* @__PURE__ */ new Map();
|
|
15847
|
+
for (const entry of readArchivedRegistry(path.join(staging, "global", REGISTRY))) archivedWorkspaces.set(entry.id, entry);
|
|
14974
15848
|
/** Every archived servers file this release can read, selected or not. */
|
|
14975
15849
|
const archivedServers = /* @__PURE__ */ new Map();
|
|
15850
|
+
/**
|
|
15851
|
+
* Workspaces the archive names that this host does not have, with the paths a
|
|
15852
|
+
* restore will create them under. The directories are made only when one of
|
|
15853
|
+
* their leaves is actually applied, so a dry run writes nothing.
|
|
15854
|
+
*/
|
|
15855
|
+
const createdWorkspaces = /* @__PURE__ */ new Map();
|
|
14976
15856
|
const archiveWorkspaces = path.join(staging, "workspaces");
|
|
14977
15857
|
if (fs.existsSync(archiveWorkspaces)) for (const entry of fs.readdirSync(archiveWorkspaces, { withFileTypes: true })) {
|
|
14978
15858
|
if (!entry.isDirectory()) continue;
|
|
14979
15859
|
const id = entry.name;
|
|
14980
15860
|
const dir = path.join(archiveWorkspaces, id);
|
|
14981
|
-
const workspace = sources.workspaces.find((candidate) => candidate.id === id);
|
|
14982
15861
|
const settings = readText(path.join(dir, "settings.json"));
|
|
14983
15862
|
const servers = readText(path.join(dir, "servers.config.json"));
|
|
14984
15863
|
const secrets = readText(path.join(dir, "secrets.json"));
|
|
15864
|
+
const archivedLabel = archivedWorkspaces.get(id)?.label ?? id;
|
|
15865
|
+
const workspace = sources.workspaces.find((candidate) => candidate.id === id) ?? createdWorkspaces.get(id) ?? (workspaceIdSchema(id) instanceof type.errors ? void 0 : {
|
|
15866
|
+
id,
|
|
15867
|
+
label: archivedLabel,
|
|
15868
|
+
...workspacePathsFor(this.options.dataRoot, id),
|
|
15869
|
+
servers: []
|
|
15870
|
+
});
|
|
14985
15871
|
if (workspace === void 0) {
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
],
|
|
14992
|
-
[
|
|
14993
|
-
"servers",
|
|
14994
|
-
"Servers",
|
|
14995
|
-
servers
|
|
14996
|
-
],
|
|
14997
|
-
[
|
|
14998
|
-
"secrets",
|
|
14999
|
-
"Secrets",
|
|
15000
|
-
secrets
|
|
15001
|
-
]
|
|
15002
|
-
];
|
|
15003
|
-
for (const [suffix, label, text] of leaves) {
|
|
15004
|
-
if (text === null) continue;
|
|
15005
|
-
addItem({
|
|
15006
|
-
id: `workspace:${id}:${suffix}`,
|
|
15007
|
-
label: `${id}: ${label}`,
|
|
15008
|
-
labelKey: "settings.backup.restoreItemLabel",
|
|
15009
|
-
labelParams: {
|
|
15010
|
-
workspace: id,
|
|
15011
|
-
item: suffix
|
|
15012
|
-
},
|
|
15013
|
-
kind: suffix,
|
|
15014
|
-
workspaceId: id,
|
|
15015
|
-
restorable: false,
|
|
15016
|
-
note: "unknown workspace",
|
|
15017
|
-
noteKey: "settings.backup.noteUnknownWorkspace"
|
|
15018
|
-
}, null);
|
|
15019
|
-
}
|
|
15872
|
+
plan.skipped.push(`${id} (not a usable workspace id)`);
|
|
15873
|
+
plan.skippedItems.push({
|
|
15874
|
+
label: id,
|
|
15875
|
+
reasonKey: "settings.restore.reasonInvalidWorkspace"
|
|
15876
|
+
});
|
|
15020
15877
|
continue;
|
|
15021
15878
|
}
|
|
15879
|
+
if (!sources.workspaces.some((candidate) => candidate.id === id)) createdWorkspaces.set(id, workspace);
|
|
15022
15880
|
if (settings !== null) {
|
|
15023
15881
|
if (readableWorkspaceSettings(settings)) addItem({
|
|
15024
15882
|
id: `workspace:${id}:settings`,
|
|
@@ -15033,6 +15891,7 @@ var init_backups = __esmMin((() => {
|
|
|
15033
15891
|
restorable: true,
|
|
15034
15892
|
note: null
|
|
15035
15893
|
}, () => {
|
|
15894
|
+
fs.mkdirSync(path.dirname(workspace.settingsPath), { recursive: true });
|
|
15036
15895
|
writeFileAtomic(workspace.settingsPath, settings);
|
|
15037
15896
|
});
|
|
15038
15897
|
else {
|
|
@@ -15065,6 +15924,7 @@ var init_backups = __esmMin((() => {
|
|
|
15065
15924
|
restorable: true,
|
|
15066
15925
|
note: null
|
|
15067
15926
|
}, () => {
|
|
15927
|
+
fs.mkdirSync(path.dirname(workspace.serversPath), { recursive: true });
|
|
15068
15928
|
writeFileAtomic(workspace.serversPath, servers);
|
|
15069
15929
|
});
|
|
15070
15930
|
} else {
|
|
@@ -15094,6 +15954,7 @@ var init_backups = __esmMin((() => {
|
|
|
15094
15954
|
restorable: true,
|
|
15095
15955
|
note: null
|
|
15096
15956
|
}, () => {
|
|
15957
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15097
15958
|
writeFileAtomic(workspace.secretsPath, secrets, { mode: 384 });
|
|
15098
15959
|
});
|
|
15099
15960
|
for (const part of secretParts("workspace", presentSecretKeys(parseSecrets(secrets)))) addItem({
|
|
@@ -15109,6 +15970,7 @@ var init_backups = __esmMin((() => {
|
|
|
15109
15970
|
restorable: true,
|
|
15110
15971
|
note: null
|
|
15111
15972
|
}, () => {
|
|
15973
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15112
15974
|
mergeIntoFile(workspace.secretsPath, secrets, part.fields);
|
|
15113
15975
|
});
|
|
15114
15976
|
}
|
|
@@ -15143,16 +16005,30 @@ var init_backups = __esmMin((() => {
|
|
|
15143
16005
|
used.add(found);
|
|
15144
16006
|
return found;
|
|
15145
16007
|
};
|
|
16008
|
+
/**
|
|
16009
|
+
* Where one archived data path lands, never across a workspace boundary.
|
|
16010
|
+
*
|
|
16011
|
+
* An archive that names a workspace is only ever matched against that workspace's
|
|
16012
|
+
* declarations: the un-scoped fallbacks below exist to survive a re-labelled or
|
|
16013
|
+
* re-ordered config, and letting them cross workspaces wrote one workspace's data
|
|
16014
|
+
* over a path another one had declared. A path only one workspace declares has no
|
|
16015
|
+
* candidate at all in the other, so the entry is reported instead of guessed at.
|
|
16016
|
+
*/
|
|
15146
16017
|
const matchTarget = (origin, workspace, archivedPath) => {
|
|
15147
|
-
|
|
15148
|
-
|
|
15149
|
-
|
|
15150
|
-
|
|
15151
|
-
|
|
15152
|
-
return take(archiveTargets, usedArchive, (target) => target.origin === origin) ?? take(instanceTargets, usedInstance, (target) => target.origin === origin) ?? take(archiveTargets, usedArchive, (target) => target.path === archivedPath) ?? take(instanceTargets, usedInstance, (target) => target.path === archivedPath);
|
|
15153
|
-
}
|
|
15154
|
-
return take(archiveTargets, usedArchive, (target) => target.path === archivedPath) ?? take(instanceTargets, usedInstance, (target) => target.path === archivedPath);
|
|
16018
|
+
const inScope = (target) => workspace === void 0 || target.workspace === workspace;
|
|
16019
|
+
const archive = archiveTargets.filter(inScope);
|
|
16020
|
+
const instance = instanceTargets.filter(inScope);
|
|
16021
|
+
if (origin !== void 0) return take(archive, usedArchive, (target) => target.origin === origin) ?? take(instance, usedInstance, (target) => target.origin === origin) ?? take(archive, usedArchive, (target) => target.path === archivedPath) ?? take(instance, usedInstance, (target) => target.path === archivedPath);
|
|
16022
|
+
return take(archive, usedArchive, (target) => target.path === archivedPath) ?? take(instance, usedInstance, (target) => target.path === archivedPath);
|
|
15155
16023
|
};
|
|
16024
|
+
/**
|
|
16025
|
+
* `workspace:serverId` for every entry running at this moment.
|
|
16026
|
+
*
|
|
16027
|
+
* Built once, before anything is copied: a data path whose owner is running is about to be
|
|
16028
|
+
* replaced under a live process, and the plan has to name it. Read here rather than in the
|
|
16029
|
+
* apply closure so a dry run reports the same list the apply would.
|
|
16030
|
+
*/
|
|
16031
|
+
const runningOwners = new Set((sources.runningServers?.() ?? []).map((entry) => `${entry.workspaceId}:${entry.serverId}`));
|
|
15156
16032
|
const archivedEntries = Array.isArray(manifest.data) ? manifest.data.filter(isRecord) : [];
|
|
15157
16033
|
for (const entry of archivedEntries) {
|
|
15158
16034
|
const archivedPath = typeof entry.path === "string" ? entry.path : "";
|
|
@@ -15187,6 +16063,12 @@ var init_backups = __esmMin((() => {
|
|
|
15187
16063
|
}, null, aliases);
|
|
15188
16064
|
continue;
|
|
15189
16065
|
}
|
|
16066
|
+
const ownerId = target.origin.split(":")[0] ?? "";
|
|
16067
|
+
if ((selectedIds === null || selectedIds.has(base.id) || aliases.includes(base.id)) && runningOwners.has(`${target.workspace}:${ownerId}`)) plan.replacedUnderRunning.push({
|
|
16068
|
+
workspaceId: target.workspace,
|
|
16069
|
+
serverId: ownerId,
|
|
16070
|
+
path: target.path
|
|
16071
|
+
});
|
|
15190
16072
|
addItem({
|
|
15191
16073
|
...base,
|
|
15192
16074
|
restorable: true,
|
|
@@ -15195,11 +16077,13 @@ var init_backups = __esmMin((() => {
|
|
|
15195
16077
|
noteKey: "settings.backup.noteRestoredFrom",
|
|
15196
16078
|
noteParams: { path: archivedPath }
|
|
15197
16079
|
}
|
|
15198
|
-
}, () =>
|
|
15199
|
-
|
|
15200
|
-
|
|
15201
|
-
|
|
15202
|
-
|
|
16080
|
+
}, () => {
|
|
16081
|
+
fs.cpSync(from, target.path, {
|
|
16082
|
+
recursive: true,
|
|
16083
|
+
force: true,
|
|
16084
|
+
filter: (_source, destination) => isInsideResolved(target.path, destination)
|
|
16085
|
+
});
|
|
16086
|
+
}, aliases);
|
|
15203
16087
|
}
|
|
15204
16088
|
if (parsedGlobal !== null && actions.has("global:settings") && settingsText !== null) {
|
|
15205
16089
|
const currentText = readText(sources.globalSettingsPath);
|
|
@@ -15216,6 +16100,14 @@ var init_backups = __esmMin((() => {
|
|
|
15216
16100
|
plan.applied.push(labelOf(plan, id));
|
|
15217
16101
|
}
|
|
15218
16102
|
plan.appliedIds = [...actions.keys()];
|
|
16103
|
+
for (const workspace of createdWorkspaces.values()) {
|
|
16104
|
+
if (![...actions.keys()].some((id) => id.startsWith(`workspace:${workspace.id}:`))) continue;
|
|
16105
|
+
this.options.ensureWorkspace?.({
|
|
16106
|
+
id: workspace.id,
|
|
16107
|
+
label: workspace.label
|
|
16108
|
+
});
|
|
16109
|
+
plan.createdWorkspaces.push(workspace.id);
|
|
16110
|
+
}
|
|
15219
16111
|
if (this.options.onRestored !== void 0 && [...actions.keys()].some((id) => RELOADABLE.test(id))) {
|
|
15220
16112
|
plan.reloaded = true;
|
|
15221
16113
|
this.options.onRestored();
|
|
@@ -15489,8 +16381,20 @@ var init_backups = __esmMin((() => {
|
|
|
15489
16381
|
this.running = true;
|
|
15490
16382
|
this.lastAttemptAt = now;
|
|
15491
16383
|
this.create({ automatic: true }).then((result) => {
|
|
15492
|
-
if (
|
|
16384
|
+
if (result.ok) {
|
|
16385
|
+
this.scheduleError = null;
|
|
16386
|
+
return;
|
|
16387
|
+
}
|
|
16388
|
+
this.scheduleError = {
|
|
16389
|
+
message: result.error ?? "the scheduled backup failed",
|
|
16390
|
+
at: Date.now()
|
|
16391
|
+
};
|
|
16392
|
+
logger.warn("the scheduled backup failed", result.error);
|
|
15493
16393
|
}).catch((error) => {
|
|
16394
|
+
this.scheduleError = {
|
|
16395
|
+
message: errorMessage(error),
|
|
16396
|
+
at: Date.now()
|
|
16397
|
+
};
|
|
15494
16398
|
logger.error("the scheduled backup failed", error);
|
|
15495
16399
|
}).finally(() => {
|
|
15496
16400
|
this.running = false;
|
|
@@ -16752,6 +17656,14 @@ var init_notifications = __esmMin((() => {
|
|
|
16752
17656
|
"crash": "gave up restarting",
|
|
16753
17657
|
"unhealthy": "health check failing",
|
|
16754
17658
|
"forced-restart": "force restarted",
|
|
17659
|
+
/**
|
|
17660
|
+
* The other half of `forced-restart`: the entry came back and is serving.
|
|
17661
|
+
*
|
|
17662
|
+
* Without it a force restart was announced and then never closed, so a reader could not
|
|
17663
|
+
* tell "it restarted and is fine now" from "it restarted and is still broken" — the two
|
|
17664
|
+
* cases looked identical until the next crash.
|
|
17665
|
+
*/
|
|
17666
|
+
"restart-ok": "restarted and healthy again",
|
|
16755
17667
|
"recovered": "recovered",
|
|
16756
17668
|
"rss": "exceeded its memory limit",
|
|
16757
17669
|
"host": "host thresholds breached",
|
|
@@ -16763,6 +17675,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16763
17675
|
"crash": "🔴 server down",
|
|
16764
17676
|
"unhealthy": "🟠 server unhealthy",
|
|
16765
17677
|
"forced-restart": "🔁 server force restarted",
|
|
17678
|
+
"restart-ok": "🟢 server back up",
|
|
16766
17679
|
"recovered": "🟢 server recovered",
|
|
16767
17680
|
"rss": "🔴 server over its memory limit",
|
|
16768
17681
|
"host": "🟠 host warning",
|
|
@@ -16775,6 +17688,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16775
17688
|
"rss": (policy) => policy.onCrash,
|
|
16776
17689
|
"unhealthy": (policy) => policy.onUnhealthy,
|
|
16777
17690
|
"forced-restart": (policy) => policy.onForcedRestart,
|
|
17691
|
+
"restart-ok": (policy) => policy.onForcedRestart,
|
|
16778
17692
|
"recovered": (policy) => policy.onRecovered,
|
|
16779
17693
|
"host": (policy) => policy.onHost,
|
|
16780
17694
|
"host-recovered": (policy) => policy.onHost,
|
|
@@ -17200,7 +18114,12 @@ var init_panel = __esmMin((() => {
|
|
|
17200
18114
|
globalSettingsPath: this.options.settings.path,
|
|
17201
18115
|
globalSecretsPath: this.options.secrets.path,
|
|
17202
18116
|
tlsDir: this.options.tls.directory,
|
|
18117
|
+
registryPath: this.options.registry.path,
|
|
17203
18118
|
includePaths: this.options.settings.backups.includePaths,
|
|
18119
|
+
runningServers: () => this.workspaces().flatMap((runtime) => runtime.supervisor.views().filter((view) => view.status === "running").map((view) => ({
|
|
18120
|
+
workspaceId: runtime.id,
|
|
18121
|
+
serverId: view.id
|
|
18122
|
+
}))),
|
|
17204
18123
|
workspaces: this.workspaces().map((runtime) => ({
|
|
17205
18124
|
id: runtime.id,
|
|
17206
18125
|
label: runtime.label,
|
|
@@ -17219,6 +18138,22 @@ var init_panel = __esmMin((() => {
|
|
|
17219
18138
|
this.scheduleState();
|
|
17220
18139
|
return runtime.view();
|
|
17221
18140
|
}
|
|
18141
|
+
/**
|
|
18142
|
+
* Registers a workspace an archive brought but this host did not have, then builds
|
|
18143
|
+
* its runtime so the files a restore is about to write have an owner.
|
|
18144
|
+
*
|
|
18145
|
+
* Idempotent, and it never touches an existing workspace: a restore must fill one
|
|
18146
|
+
* that is already here, not replace its label or its runtime.
|
|
18147
|
+
*/
|
|
18148
|
+
ensureWorkspace(input) {
|
|
18149
|
+
if (this.options.registry.has(input.id)) return;
|
|
18150
|
+
const workspace = this.options.registry.create(input);
|
|
18151
|
+
const runtime = this.createRuntime(workspace);
|
|
18152
|
+
this.runtimes.set(workspace.id, runtime);
|
|
18153
|
+
logger.info(`workspace "${workspace.id}" restored from an archive`);
|
|
18154
|
+
this.startRestored(runtime, /* @__PURE__ */ new Set());
|
|
18155
|
+
this.scheduleState();
|
|
18156
|
+
}
|
|
17222
18157
|
rename(id, label) {
|
|
17223
18158
|
const workspace = this.options.registry.rename(id, label);
|
|
17224
18159
|
const runtime = this.runtimes.get(id);
|
|
@@ -17258,16 +18193,35 @@ var init_panel = __esmMin((() => {
|
|
|
17258
18193
|
this.scheduleState();
|
|
17259
18194
|
return entry;
|
|
17260
18195
|
}
|
|
17261
|
-
/**
|
|
18196
|
+
/**
|
|
18197
|
+
* Re-reads every workspace and the global settings, e.g. after a restore.
|
|
18198
|
+
*
|
|
18199
|
+
* `store.load()` resets the byte baseline the config watcher compares against, so the
|
|
18200
|
+
* poll that follows sees "no change" and never reaches its autostart pass. The entries
|
|
18201
|
+
* an archive brought therefore waited for a panel restart — which is why the start of
|
|
18202
|
+
* newly appeared autostart entries belongs here, the one place that knows what was new.
|
|
18203
|
+
*/
|
|
17262
18204
|
reloadAll() {
|
|
17263
18205
|
this.options.settings.load();
|
|
17264
18206
|
for (const runtime of this.workspaces()) {
|
|
18207
|
+
const before = new Set(runtime.store.servers.map((server) => server.id));
|
|
17265
18208
|
runtime.store.load();
|
|
17266
18209
|
runtime.history.load();
|
|
17267
18210
|
this.reportWorkspaceErrors(runtime.id);
|
|
18211
|
+
this.startRestored(runtime, before);
|
|
17268
18212
|
}
|
|
17269
18213
|
this.scheduleState();
|
|
17270
18214
|
}
|
|
18215
|
+
/** Starts the autostart entries a reload just revealed, exactly as a hand edit would. */
|
|
18216
|
+
startRestored(runtime, before) {
|
|
18217
|
+
if (!this.options.autostart) return;
|
|
18218
|
+
for (const server of runtime.store.servers) {
|
|
18219
|
+
if (before.has(server.id) || !server.enabled || !server.autostart) continue;
|
|
18220
|
+
runtime.supervisor.start(server.id, { actor: "boot" }).catch((error) => {
|
|
18221
|
+
logger.error(`could not start the restored server ${server.id}`, error);
|
|
18222
|
+
});
|
|
18223
|
+
}
|
|
18224
|
+
}
|
|
17271
18225
|
/** Starts whatever the config marks autostart, across every workspace. */
|
|
17272
18226
|
async startAll(workspaces = this.workspaces().map((runtime) => runtime.id)) {
|
|
17273
18227
|
for (const id of workspaces) {
|
|
@@ -18315,6 +19269,7 @@ async function runControlPlane(options) {
|
|
|
18315
19269
|
dataRoot: hhDir,
|
|
18316
19270
|
getConfig: () => settings.backups,
|
|
18317
19271
|
getSources: () => panel.backupSources(),
|
|
19272
|
+
ensureWorkspace: (input) => panel?.ensureWorkspace(input),
|
|
18318
19273
|
onRestored: () => panel?.reloadAll()
|
|
18319
19274
|
});
|
|
18320
19275
|
panel = new PanelService({
|
|
@@ -18540,7 +19495,7 @@ async function runUp(flags, entry) {
|
|
|
18540
19495
|
process.stdout.write(`${green("already running")} home-hosted ${existing.version} (pid ${existing.pid}) at ${existing.url}\n`);
|
|
18541
19496
|
const note = versionMismatchNote(existing.version);
|
|
18542
19497
|
if (note !== null) process.stdout.write(`${dim(note)}\n`);
|
|
18543
|
-
process.stdout.write(`${dim(
|
|
19498
|
+
process.stdout.write(`${dim(`stop it with \`${invocation()} down\``)}\n`);
|
|
18544
19499
|
return;
|
|
18545
19500
|
}
|
|
18546
19501
|
if (existing !== null && await runtimeIsGone(existing)) clearRuntime();
|
|
@@ -18776,7 +19731,7 @@ async function runServerAction(action, id, workspace) {
|
|
|
18776
19731
|
const runtime = readRuntime();
|
|
18777
19732
|
if (runtime === null || !await runtimeIsAlive(runtime)) {
|
|
18778
19733
|
if (runtime !== null && await runtimeIsGone(runtime)) clearRuntime();
|
|
18779
|
-
fail(
|
|
19734
|
+
fail(`home-hosted is not running — start it with \`${invocation()} up\``);
|
|
18780
19735
|
}
|
|
18781
19736
|
const query = workspace === void 0 || workspace.length === 0 ? "" : `?workspace=${encodeURIComponent(workspace)}`;
|
|
18782
19737
|
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}/${action}${query}`);
|
|
@@ -18808,7 +19763,7 @@ function serverCommand(action) {
|
|
|
18808
19763
|
},
|
|
18809
19764
|
run: async ({ args }) => {
|
|
18810
19765
|
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
18811
|
-
if (id.length === 0) fail(`${action} needs a server id — see
|
|
19766
|
+
if (id.length === 0) fail(`${action} needs a server id — see \`${invocation()} status\` or the workspace's servers.config.json`);
|
|
18812
19767
|
await runServerAction(action, id, typeof args.workspace === "string" ? args.workspace.trim() : void 0);
|
|
18813
19768
|
}
|
|
18814
19769
|
});
|
|
@@ -18882,8 +19837,8 @@ async function runStatus(json) {
|
|
|
18882
19837
|
running: false,
|
|
18883
19838
|
initialised
|
|
18884
19839
|
}, null, 2)}\n`);
|
|
18885
|
-
else if (initialised) process.stdout.write(
|
|
18886
|
-
else process.stdout.write(
|
|
19840
|
+
else if (initialised) process.stdout.write(`home-hosted is not running — start it with \`${invocation()} up\`\n`);
|
|
19841
|
+
else process.stdout.write(`home-hosted is not running — nothing is set up here yet; \`${invocation()} init\` creates a project, \`${invocation()} up\` starts one here\n`);
|
|
18887
19842
|
process.exitCode = 1;
|
|
18888
19843
|
return;
|
|
18889
19844
|
}
|
|
@@ -18928,7 +19883,7 @@ async function runStatus(json) {
|
|
|
18928
19883
|
const dir = path.join(workspaceDir(DEFAULT_WORKSPACE_ID), ".logs");
|
|
18929
19884
|
return fs.existsSync(dir) ? `${dir} (one file per server: <id>.log)` : dir;
|
|
18930
19885
|
})()],
|
|
18931
|
-
["ui", ui.custom ? `custom — ${uiLabel} (revert with
|
|
19886
|
+
["ui", ui.custom ? `custom — ${uiLabel} (revert with \`${invocation()} ui-revert\`)` : "stock"]
|
|
18932
19887
|
];
|
|
18933
19888
|
process.stdout.write(`${bold(`home-hosted ${runtime.version}`)}\n`);
|
|
18934
19889
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
@@ -19113,7 +20068,7 @@ async function runSetPassword(clear) {
|
|
|
19113
20068
|
store.setPassword(password);
|
|
19114
20069
|
process.stdout.write(`${green("password stored")} in ${globalSecretsPath} (mode 0600)\n`);
|
|
19115
20070
|
if (password.length < 8) process.stdout.write(`${dim(`"${password}" is short — easy to guess if the panel is reachable beyond loopback`)}\n`);
|
|
19116
|
-
process.stdout.write(`${dim("
|
|
20071
|
+
process.stdout.write(`${dim("a running panel picks it up immediately, and every existing browser session is signed out")}\n`);
|
|
19117
20072
|
}
|
|
19118
20073
|
var setPasswordArgs, setPasswordCommand;
|
|
19119
20074
|
var init_set_password = __esmMin((() => {
|
|
@@ -20016,6 +20971,149 @@ var init_ui_revert = __esmMin((() => {
|
|
|
20016
20971
|
});
|
|
20017
20972
|
}));
|
|
20018
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
|
|
20019
21117
|
//#region src/services/nanny.ts
|
|
20020
21118
|
var nanny_exports$1 = /* @__PURE__ */ __exportAll({ runNanny: () => runNanny });
|
|
20021
21119
|
/**
|
|
@@ -20200,6 +21298,7 @@ var SYNOPSIS = {
|
|
|
20200
21298
|
"restart": "home-hosted restart [<id>] [options]",
|
|
20201
21299
|
"status": "home-hosted status [--json]",
|
|
20202
21300
|
"logs": "home-hosted logs [--lines <n>] [--follow] [--json]",
|
|
21301
|
+
"backup": "home-hosted backup [list|create|restore] [options]",
|
|
20203
21302
|
"start": "home-hosted start <id> [--workspace <id>]",
|
|
20204
21303
|
"stop": "home-hosted stop <id> [--workspace <id>]",
|
|
20205
21304
|
"set-password": "home-hosted set-password",
|
|
@@ -20216,6 +21315,7 @@ var SUMMARIES = {
|
|
|
20216
21315
|
"restart": "down then up — or one server, given an id",
|
|
20217
21316
|
"status": "is it running, where, and how to reach it",
|
|
20218
21317
|
"logs": "show the panel's own console output",
|
|
21318
|
+
"backup": "list, create or restore a backup archive",
|
|
20219
21319
|
"start": "start one server, leaving the panel up",
|
|
20220
21320
|
"stop": "stop one server, leaving the panel up",
|
|
20221
21321
|
"set-password": "set the panel password without the API",
|
|
@@ -20227,7 +21327,7 @@ var SUMMARIES = {
|
|
|
20227
21327
|
"ui-revert": "go back to the stock control panel UI"
|
|
20228
21328
|
};
|
|
20229
21329
|
/** Every section lays its left column out at this width, so the two views align. */
|
|
20230
|
-
var OPTION_WIDTH =
|
|
21330
|
+
var OPTION_WIDTH = 21;
|
|
20231
21331
|
var UP_SECTION = {
|
|
20232
21332
|
heading: "Options for up/restart",
|
|
20233
21333
|
lines: [
|
|
@@ -20252,9 +21352,20 @@ var LOGS_SECTION = {
|
|
|
20252
21352
|
["--json", "print machine-readable JSON (one object per line with --follow)"]
|
|
20253
21353
|
]
|
|
20254
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
|
+
};
|
|
20255
21366
|
var SERVER_SECTION = {
|
|
20256
21367
|
heading: "Arguments for start/stop",
|
|
20257
|
-
lines: [["<id>", "the server id from servers.config.json"]]
|
|
21368
|
+
lines: [["<id>", "the server id from servers.config.json"], ["-w, --workspace <id>", "the workspace to act in (default: the default workspace)"]]
|
|
20258
21369
|
};
|
|
20259
21370
|
var RESTART_SECTION = {
|
|
20260
21371
|
heading: "Options for restart",
|
|
@@ -20274,7 +21385,11 @@ var SET_TOKEN_SECTION = {
|
|
|
20274
21385
|
};
|
|
20275
21386
|
var MIGRATE_SECTION = {
|
|
20276
21387
|
heading: "Options for migrate",
|
|
20277
|
-
lines: [
|
|
21388
|
+
lines: [
|
|
21389
|
+
["-c, --config <file>", "one config file to migrate (default: every file this state root owns)"],
|
|
21390
|
+
["--dry-run", "print what would change, write nothing"],
|
|
21391
|
+
["-y, --yes", "apply without asking (or set HHOSTED_MIGRATE=allow)"]
|
|
21392
|
+
]
|
|
20278
21393
|
};
|
|
20279
21394
|
var INIT_SECTION = {
|
|
20280
21395
|
heading: "Options for init",
|
|
@@ -20391,6 +21506,7 @@ var UP_COMMANDS = /* @__PURE__ */ new Set(["up", "restart"]);
|
|
|
20391
21506
|
var SECTIONS = {
|
|
20392
21507
|
"status": STATUS_SECTION,
|
|
20393
21508
|
"logs": LOGS_SECTION,
|
|
21509
|
+
"backup": BACKUP_SECTION,
|
|
20394
21510
|
"restart": RESTART_SECTION,
|
|
20395
21511
|
"start": SERVER_SECTION,
|
|
20396
21512
|
"stop": SERVER_SECTION,
|
|
@@ -20442,7 +21558,8 @@ var COMMANDS = {
|
|
|
20442
21558
|
"init": () => Promise.resolve().then(() => (init_init(), init_exports)).then((module) => module.initCommand),
|
|
20443
21559
|
"ui-switch": () => Promise.resolve().then(() => (init_ui_switch(), ui_switch_exports)).then((module) => module.uiSwitchCommand),
|
|
20444
21560
|
"ui-update": () => Promise.resolve().then(() => (init_ui_update(), ui_update_exports)).then((module) => module.uiUpdateCommand),
|
|
20445
|
-
"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)
|
|
20446
21563
|
};
|
|
20447
21564
|
var rootCommand = defineCommand({
|
|
20448
21565
|
meta: {
|