home-hosted 0.9.2 → 0.9.4
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 +107 -50
- package/dist/cli.js +1027 -152
- package/dist/cli.js.map +1 -1
- package/docs/DDNS.md +6 -8
- package/docs/NOTIFICATIONS.md +6 -0
- package/docs/REVERSE_PROXY.md +23 -12
- package/docs/SERVERS.md +50 -2
- package/docs/UI_CREATION.md +7 -7
- package/package.json +1 -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-GoyomBBn.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-DL4xkOYj.js +0 -1
- package/uis/stock/dist/assets/es-CKj-v3FY.js +0 -1
- package/uis/stock/dist/assets/fr-72WremqT.js +0 -1
- package/uis/stock/dist/assets/index-GxTN2fYn.css +0 -2
- package/uis/stock/dist/assets/ja-BU4XyMbC.js +0 -1
- package/uis/stock/dist/assets/ko-Db8xtJ0N.js +0 -1
- package/uis/stock/dist/assets/ru-Bs8KXP2O.js +0 -1
- package/uis/stock/dist/assets/vi-DdQD4h7B.js +0 -1
- package/uis/stock/dist/assets/zh-CN-DIrw2Ubv.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
|
}
|
|
@@ -3879,10 +4064,12 @@ var init_control = __esmMin((() => {
|
|
|
3879
4064
|
init_deferred();
|
|
3880
4065
|
init_factory();
|
|
3881
4066
|
init_logger();
|
|
4067
|
+
init_openapi$1();
|
|
3882
4068
|
init_secret_compare();
|
|
3883
4069
|
init_validator();
|
|
3884
4070
|
init_workspace();
|
|
3885
4071
|
init_loopback();
|
|
4072
|
+
init_contracts();
|
|
3886
4073
|
}));
|
|
3887
4074
|
//#endregion
|
|
3888
4075
|
//#region src/config/migrations.ts
|
|
@@ -4229,6 +4416,12 @@ function validateCrossField(servers) {
|
|
|
4229
4416
|
settled.add(id);
|
|
4230
4417
|
};
|
|
4231
4418
|
for (const server of servers) walk(server.id);
|
|
4419
|
+
const byPort = /* @__PURE__ */ new Map();
|
|
4420
|
+
for (const server of servers) {
|
|
4421
|
+
if (server.port === null || !server.enabled) continue;
|
|
4422
|
+
byPort.set(server.port, [...byPort.get(server.port) ?? [], server.id]);
|
|
4423
|
+
}
|
|
4424
|
+
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
4425
|
return [...new Set(errors)];
|
|
4233
4426
|
}
|
|
4234
4427
|
/** Adds the stamp every write carries, so the next release can tell what wrote the file. */
|
|
@@ -6519,6 +6712,30 @@ var init_store = __esmMin((() => {
|
|
|
6519
6712
|
this.commitServers(draft);
|
|
6520
6713
|
return validated;
|
|
6521
6714
|
}
|
|
6715
|
+
/**
|
|
6716
|
+
* Creates the entry, or replaces a same-id one outright — "make it so".
|
|
6717
|
+
*
|
|
6718
|
+
* `addServer` refuses a duplicate and `updateServer` only patches an existing entry, so a config
|
|
6719
|
+
* management pass had to GET, diff, then POST or PATCH, and a re-run of an unchanged declaration
|
|
6720
|
+
* got `400 INVALID_SERVER` for its trouble. A replace is what a declarative caller means: the
|
|
6721
|
+
* body is the whole entry, not a patch.
|
|
6722
|
+
*
|
|
6723
|
+
* Returns whether it created or replaced, so the route can answer 201 or 200 honestly.
|
|
6724
|
+
*/
|
|
6725
|
+
putServer(input) {
|
|
6726
|
+
const draft = structuredClone(this.rawServers);
|
|
6727
|
+
const list = draft.servers ?? (draft.servers = []);
|
|
6728
|
+
const index = list.findIndex((entry) => entry.id === input.id);
|
|
6729
|
+
const created = index < 0;
|
|
6730
|
+
if (created) list.push(structuredClone(input));
|
|
6731
|
+
else list[index] = structuredClone(input);
|
|
6732
|
+
const validated = this.validateServer(list[created ? list.length - 1 : index], `servers[${created ? list.length - 1 : index}]`);
|
|
6733
|
+
this.commitServers(draft);
|
|
6734
|
+
return {
|
|
6735
|
+
server: validated,
|
|
6736
|
+
created
|
|
6737
|
+
};
|
|
6738
|
+
}
|
|
6522
6739
|
removeServer(id) {
|
|
6523
6740
|
const draft = structuredClone(this.rawServers);
|
|
6524
6741
|
const list = draft.servers ?? [];
|
|
@@ -6877,9 +7094,9 @@ var init_events = __esmMin((() => {
|
|
|
6877
7094
|
//#region src/api/health.ts
|
|
6878
7095
|
/**
|
|
6879
7096
|
* 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
|
-
*
|
|
7097
|
+
* session: it reports whether the panel itself is serving, and 503 when any server
|
|
7098
|
+
* has crashed, or a running one is failing its own health check. Server details are
|
|
7099
|
+
* only included for an authenticated caller.
|
|
6883
7100
|
*/
|
|
6884
7101
|
function createHealthRoute(deps) {
|
|
6885
7102
|
return appFactory.createApp().get("/healthz", describeRoute({
|
|
@@ -6890,12 +7107,12 @@ function createHealthRoute(deps) {
|
|
|
6890
7107
|
description: "Serving",
|
|
6891
7108
|
content: jsonBody(healthResponseSchema)
|
|
6892
7109
|
},
|
|
6893
|
-
503: { description: "
|
|
7110
|
+
503: { description: "A server has crashed, or a running one is unhealthy" }
|
|
6894
7111
|
}
|
|
6895
7112
|
}), (c) => {
|
|
6896
7113
|
const state = deps.panel.getState();
|
|
6897
7114
|
const servers = state.workspaces.flatMap((workspace) => workspace.servers);
|
|
6898
|
-
const broken = servers.filter((server) => server.
|
|
7115
|
+
const broken = servers.filter((server) => server.status === "crashed" || server.stoppedByPanel === true || server.status === "running" && server.health === "unhealthy");
|
|
6899
7116
|
const authenticated = requestIdentity(c, deps.auth).authenticated;
|
|
6900
7117
|
return c.json({
|
|
6901
7118
|
status: broken.length > 0 ? "degraded" : "ok",
|
|
@@ -6940,7 +7157,10 @@ function createLogsRoute(deps) {
|
|
|
6940
7157
|
tags: ["logs"],
|
|
6941
7158
|
summary: "Persisted log lines, with search and a stream filter",
|
|
6942
7159
|
responses: {
|
|
6943
|
-
200: {
|
|
7160
|
+
200: {
|
|
7161
|
+
description: "Lines",
|
|
7162
|
+
content: jsonBody(logLinesResponseSchema)
|
|
7163
|
+
},
|
|
6944
7164
|
404: ERROR_RESPONSES[404]
|
|
6945
7165
|
}
|
|
6946
7166
|
}), validate("query", historyQuery), validate("param", idParam$2), (c) => {
|
|
@@ -7003,7 +7223,10 @@ function createLogsRoute(deps) {
|
|
|
7003
7223
|
tags: ["logs"],
|
|
7004
7224
|
summary: "Delete the persisted logs of one server",
|
|
7005
7225
|
responses: {
|
|
7006
|
-
200: {
|
|
7226
|
+
200: {
|
|
7227
|
+
description: "Cleared",
|
|
7228
|
+
content: jsonBody(okResponseSchema)
|
|
7229
|
+
},
|
|
7007
7230
|
404: ERROR_RESPONSES[404]
|
|
7008
7231
|
}
|
|
7009
7232
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$2), (c) => {
|
|
@@ -7102,12 +7325,12 @@ function getBot(token) {
|
|
|
7102
7325
|
function forgetBots() {
|
|
7103
7326
|
bots.clear();
|
|
7104
7327
|
}
|
|
7105
|
-
function escapeHtml(value) {
|
|
7328
|
+
function escapeHtml$1(value) {
|
|
7106
7329
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
7107
7330
|
}
|
|
7108
7331
|
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}` : ""}`;
|
|
7332
|
+
const body = lines.filter((line) => line.length > 0).map((line) => `• ${escapeHtml$1(line)}`).join("\n");
|
|
7333
|
+
return `<b>${escapeHtml$1(title)}</b>${body.length > 0 ? `\n${body}` : ""}`;
|
|
7111
7334
|
}
|
|
7112
7335
|
/** Turns a grammY error into something worth showing in the settings page. */
|
|
7113
7336
|
function describeTelegramError(error) {
|
|
@@ -7202,7 +7425,10 @@ function createNotificationsRoute(deps) {
|
|
|
7202
7425
|
tags: ["notifications"],
|
|
7203
7426
|
summary: "Store a Telegram destination's bot token (verified first)",
|
|
7204
7427
|
responses: {
|
|
7205
|
-
200: {
|
|
7428
|
+
200: {
|
|
7429
|
+
description: "Stored",
|
|
7430
|
+
content: jsonBody(okResponseSchema)
|
|
7431
|
+
},
|
|
7206
7432
|
400: ERROR_RESPONSES[400]
|
|
7207
7433
|
}
|
|
7208
7434
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), validate("json", telegramTokenSchema), async (c) => {
|
|
@@ -7223,7 +7449,10 @@ function createNotificationsRoute(deps) {
|
|
|
7223
7449
|
}).delete("/notifications/destinations/:id/token", describeRoute({
|
|
7224
7450
|
tags: ["notifications"],
|
|
7225
7451
|
summary: "Forget a Telegram destination's bot token",
|
|
7226
|
-
responses: { 200: {
|
|
7452
|
+
responses: { 200: {
|
|
7453
|
+
description: "Removed",
|
|
7454
|
+
content: jsonBody(okResponseSchema)
|
|
7455
|
+
} }
|
|
7227
7456
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), (c) => {
|
|
7228
7457
|
runtimeFor(c.req.valid("query").workspace).secrets.setTelegramToken(c.req.valid("param").id, null);
|
|
7229
7458
|
forgetBots();
|
|
@@ -7232,7 +7461,10 @@ function createNotificationsRoute(deps) {
|
|
|
7232
7461
|
tags: ["notifications"],
|
|
7233
7462
|
summary: "Send a test message to one destination",
|
|
7234
7463
|
responses: {
|
|
7235
|
-
200: {
|
|
7464
|
+
200: {
|
|
7465
|
+
description: "Sent or refused",
|
|
7466
|
+
content: jsonBody(deliveryResultSchema)
|
|
7467
|
+
},
|
|
7236
7468
|
400: ERROR_RESPONSES[400]
|
|
7237
7469
|
}
|
|
7238
7470
|
}), validate("query", workspaceQuerySchema), validate("param", destinationIdParamSchema), validate("json", notificationActionSchema), async (c) => {
|
|
@@ -7246,7 +7478,10 @@ function createNotificationsRoute(deps) {
|
|
|
7246
7478
|
tags: ["notifications"],
|
|
7247
7479
|
summary: "Send a test to one webhook destination",
|
|
7248
7480
|
responses: {
|
|
7249
|
-
200: {
|
|
7481
|
+
200: {
|
|
7482
|
+
description: "Sent or refused",
|
|
7483
|
+
content: jsonBody(deliveryResultSchema)
|
|
7484
|
+
},
|
|
7250
7485
|
400: ERROR_RESPONSES[400]
|
|
7251
7486
|
}
|
|
7252
7487
|
}), validate("query", workspaceQuerySchema), validate("json", destinationTestSchema), async (c) => {
|
|
@@ -8049,6 +8284,44 @@ function parseNetstatListeners(output, port) {
|
|
|
8049
8284
|
}
|
|
8050
8285
|
return [...pids];
|
|
8051
8286
|
}
|
|
8287
|
+
async function findDockerPortHolder(port) {
|
|
8288
|
+
try {
|
|
8289
|
+
const { stdout } = await execFileAsync$2("docker", [
|
|
8290
|
+
"ps",
|
|
8291
|
+
"--filter",
|
|
8292
|
+
`publish=${port}`,
|
|
8293
|
+
"--format",
|
|
8294
|
+
"{{.Names}} {{.Label \"com.docker.compose.project.working_dir\"}}"
|
|
8295
|
+
], { timeout: 3e3 });
|
|
8296
|
+
const line = stdout.split("\n").find((entry) => entry.trim().length > 0);
|
|
8297
|
+
if (line === void 0) return null;
|
|
8298
|
+
const [container = "", composeDir = ""] = line.split(" ");
|
|
8299
|
+
if (container.trim().length === 0) return null;
|
|
8300
|
+
return {
|
|
8301
|
+
container: container.trim(),
|
|
8302
|
+
composeDir: composeDir.trim().length > 0 ? composeDir.trim() : null,
|
|
8303
|
+
port
|
|
8304
|
+
};
|
|
8305
|
+
} catch {
|
|
8306
|
+
return null;
|
|
8307
|
+
}
|
|
8308
|
+
}
|
|
8309
|
+
/**
|
|
8310
|
+
* Stops the container publishing a host port, which is how docker's port is freed.
|
|
8311
|
+
*
|
|
8312
|
+
* The socket belongs to a root-owned `docker-proxy`, so there is no pid this process may signal —
|
|
8313
|
+
* but the container is the panel's to stop through docker itself, which needs no privileges
|
|
8314
|
+
* beyond the socket the user already has. `docker stop` releases the published port and leaves the
|
|
8315
|
+
* stack's other services alone.
|
|
8316
|
+
*/
|
|
8317
|
+
async function releaseDockerPort(holder, timeoutMs = 2e4) {
|
|
8318
|
+
try {
|
|
8319
|
+
await execFileAsync$2("docker", ["stop", holder.container], { timeout: timeoutMs });
|
|
8320
|
+
return true;
|
|
8321
|
+
} catch {
|
|
8322
|
+
return false;
|
|
8323
|
+
}
|
|
8324
|
+
}
|
|
8052
8325
|
async function listPortHolders(port) {
|
|
8053
8326
|
if (process.platform === "win32") try {
|
|
8054
8327
|
const { stdout } = await execFileAsync$2("netstat", [
|
|
@@ -8101,6 +8374,7 @@ var nanny_exports$2 = /* @__PURE__ */ __exportAll({
|
|
|
8101
8374
|
clearNannySpec: () => clearNannySpec,
|
|
8102
8375
|
clearNannyState: () => clearNannyState,
|
|
8103
8376
|
describeNannyExit: () => describeNannyExit,
|
|
8377
|
+
describeSpawnError: () => describeSpawnError,
|
|
8104
8378
|
nannyEntryPoint: () => nannyEntryPoint,
|
|
8105
8379
|
nannyIsAlive: () => nannyIsAlive,
|
|
8106
8380
|
nannyLogFile: () => nannyLogFile,
|
|
@@ -8211,6 +8485,22 @@ function exitCodeHint(code) {
|
|
|
8211
8485
|
if (signal === null) return null;
|
|
8212
8486
|
return code === 137 ? `${signal} — which the kernel sends when memory runs out` : `${signal}, if the shell reported the kill`;
|
|
8213
8487
|
}
|
|
8488
|
+
/**
|
|
8489
|
+
* A spawn failure in words a person can act on.
|
|
8490
|
+
*
|
|
8491
|
+
* Node reports a missing program as `spawn <cmd> ENOENT` — the same errno as a missing *file*, and
|
|
8492
|
+
* the same wording whichever of the two it is. A user who pasted `java -jar server.jar` into
|
|
8493
|
+
* `command` saw exactly that and had nothing to go on: the message names the whole line, so it
|
|
8494
|
+
* reads as "the program is missing" even when the program is fine and only the argument is wrong.
|
|
8495
|
+
*
|
|
8496
|
+
* `command` is the configured program, so the two cases can be told apart: if a bare name has no
|
|
8497
|
+
* path separator, the shell would have searched `PATH` and this one did not.
|
|
8498
|
+
*/
|
|
8499
|
+
function describeSpawnError(error, command) {
|
|
8500
|
+
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?`;
|
|
8501
|
+
if (error.code === "EACCES") return `\`${command}\` exists but is not executable — check its permissions (chmod +x)`;
|
|
8502
|
+
return `${error.message} (while running \`${command}\`)`;
|
|
8503
|
+
}
|
|
8214
8504
|
/** `SIGKILL` for 9, or null when the number names nothing. */
|
|
8215
8505
|
function signalName(number) {
|
|
8216
8506
|
for (const [name, value] of Object.entries(os.constants.signals)) if (value === number) return name;
|
|
@@ -8362,6 +8652,16 @@ function acmeIssuers(acme, challenge = {}) {
|
|
|
8362
8652
|
}, { module: "internal" }];
|
|
8363
8653
|
}
|
|
8364
8654
|
/**
|
|
8655
|
+
* HTML-escape a value interpolated into a page.
|
|
8656
|
+
*
|
|
8657
|
+
* The notice page interpolates a routed hostname — configuration, but a config file may be
|
|
8658
|
+
* hand-edited, so it is not trusted markup. Escaped here rather than left to the engine's
|
|
8659
|
+
* authority parser, so correct encoding does not depend on what sits in front of it.
|
|
8660
|
+
*/
|
|
8661
|
+
function escapeHtml(value) {
|
|
8662
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
8663
|
+
}
|
|
8664
|
+
/**
|
|
8365
8665
|
* The one page shell both visitor-facing pages use. They are the same document with
|
|
8366
8666
|
* different words, and the stylesheet has to stay identical — a page the engine serves
|
|
8367
8667
|
* on a port a person reaches by hand is a page that has to look like this panel.
|
|
@@ -8391,8 +8691,8 @@ ${body}
|
|
|
8391
8691
|
* that cannot finish.
|
|
8392
8692
|
*/
|
|
8393
8693
|
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
|
-
|
|
8694
|
+
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
|
|
8695
|
+
reached, so there is nothing here to serve.</p>
|
|
8396
8696
|
<p>Add a route for it under <strong>Others → Reverse Proxy</strong>, or check that you
|
|
8397
8697
|
reached the hostname you meant to.</p>
|
|
8398
8698
|
<footer>home-hosted reverse proxy</footer>`);
|
|
@@ -8402,18 +8702,23 @@ function notConfiguredRoute() {
|
|
|
8402
8702
|
return { handle: [{
|
|
8403
8703
|
handler: "static_response",
|
|
8404
8704
|
status_code: 404,
|
|
8405
|
-
headers: {
|
|
8705
|
+
headers: {
|
|
8706
|
+
"content-type": ["text/html; charset=utf-8"],
|
|
8707
|
+
"cache-control": ["no-store"],
|
|
8708
|
+
"vary": ["Host"]
|
|
8709
|
+
},
|
|
8406
8710
|
body: notConfiguredPage()
|
|
8407
8711
|
}] };
|
|
8408
8712
|
}
|
|
8409
8713
|
/** The page a visitor gets when a name has no certificate yet and HTTPS cannot work. */
|
|
8410
8714
|
function noticePage(host, httpPort, httpsPort) {
|
|
8411
|
-
|
|
8715
|
+
const safeHost = escapeHtml(host);
|
|
8716
|
+
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
8717
|
for it yet, so HTTPS cannot complete a handshake. The engine keeps trying in the
|
|
8413
8718
|
background and will serve the name as soon as it succeeds.</p>
|
|
8414
8719
|
<p>The usual cause is that the CA cannot reach this machine: with the proxy on
|
|
8415
8720
|
<code>${httpPort}</code>/<code>${httpsPort}</code>, forward <code>80 → ${httpPort}</code>
|
|
8416
|
-
and <code>443 → ${httpsPort}</code> on your router. Otherwise <code>http://${
|
|
8721
|
+
and <code>443 → ${httpsPort}</code> on your router. Otherwise <code>http://${safeHost}</code>
|
|
8417
8722
|
will keep landing here.</p>
|
|
8418
8723
|
<footer>Details, and the engine's own reason, are in the panel: Others → Reverse Proxy.</footer>`);
|
|
8419
8724
|
}
|
|
@@ -8461,6 +8766,18 @@ function proxyHandler(route) {
|
|
|
8461
8766
|
};
|
|
8462
8767
|
}
|
|
8463
8768
|
/**
|
|
8769
|
+
* The ports a rendered configuration listens on.
|
|
8770
|
+
*
|
|
8771
|
+
* The one derivation: `httpPort`/`httpsPort` are what was *asked for*, not what is bound — a
|
|
8772
|
+
* `tls: 'off'`-only table binds no HTTPS listener, and a table with no servable route binds nothing.
|
|
8773
|
+
* Both the applied record and the port preflight read this, so they cannot disagree.
|
|
8774
|
+
*/
|
|
8775
|
+
function boundPorts(rendered) {
|
|
8776
|
+
const servers = rendered.apps?.http?.servers;
|
|
8777
|
+
if (servers === void 0) return [];
|
|
8778
|
+
return Object.values(servers).flatMap((server) => server.listen ?? []).map((listen) => Number.parseInt(listen.replace(/^.*:/, ""), 10)).filter((port) => Number.isInteger(port));
|
|
8779
|
+
}
|
|
8780
|
+
/**
|
|
8464
8781
|
* The whole engine configuration, generated from the panel's route table.
|
|
8465
8782
|
*
|
|
8466
8783
|
* Two servers on purpose: one terminates TLS for the names that ask for it, the
|
|
@@ -8516,7 +8833,11 @@ function renderCaddyConfig(input) {
|
|
|
8516
8833
|
handle: [{
|
|
8517
8834
|
handler: "static_response",
|
|
8518
8835
|
status_code: 503,
|
|
8519
|
-
headers: {
|
|
8836
|
+
headers: {
|
|
8837
|
+
"content-type": ["text/html; charset=utf-8"],
|
|
8838
|
+
"cache-control": ["no-store"],
|
|
8839
|
+
"vary": ["Host"]
|
|
8840
|
+
},
|
|
8520
8841
|
body: noticePage(host, config.httpPort, config.httpsPort)
|
|
8521
8842
|
}]
|
|
8522
8843
|
})),
|
|
@@ -8902,7 +9223,7 @@ function engineMessage(body) {
|
|
|
8902
9223
|
return body.trim().length > 0 ? body.trim().slice(0, 400) : null;
|
|
8903
9224
|
}
|
|
8904
9225
|
}
|
|
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;
|
|
9226
|
+
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
9227
|
var init_proxy$1 = __esmMin((() => {
|
|
8907
9228
|
init_atomic();
|
|
8908
9229
|
init_logger();
|
|
@@ -8919,6 +9240,9 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
8919
9240
|
init_error_message();
|
|
8920
9241
|
init_proxy_form();
|
|
8921
9242
|
PROXY_ID = "proxy";
|
|
9243
|
+
SYNC_RETRY_BASE_MS = 2e3;
|
|
9244
|
+
SYNC_RETRY_MAX_MS = 3e5;
|
|
9245
|
+
SYNC_MAX_FAILURES = 8;
|
|
8922
9246
|
ADMIN_TIMEOUT_MS = 5e3;
|
|
8923
9247
|
READY_TIMEOUT_MS = 2e4;
|
|
8924
9248
|
READY_POLL_MS = 250;
|
|
@@ -8938,8 +9262,8 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
8938
9262
|
password: "string >= 1"
|
|
8939
9263
|
}).onUndeclaredKey("reject");
|
|
8940
9264
|
appliedRecordSchema = type({
|
|
8941
|
-
httpPort: "1 <= number.integer <= 65535",
|
|
8942
|
-
httpsPort: "1 <= number.integer <= 65535",
|
|
9265
|
+
httpPort: "1 <= number.integer <= 65535 | null",
|
|
9266
|
+
httpsPort: "1 <= number.integer <= 65535 | null",
|
|
8943
9267
|
at: "number"
|
|
8944
9268
|
}).onUndeclaredKey("reject");
|
|
8945
9269
|
adminRecordSchema = type({
|
|
@@ -9558,6 +9882,10 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9558
9882
|
};
|
|
9559
9883
|
}
|
|
9560
9884
|
/** Records why the last start or apply failed, for the frame the page reads. */
|
|
9885
|
+
/** Backoff for a failing `sync()` re-apply; see the retry notes there. */
|
|
9886
|
+
nextSyncAttemptAt = 0;
|
|
9887
|
+
syncFailures = 0;
|
|
9888
|
+
lastSyncError = null;
|
|
9561
9889
|
recordError(message) {
|
|
9562
9890
|
this.lastError = message;
|
|
9563
9891
|
this.options.onStateChange();
|
|
@@ -9600,7 +9928,12 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9600
9928
|
await this.apply({ force: true });
|
|
9601
9929
|
return;
|
|
9602
9930
|
}
|
|
9603
|
-
|
|
9931
|
+
const staged = this.render(/* @__PURE__ */ new Set([route.id]));
|
|
9932
|
+
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`, {
|
|
9933
|
+
statusCode: 409,
|
|
9934
|
+
code: "PROXY_CERT_RETRY_LAST_ROUTE"
|
|
9935
|
+
});
|
|
9936
|
+
await this.loadIntoEngine(staged);
|
|
9604
9937
|
this.forgetCertificates(route.host);
|
|
9605
9938
|
await this.apply({ force: true });
|
|
9606
9939
|
}
|
|
@@ -9639,7 +9972,8 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9639
9972
|
await this.assertPortsFree(this.config.httpPort, this.config.httpsPort);
|
|
9640
9973
|
await this.postConfiguration(rendered);
|
|
9641
9974
|
this.rememberConfig(text);
|
|
9642
|
-
|
|
9975
|
+
const bound = boundPorts(rendered);
|
|
9976
|
+
this.rememberApplied(bound.includes(this.config.httpPort) ? this.config.httpPort : null, bound.includes(this.config.httpsPort) ? this.config.httpsPort : null);
|
|
9643
9977
|
const swept = this.sweepUnroutedCertificates();
|
|
9644
9978
|
if (swept > 0) logger.info(`proxy: dropped ${swept} certificate(s) for names no longer routed`);
|
|
9645
9979
|
this.lastError = null;
|
|
@@ -9716,13 +10050,13 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9716
10050
|
if (fs.existsSync(this.options.configPath)) writeFileAtomic(this.options.previousConfigPath, fs.readFileSync(this.options.configPath, "utf8"), { mode: 384 });
|
|
9717
10051
|
writeFileAtomic(this.options.configPath, text, { mode: 384 });
|
|
9718
10052
|
}
|
|
9719
|
-
/** The ports the engine last bound. */
|
|
10053
|
+
/** The ports the engine last bound — `null` for a configured port the document did not bind. */
|
|
9720
10054
|
readApplied() {
|
|
9721
10055
|
try {
|
|
9722
10056
|
const parsed = appliedRecordSchema(JSON.parse(fs.readFileSync(path.join(this.options.stateDir, "applied.json"), "utf8")));
|
|
9723
10057
|
return parsed instanceof type.errors ? null : {
|
|
9724
|
-
httpPort: parsed.httpPort,
|
|
9725
|
-
httpsPort: parsed.httpsPort
|
|
10058
|
+
httpPort: parsed.httpPort ?? null,
|
|
10059
|
+
httpsPort: parsed.httpsPort ?? null
|
|
9726
10060
|
};
|
|
9727
10061
|
} catch {
|
|
9728
10062
|
return null;
|
|
@@ -9757,12 +10091,27 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
9757
10091
|
if (this.status().state !== "running") return;
|
|
9758
10092
|
const signature = this.routeViews().map((view) => `${view.route.id}:${view.certificate?.state ?? ""}`).join("|");
|
|
9759
10093
|
if (signature === this.certificateSignature) return;
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
10094
|
+
if (this.certificateSignature === null) {
|
|
10095
|
+
this.certificateSignature = signature;
|
|
10096
|
+
return;
|
|
10097
|
+
}
|
|
10098
|
+
if (Date.now() < this.nextSyncAttemptAt) return;
|
|
10099
|
+
try {
|
|
10100
|
+
await this.apply();
|
|
10101
|
+
this.certificateSignature = signature;
|
|
10102
|
+
this.syncFailures = 0;
|
|
10103
|
+
this.nextSyncAttemptAt = 0;
|
|
10104
|
+
} catch (error) {
|
|
10105
|
+
const message = errorMessage(error);
|
|
10106
|
+
this.syncFailures += 1;
|
|
10107
|
+
this.nextSyncAttemptAt = Date.now() + Math.min(SYNC_RETRY_MAX_MS, SYNC_RETRY_BASE_MS * 2 ** (this.syncFailures - 1));
|
|
10108
|
+
if (message !== this.lastSyncError) {
|
|
10109
|
+
this.lastSyncError = message;
|
|
10110
|
+
logger.warn(`proxy: could not re-apply after a certificate change: ${message}`);
|
|
10111
|
+
}
|
|
10112
|
+
if (this.lastError !== message) this.recordError(message);
|
|
10113
|
+
if (this.syncFailures >= SYNC_MAX_FAILURES) this.certificateSignature = signature;
|
|
10114
|
+
}
|
|
9766
10115
|
}
|
|
9767
10116
|
/**
|
|
9768
10117
|
* Puts the last configuration that applied back, and keeps the rejected one as
|
|
@@ -10334,13 +10683,43 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10334
10683
|
if (this.nanny !== null) this.nanny.unref();
|
|
10335
10684
|
this.nanny = null;
|
|
10336
10685
|
}
|
|
10686
|
+
/**
|
|
10687
|
+
* "May we bind these ports" — a **start** question, asked before handing the engine a
|
|
10688
|
+
* configuration it would fail to serve.
|
|
10689
|
+
*
|
|
10690
|
+
* A busy port is not automatically a problem: on a re-apply the engine is already bound to it,
|
|
10691
|
+
* which is the normal case. Pid attribution cannot tell the difference — the engine carries
|
|
10692
|
+
* `cap_net_bind_service`, which makes it non-dumpable, so `listPortHolders` returns an empty list
|
|
10693
|
+
* for the very port it serves on, and the old code read that as "nothing there" and then threw.
|
|
10694
|
+
*
|
|
10695
|
+
* What makes a port ours is the engine being live *and this configuration binding it*, both
|
|
10696
|
+
* answerable without inspecting anything: the nanny state's heartbeat, and the rendered config.
|
|
10697
|
+
* Note the two are not `httpPort`/`httpsPort` — a `tls: 'off'`-only config binds no HTTPS
|
|
10698
|
+
* listener, so claiming that port would admit a stranger standing on it.
|
|
10699
|
+
*
|
|
10700
|
+
* An attributable pid that is neither the nanny nor the engine is always foreign, whatever the
|
|
10701
|
+
* records say.
|
|
10702
|
+
*/
|
|
10337
10703
|
async assertPortsFree(httpPort, httpsPort) {
|
|
10704
|
+
const state = readNannyState(nannyStatePath(this.options.stateDir, PROXY_ID));
|
|
10705
|
+
const live = state !== null && await nannyIsAlive(state, PROXY_ID);
|
|
10706
|
+
const applied = this.readApplied();
|
|
10707
|
+
const binds = new Set([applied?.httpPort ?? null, applied?.httpsPort ?? null].filter((port) => port !== null));
|
|
10708
|
+
const enginePids = state === null ? [] : [state.nannyPid, state.childPid].filter((pid) => pid !== null);
|
|
10338
10709
|
for (const port of [httpPort, httpsPort]) {
|
|
10339
10710
|
if (await isPortFree(port)) continue;
|
|
10340
10711
|
const holders = await listPortHolders(port);
|
|
10341
|
-
|
|
10342
|
-
if (
|
|
10343
|
-
|
|
10712
|
+
if (holders.some((pid) => enginePids.includes(pid))) continue;
|
|
10713
|
+
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`, {
|
|
10714
|
+
statusCode: 409,
|
|
10715
|
+
code: "PROXY_PORT_IN_USE",
|
|
10716
|
+
detail: {
|
|
10717
|
+
port,
|
|
10718
|
+
holders
|
|
10719
|
+
}
|
|
10720
|
+
});
|
|
10721
|
+
if (live && binds.has(port)) continue;
|
|
10722
|
+
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
10723
|
statusCode: 409,
|
|
10345
10724
|
code: "PROXY_PORT_IN_USE",
|
|
10346
10725
|
detail: {
|
|
@@ -10350,6 +10729,23 @@ var init_proxy$1 = __esmMin((() => {
|
|
|
10350
10729
|
});
|
|
10351
10730
|
}
|
|
10352
10731
|
}
|
|
10732
|
+
/**
|
|
10733
|
+
* Who holds a busy port, in the most specific terms available.
|
|
10734
|
+
*
|
|
10735
|
+
* An empty holder list is not "nothing is listening": for a capped engine it is the normal
|
|
10736
|
+
* reading, and for a docker-published port it is a root-owned proxy this user may not inspect.
|
|
10737
|
+
* Say which engine it is when it is our own, and say plainly that the socket is uninspectable
|
|
10738
|
+
* rather than implying the port is idle.
|
|
10739
|
+
*/
|
|
10740
|
+
describeHolders(port, holders) {
|
|
10741
|
+
if (holders.length > 0) return ` (pid ${holders.join(", ")})`;
|
|
10742
|
+
if (readNannyState(nannyStatePath(this.options.stateDir, PROXY_ID)) !== null) {
|
|
10743
|
+
const applied = this.readApplied();
|
|
10744
|
+
const bound = [applied?.httpPort ?? null, applied?.httpsPort ?? null].filter((port) => port !== null);
|
|
10745
|
+
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`;
|
|
10746
|
+
}
|
|
10747
|
+
return " — the socket cannot be inspected by this user, so the holder cannot be named";
|
|
10748
|
+
}
|
|
10353
10749
|
unixAdmin() {
|
|
10354
10750
|
return {
|
|
10355
10751
|
kind: "unix",
|
|
@@ -10715,6 +11111,61 @@ function createServersRoute(deps) {
|
|
|
10715
11111
|
});
|
|
10716
11112
|
throw error;
|
|
10717
11113
|
}
|
|
11114
|
+
}).put("/:id", describeRoute({
|
|
11115
|
+
tags: ["servers"],
|
|
11116
|
+
summary: "Create or replace one entry (idempotent)",
|
|
11117
|
+
responses: {
|
|
11118
|
+
200: {
|
|
11119
|
+
description: "Replaced",
|
|
11120
|
+
content: jsonBody(storedServerResponse)
|
|
11121
|
+
},
|
|
11122
|
+
201: {
|
|
11123
|
+
description: "Created",
|
|
11124
|
+
content: jsonBody(storedServerResponse)
|
|
11125
|
+
},
|
|
11126
|
+
400: ERROR_RESPONSES[400]
|
|
11127
|
+
}
|
|
11128
|
+
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), validate("json", serverCreateSchema), (c) => {
|
|
11129
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11130
|
+
const { id } = c.req.valid("param");
|
|
11131
|
+
const body = c.req.valid("json");
|
|
11132
|
+
if (body.id !== id) throw new DetailedError(`the body's id "${body.id}" does not match the path id "${id}"`, {
|
|
11133
|
+
statusCode: 400,
|
|
11134
|
+
code: "ID_MISMATCH"
|
|
11135
|
+
});
|
|
11136
|
+
try {
|
|
11137
|
+
const result = runtime.store.putServer(body);
|
|
11138
|
+
return c.json({ server: result.server }, result.created ? 201 : 200);
|
|
11139
|
+
} catch (error) {
|
|
11140
|
+
if (error instanceof ConfigError) throw new DetailedError(error.message, {
|
|
11141
|
+
statusCode: 400,
|
|
11142
|
+
code: "INVALID_SERVER"
|
|
11143
|
+
});
|
|
11144
|
+
throw error;
|
|
11145
|
+
}
|
|
11146
|
+
}).post("/orphans/:id/stop", describeRoute({
|
|
11147
|
+
tags: ["servers"],
|
|
11148
|
+
summary: "Stop an orphaned process this panel started",
|
|
11149
|
+
responses: {
|
|
11150
|
+
200: {
|
|
11151
|
+
description: "Stopped",
|
|
11152
|
+
content: jsonBody(okResponseSchema)
|
|
11153
|
+
},
|
|
11154
|
+
404: ERROR_RESPONSES[404],
|
|
11155
|
+
409: { description: "The process survived the stop" }
|
|
11156
|
+
}
|
|
11157
|
+
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
11158
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11159
|
+
const id = c.req.valid("param").id;
|
|
11160
|
+
const result = await runtime.supervisor.stopOrphan(id);
|
|
11161
|
+
if (!result.ok) {
|
|
11162
|
+
const survived = result.error?.includes("survived the stop") === true;
|
|
11163
|
+
throw new DetailedError(result.error ?? `could not stop the orphaned process "${id}"`, {
|
|
11164
|
+
statusCode: survived ? 409 : 404,
|
|
11165
|
+
code: survived ? "ORPHAN_SURVIVED" : "UNKNOWN_ORPHAN"
|
|
11166
|
+
});
|
|
11167
|
+
}
|
|
11168
|
+
return c.json({ ok: true });
|
|
10718
11169
|
}).post("/start-all", describeRoute({
|
|
10719
11170
|
tags: ["servers"],
|
|
10720
11171
|
summary: "Start every enabled server in a workspace",
|
|
@@ -10757,7 +11208,10 @@ function createServersRoute(deps) {
|
|
|
10757
11208
|
tags: ["servers"],
|
|
10758
11209
|
summary: "Buffered log lines from memory",
|
|
10759
11210
|
responses: {
|
|
10760
|
-
200: {
|
|
11211
|
+
200: {
|
|
11212
|
+
description: "Lines",
|
|
11213
|
+
content: jsonBody(logLinesResponseSchema)
|
|
11214
|
+
},
|
|
10761
11215
|
404: ERROR_RESPONSES[404]
|
|
10762
11216
|
}
|
|
10763
11217
|
}), validate("query", bufferedLogsQuery), validate("param", idParam$1), (c) => {
|
|
@@ -10831,41 +11285,56 @@ function createServersRoute(deps) {
|
|
|
10831
11285
|
tags: ["servers"],
|
|
10832
11286
|
summary: "Start a server",
|
|
10833
11287
|
responses: {
|
|
10834
|
-
200: {
|
|
10835
|
-
|
|
11288
|
+
200: {
|
|
11289
|
+
description: "Result",
|
|
11290
|
+
content: jsonBody(actionResultSchema)
|
|
11291
|
+
},
|
|
11292
|
+
404: ERROR_RESPONSES[404],
|
|
11293
|
+
409: { description: "The entry cannot act right now" }
|
|
10836
11294
|
}
|
|
10837
11295
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10838
11296
|
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));
|
|
11297
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10840
11298
|
}).post("/:id/stop", describeRoute({
|
|
10841
11299
|
tags: ["servers"],
|
|
10842
11300
|
summary: "Stop a server",
|
|
10843
11301
|
responses: {
|
|
10844
|
-
200: {
|
|
10845
|
-
|
|
11302
|
+
200: {
|
|
11303
|
+
description: "Result",
|
|
11304
|
+
content: jsonBody(actionResultSchema)
|
|
11305
|
+
},
|
|
11306
|
+
404: ERROR_RESPONSES[404],
|
|
11307
|
+
409: { description: "The entry cannot act right now" }
|
|
10846
11308
|
}
|
|
10847
11309
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10848
11310
|
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
|
|
11311
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10850
11312
|
}).post("/:id/restart", describeRoute({
|
|
10851
11313
|
tags: ["servers"],
|
|
10852
11314
|
summary: "Restart a server",
|
|
10853
11315
|
responses: {
|
|
10854
|
-
200: {
|
|
10855
|
-
|
|
11316
|
+
200: {
|
|
11317
|
+
description: "Result",
|
|
11318
|
+
content: jsonBody(actionResultSchema)
|
|
11319
|
+
},
|
|
11320
|
+
404: ERROR_RESPONSES[404],
|
|
11321
|
+
409: { description: "The entry cannot act right now" }
|
|
10856
11322
|
}
|
|
10857
11323
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), async (c) => {
|
|
10858
11324
|
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));
|
|
11325
|
+
return c.json(actionAnswer(result), statusForAction(result));
|
|
10860
11326
|
}).post("/:id/clear-logs", describeRoute({
|
|
10861
11327
|
tags: ["servers"],
|
|
10862
11328
|
summary: "Forget the buffered log lines",
|
|
10863
11329
|
responses: { 200: {
|
|
10864
11330
|
description: "Cleared",
|
|
10865
|
-
content: jsonBody(
|
|
11331
|
+
content: jsonBody(okResponseSchema)
|
|
10866
11332
|
} }
|
|
10867
11333
|
}), validate("query", workspaceQuerySchema), validate("param", idParam$1), (c) => {
|
|
10868
|
-
requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace)
|
|
11334
|
+
const runtime = requireWorkspace(deps.panel.requireWorkspace.bind(deps.panel), c.req.valid("query").workspace);
|
|
11335
|
+
const { id } = c.req.valid("param");
|
|
11336
|
+
if (!runtime.store.getServer(id)) throw unknownServerError(id);
|
|
11337
|
+
runtime.supervisor.clearLogs(id);
|
|
10869
11338
|
return c.json({ ok: true });
|
|
10870
11339
|
}).post("/:id/free-port", describeRoute({
|
|
10871
11340
|
tags: ["servers"],
|
|
@@ -10884,7 +11353,7 @@ function createServersRoute(deps) {
|
|
|
10884
11353
|
const result = await runtime.supervisor.freePort(id);
|
|
10885
11354
|
if (!result.ok) throw new DetailedError(result.error ?? `could not free the port for "${id}"`, {
|
|
10886
11355
|
statusCode: statusForAction(result),
|
|
10887
|
-
code: "FREE_PORT_FAILED"
|
|
11356
|
+
code: actionCode(result) === "UNKNOWN_SERVER" ? "UNKNOWN_SERVER" : "FREE_PORT_FAILED"
|
|
10888
11357
|
});
|
|
10889
11358
|
return c.json(result);
|
|
10890
11359
|
}).patch("/:id", describeRoute({
|
|
@@ -10918,7 +11387,7 @@ function createServersRoute(deps) {
|
|
|
10918
11387
|
responses: {
|
|
10919
11388
|
200: {
|
|
10920
11389
|
description: "Removed",
|
|
10921
|
-
content: jsonBody(
|
|
11390
|
+
content: jsonBody(okResponseSchema)
|
|
10922
11391
|
},
|
|
10923
11392
|
404: ERROR_RESPONSES[404]
|
|
10924
11393
|
}
|
|
@@ -10935,7 +11404,7 @@ function createServersRoute(deps) {
|
|
|
10935
11404
|
}
|
|
10936
11405
|
});
|
|
10937
11406
|
}
|
|
10938
|
-
var idParam$1, MAX_PENDING_WRITES, serverResponse, serversResponse, storedServerResponse,
|
|
11407
|
+
var idParam$1, MAX_PENDING_WRITES, serverResponse, serversResponse, storedServerResponse, bufferedLogsQuery;
|
|
10939
11408
|
var init_$_routes$1 = __esmMin((() => {
|
|
10940
11409
|
init_store();
|
|
10941
11410
|
init_action_result();
|
|
@@ -10951,7 +11420,6 @@ var init_$_routes$1 = __esmMin((() => {
|
|
|
10951
11420
|
serverResponse = type({ server: serverViewSchema });
|
|
10952
11421
|
serversResponse = type({ servers: serverViewSchema.array() });
|
|
10953
11422
|
storedServerResponse = type({ server: serverSchema });
|
|
10954
|
-
okResponse = type({ ok: "boolean" });
|
|
10955
11423
|
bufferedLogsQuery = logQuerySchema.merge(workspaceQuerySchema);
|
|
10956
11424
|
}));
|
|
10957
11425
|
//#endregion
|
|
@@ -11075,7 +11543,10 @@ function createSettingsRoute(deps) {
|
|
|
11075
11543
|
tags: ["panel"],
|
|
11076
11544
|
summary: "Replace the panel UI with an uploaded static build",
|
|
11077
11545
|
responses: {
|
|
11078
|
-
200: {
|
|
11546
|
+
200: {
|
|
11547
|
+
description: "Installed",
|
|
11548
|
+
content: jsonBody(uiInstallResponseSchema)
|
|
11549
|
+
},
|
|
11079
11550
|
400: ERROR_RESPONSES[400],
|
|
11080
11551
|
413: ERROR_RESPONSES[413]
|
|
11081
11552
|
}
|
|
@@ -11131,7 +11602,10 @@ function createSettingsRoute(deps) {
|
|
|
11131
11602
|
).delete("/settings/ui", describeRoute({
|
|
11132
11603
|
tags: ["panel"],
|
|
11133
11604
|
summary: "Go back to the stock UI",
|
|
11134
|
-
responses: { 200: {
|
|
11605
|
+
responses: { 200: {
|
|
11606
|
+
description: "Reverted",
|
|
11607
|
+
content: jsonBody(uiInstallResponseSchema)
|
|
11608
|
+
} }
|
|
11135
11609
|
}), (c) => {
|
|
11136
11610
|
const removed = deps.ui.revert();
|
|
11137
11611
|
logger.info(removed ? "custom UI removed — the stock panel is back" : "no custom UI was installed");
|
|
@@ -11227,6 +11701,10 @@ function createStaticRoute(options) {
|
|
|
11227
11701
|
const root = currentRoot();
|
|
11228
11702
|
const pathname = safeDecode(new URL(c.req.url).pathname);
|
|
11229
11703
|
if (pathname === null) return c.text("bad path", 400);
|
|
11704
|
+
if (isApiPath(pathname)) return c.json({
|
|
11705
|
+
message: `no route for ${c.req.method} ${pathname}`,
|
|
11706
|
+
code: "NOT_FOUND"
|
|
11707
|
+
}, 404);
|
|
11230
11708
|
const file = resolveWithin(root, pathname);
|
|
11231
11709
|
if (file !== null) {
|
|
11232
11710
|
const response = await serveFile(c, file, pathname);
|
|
@@ -11241,6 +11719,10 @@ function createStaticRoute(options) {
|
|
|
11241
11719
|
});
|
|
11242
11720
|
return route;
|
|
11243
11721
|
}
|
|
11722
|
+
/** `/api` itself and everything under it is the JSON surface, never a UI route. */
|
|
11723
|
+
function isApiPath(pathname) {
|
|
11724
|
+
return pathname === "/api" || pathname.startsWith("/api/");
|
|
11725
|
+
}
|
|
11244
11726
|
function safeDecode(value) {
|
|
11245
11727
|
try {
|
|
11246
11728
|
return decodeURIComponent(value);
|
|
@@ -11312,7 +11794,10 @@ function createTlsRoute(deps) {
|
|
|
11312
11794
|
tags: ["tls"],
|
|
11313
11795
|
summary: "Upload the certificate and key the panel should serve",
|
|
11314
11796
|
responses: {
|
|
11315
|
-
200: {
|
|
11797
|
+
200: {
|
|
11798
|
+
description: "Stored; the panel may be moving to https",
|
|
11799
|
+
content: jsonBody(tlsReviewResponseSchema)
|
|
11800
|
+
},
|
|
11316
11801
|
400: ERROR_RESPONSES[400]
|
|
11317
11802
|
}
|
|
11318
11803
|
}), validate("json", tlsUploadSchema), (c) => {
|
|
@@ -11331,7 +11816,10 @@ function createTlsRoute(deps) {
|
|
|
11331
11816
|
}).delete("/settings/tls", describeRoute({
|
|
11332
11817
|
tags: ["tls"],
|
|
11333
11818
|
summary: "Remove the certificate pair",
|
|
11334
|
-
responses: { 200: {
|
|
11819
|
+
responses: { 200: {
|
|
11820
|
+
description: "Removed",
|
|
11821
|
+
content: jsonBody(tlsReviewResponseSchema)
|
|
11822
|
+
} }
|
|
11335
11823
|
}), (c) => {
|
|
11336
11824
|
deps.tls.clear();
|
|
11337
11825
|
if (deps.panel.settings.control.tls.enabled) afterResponse(async () => {
|
|
@@ -11520,6 +12008,10 @@ function setupOpenAPI(app) {
|
|
|
11520
12008
|
name: "logs",
|
|
11521
12009
|
description: "Live and persisted logs"
|
|
11522
12010
|
},
|
|
12011
|
+
{
|
|
12012
|
+
name: "workspaces",
|
|
12013
|
+
description: "The ownership boundary: one scope per setup"
|
|
12014
|
+
},
|
|
11523
12015
|
{
|
|
11524
12016
|
name: "backups",
|
|
11525
12017
|
description: "Archives of config, secrets, TLS and data paths"
|
|
@@ -11530,13 +12022,40 @@ function setupOpenAPI(app) {
|
|
|
11530
12022
|
},
|
|
11531
12023
|
{
|
|
11532
12024
|
name: "notifications",
|
|
11533
|
-
description: "Telegram delivery"
|
|
12025
|
+
description: "Telegram delivery and webhook destinations"
|
|
12026
|
+
},
|
|
12027
|
+
{
|
|
12028
|
+
name: "ddns",
|
|
12029
|
+
description: "Dynamic DNS accounts and hostnames"
|
|
12030
|
+
},
|
|
12031
|
+
{
|
|
12032
|
+
name: "proxy",
|
|
12033
|
+
description: "The reverse proxy: engine, routes and certificates"
|
|
11534
12034
|
},
|
|
11535
12035
|
{
|
|
11536
12036
|
name: "tls",
|
|
11537
12037
|
description: "The panel certificate"
|
|
11538
12038
|
}
|
|
11539
|
-
]
|
|
12039
|
+
],
|
|
12040
|
+
/**
|
|
12041
|
+
* The auth scheme, so a generated client can be told how to send a credential.
|
|
12042
|
+
*
|
|
12043
|
+
* Every `/api` route takes `Authorization: Bearer hh_…`, and the spec said nothing
|
|
12044
|
+
* about it: openapi-typescript, openapi-generator and Scalar's "try it" all produced
|
|
12045
|
+
* clients with no auth hook, and the README tells an agent this document *is* the API
|
|
12046
|
+
* it may call. Two lines here are the difference between generating a client and
|
|
12047
|
+
* hand-writing one.
|
|
12048
|
+
*/
|
|
12049
|
+
components: { securitySchemes: { bearerAuth: {
|
|
12050
|
+
type: "http",
|
|
12051
|
+
scheme: "bearer",
|
|
12052
|
+
description: "An API token from `home-hosted set-token --generate`. A cookie session works too, but is not part of this scheme."
|
|
12053
|
+
} } },
|
|
12054
|
+
security: [{ bearerAuth: [] }],
|
|
12055
|
+
servers: [{
|
|
12056
|
+
url: "/",
|
|
12057
|
+
description: "This panel"
|
|
12058
|
+
}]
|
|
11540
12059
|
} })).get(`${PREFIX}/ui`, Scalar({
|
|
11541
12060
|
theme: "deepSpace",
|
|
11542
12061
|
url: `${PREFIX}/spec.json`
|
|
@@ -12021,9 +12540,18 @@ async function listZip(file) {
|
|
|
12021
12540
|
await reader.close();
|
|
12022
12541
|
}
|
|
12023
12542
|
}
|
|
12024
|
-
/**
|
|
12543
|
+
/**
|
|
12544
|
+
* True when the archive rejected the password we used.
|
|
12545
|
+
*
|
|
12546
|
+
* Matched on the wording zip.js raises for a bad password, not on the word alone: the message is
|
|
12547
|
+
* `Invalid password`, while a *file it cannot open* produces `ENOENT: … stat '/tmp/…/my-password-
|
|
12548
|
+
* backup.zip'` — which carries the word because the caller named the archive that. A substring test
|
|
12549
|
+
* read that as a wrong password and told the person to re-enter one, when the archive was simply
|
|
12550
|
+
* not there. (Caught by CI, where Node's fs message names the path; the local run said
|
|
12551
|
+
* `Unable to open file as blob`, so the same call looked fine.)
|
|
12552
|
+
*/
|
|
12025
12553
|
function isInvalidPassword(error) {
|
|
12026
|
-
return error instanceof Error && /password/i.test(error.message);
|
|
12554
|
+
return error instanceof Error && /invalid password/i.test(error.message);
|
|
12027
12555
|
}
|
|
12028
12556
|
/**
|
|
12029
12557
|
* Writes the contents of `sourceDir` into `destination`, preserving the tree.
|
|
@@ -12588,18 +13116,28 @@ function dependentsOf(server, servers) {
|
|
|
12588
13116
|
var init_dependencies = __esmMin((() => {}));
|
|
12589
13117
|
//#endregion
|
|
12590
13118
|
//#region src/services/log-buffer.ts
|
|
12591
|
-
var MAX_PENDING_CHARS, LogBuffer, LineSplitter;
|
|
13119
|
+
var MAX_PENDING_CHARS, MAX_TOTAL_CHARS, LogBuffer, LineSplitter;
|
|
12592
13120
|
var init_log_buffer = __esmMin((() => {
|
|
12593
13121
|
MAX_PENDING_CHARS = 65536;
|
|
13122
|
+
MAX_TOTAL_CHARS = 4194304;
|
|
12594
13123
|
LogBuffer = class {
|
|
12595
13124
|
capacity;
|
|
12596
13125
|
lines = [];
|
|
13126
|
+
/** Characters held, so the byte ceiling never needs a rescan. */
|
|
13127
|
+
chars = 0;
|
|
12597
13128
|
constructor(capacity) {
|
|
12598
13129
|
this.capacity = capacity;
|
|
12599
13130
|
}
|
|
12600
13131
|
push(line) {
|
|
12601
13132
|
this.lines.push(line);
|
|
12602
|
-
|
|
13133
|
+
this.chars += line.text.length;
|
|
13134
|
+
if (this.lines.length > this.capacity) this.dropOldest(this.lines.length - this.capacity);
|
|
13135
|
+
while (this.chars > MAX_TOTAL_CHARS && this.lines.length > 1) this.dropOldest(1);
|
|
13136
|
+
}
|
|
13137
|
+
/** Removes the oldest `count` lines and keeps `chars` in step with them. */
|
|
13138
|
+
dropOldest(count) {
|
|
13139
|
+
const dropped = this.lines.splice(0, count);
|
|
13140
|
+
for (const line of dropped) this.chars -= line.text.length;
|
|
12603
13141
|
}
|
|
12604
13142
|
extend(lines) {
|
|
12605
13143
|
for (const line of lines) this.push(line);
|
|
@@ -12610,6 +13148,7 @@ var init_log_buffer = __esmMin((() => {
|
|
|
12610
13148
|
}
|
|
12611
13149
|
clear() {
|
|
12612
13150
|
this.lines = [];
|
|
13151
|
+
this.chars = 0;
|
|
12613
13152
|
}
|
|
12614
13153
|
get size() {
|
|
12615
13154
|
return this.lines.length;
|
|
@@ -12961,6 +13500,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
12961
13500
|
*/
|
|
12962
13501
|
relay = new LogRelay({ onLines: (serverId, lines) => this.ingestExternalLines(serverId, lines) });
|
|
12963
13502
|
entries = /* @__PURE__ */ new Map();
|
|
13503
|
+
/** Processes no entry owns, refreshed by the tick; read synchronously by the state frame. */
|
|
13504
|
+
orphanCache = [];
|
|
12964
13505
|
tickTimer;
|
|
12965
13506
|
/** Detaches this supervisor from the store's listener set in `dispose()`. */
|
|
12966
13507
|
storeUnsubscribe;
|
|
@@ -12981,6 +13522,82 @@ var init_supervisor = __esmMin((() => {
|
|
|
12981
13522
|
views() {
|
|
12982
13523
|
return [...this.entries.values()].map((entry) => this.view(entry));
|
|
12983
13524
|
}
|
|
13525
|
+
/**
|
|
13526
|
+
* Processes this panel started that no configured entry claims any more.
|
|
13527
|
+
*
|
|
13528
|
+
* A detached child outlives a hard panel death, and the only handle is the entry-state file
|
|
13529
|
+
* keyed by the id it was started under. Rename the entry and no code path reads that file again;
|
|
13530
|
+
* remove the entry while the panel is down and `sync` reclaims it, destroying the last handle.
|
|
13531
|
+
* The orphan then runs with no card, no `/healthz` line and no CLI action — for a queue consumer
|
|
13532
|
+
* that is two consumers of one queue, which is the most damaging duplicate this tool can create.
|
|
13533
|
+
*
|
|
13534
|
+
* Read from the state directory rather than from a list, so a file left by an *earlier* panel is
|
|
13535
|
+
* found too. Reported, never touched: a pid here is one whose identity the platform may not be
|
|
13536
|
+
* able to confirm, and killing on a guess is exactly what the rest of this file refuses to do.
|
|
13537
|
+
*/
|
|
13538
|
+
orphans() {
|
|
13539
|
+
return [...this.orphanCache];
|
|
13540
|
+
}
|
|
13541
|
+
/**
|
|
13542
|
+
* Re-reads the state directory for processes no entry owns.
|
|
13543
|
+
*
|
|
13544
|
+
* Async (it asks the platform for a birth time per pid) and therefore driven by the tick, not by
|
|
13545
|
+
* the state frame: the view is built on every publish, and a `readdirSync` plus an async birth
|
|
13546
|
+
* check there would either block or force the whole frame async.
|
|
13547
|
+
*/
|
|
13548
|
+
async refreshOrphans() {
|
|
13549
|
+
let names;
|
|
13550
|
+
try {
|
|
13551
|
+
names = fs.readdirSync(this.options.nannyDir);
|
|
13552
|
+
} catch {
|
|
13553
|
+
this.orphanCache = [];
|
|
13554
|
+
return;
|
|
13555
|
+
}
|
|
13556
|
+
const found = [];
|
|
13557
|
+
for (const name of names) {
|
|
13558
|
+
if (!name.endsWith(".run.json")) continue;
|
|
13559
|
+
const id = name.slice(0, -9);
|
|
13560
|
+
if (this.entries.has(id)) continue;
|
|
13561
|
+
const state = readEntryState(path.join(this.options.nannyDir, name));
|
|
13562
|
+
const pid = state?.lastPid ?? null;
|
|
13563
|
+
if (pid === null || pid === process.pid) continue;
|
|
13564
|
+
const startedAt = state?.lastStartedAt ?? 0;
|
|
13565
|
+
const liveness = startedAt > 0 ? await processLiveness(pid, startedAt) : isProcessAlive(pid) ? "unknown" : "gone";
|
|
13566
|
+
if (liveness === "gone" || liveness === "recycled") continue;
|
|
13567
|
+
found.push({
|
|
13568
|
+
serverId: id,
|
|
13569
|
+
pid,
|
|
13570
|
+
startedAt: startedAt > 0 ? startedAt : null
|
|
13571
|
+
});
|
|
13572
|
+
}
|
|
13573
|
+
this.orphanCache = found;
|
|
13574
|
+
}
|
|
13575
|
+
/**
|
|
13576
|
+
* Stops one reported orphan and reclaims its record.
|
|
13577
|
+
*
|
|
13578
|
+
* Reporting without acting is a dead end: the alternative was `ps` + `kill` in a shell, which is
|
|
13579
|
+
* the thing this panel exists to avoid. The record is cleared only once the pid is gone — a pid
|
|
13580
|
+
* that survived SIGKILL keeps its file, so the next boot can still find it.
|
|
13581
|
+
*/
|
|
13582
|
+
async stopOrphan(serverId) {
|
|
13583
|
+
await this.refreshOrphans();
|
|
13584
|
+
const orphan = this.orphans().find((entry) => entry.serverId === serverId);
|
|
13585
|
+
if (orphan === void 0) return {
|
|
13586
|
+
ok: false,
|
|
13587
|
+
error: `no orphaned process is running as "${serverId}"`
|
|
13588
|
+
};
|
|
13589
|
+
const { forced } = await terminatePids([orphan.pid], { graceMs: 5e3 });
|
|
13590
|
+
const statePath = entryStatePath(this.options.nannyDir, serverId);
|
|
13591
|
+
if (isProcessAlive(orphan.pid)) return {
|
|
13592
|
+
ok: false,
|
|
13593
|
+
error: `pid ${orphan.pid} survived the stop — kill it from a shell, its record is kept`
|
|
13594
|
+
};
|
|
13595
|
+
clearEntryState(statePath);
|
|
13596
|
+
await this.refreshOrphans();
|
|
13597
|
+
logger.info(`stopped the orphaned process ${orphan.pid} (was "${serverId}")${forced.length > 0 ? ", force-killed" : ""}`);
|
|
13598
|
+
this.publishState();
|
|
13599
|
+
return { ok: true };
|
|
13600
|
+
}
|
|
12984
13601
|
logLines(id, limit) {
|
|
12985
13602
|
return this.entries.get(id)?.logs.list(limit) ?? [];
|
|
12986
13603
|
}
|
|
@@ -13032,9 +13649,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
13032
13649
|
};
|
|
13033
13650
|
entry.starting = true;
|
|
13034
13651
|
entry.actor = options.retry ? "policy" : options.actor ?? "policy";
|
|
13652
|
+
entry.stoppedByPanel = false;
|
|
13035
13653
|
this.clearRetry(entry);
|
|
13036
13654
|
if (!options.retry) {
|
|
13037
13655
|
entry.restarts = 0;
|
|
13656
|
+
if (entry.actor !== "policy") entry.healthRestarts = 0;
|
|
13657
|
+
if (entry.actor !== "policy") entry.pendingRestart = null;
|
|
13038
13658
|
entry.healthFailures = 0;
|
|
13039
13659
|
entry.unhealthySince = null;
|
|
13040
13660
|
this.persistEntryState(entry);
|
|
@@ -13084,7 +13704,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
13084
13704
|
return this.stopEntry(entry);
|
|
13085
13705
|
}
|
|
13086
13706
|
async restart(id, options = {}) {
|
|
13707
|
+
const owed = this.entries.get(id)?.pendingRestart ?? null;
|
|
13087
13708
|
await this.stop(id);
|
|
13709
|
+
const entry = this.entries.get(id);
|
|
13710
|
+
if (entry !== void 0 && owed !== null && entry.pendingRestart === null) entry.pendingRestart = owed;
|
|
13088
13711
|
return this.start(id, options);
|
|
13089
13712
|
}
|
|
13090
13713
|
/**
|
|
@@ -13120,11 +13743,40 @@ var init_supervisor = __esmMin((() => {
|
|
|
13120
13743
|
error: `server "${id}" is busy — try again in a moment`
|
|
13121
13744
|
};
|
|
13122
13745
|
const { ours, foreign } = await this.portHolders(port);
|
|
13123
|
-
if ([...ours, ...foreign].length === 0)
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13746
|
+
if ([...ours, ...foreign].length === 0) {
|
|
13747
|
+
const docker = await findDockerPortHolder(port);
|
|
13748
|
+
if (docker !== null) {
|
|
13749
|
+
this.log(entry, "system", `freeing port ${port}: stopping the docker container "${docker.container}"`);
|
|
13750
|
+
if (await releaseDockerPort(docker) && await this.waitForPortRelease(entry, port)) {
|
|
13751
|
+
if (entry.status === "conflict") {
|
|
13752
|
+
entry.status = "stopped";
|
|
13753
|
+
entry.lastError = null;
|
|
13754
|
+
}
|
|
13755
|
+
entry.portState = "free";
|
|
13756
|
+
this.log(entry, "system", `port ${port} is free (stopped the docker container "${docker.container}")`);
|
|
13757
|
+
this.publishServer(entry);
|
|
13758
|
+
return {
|
|
13759
|
+
...empty,
|
|
13760
|
+
ok: true,
|
|
13761
|
+
port,
|
|
13762
|
+
terminated: [],
|
|
13763
|
+
forced: [],
|
|
13764
|
+
skipped: [],
|
|
13765
|
+
free: true
|
|
13766
|
+
};
|
|
13767
|
+
}
|
|
13768
|
+
return {
|
|
13769
|
+
...empty,
|
|
13770
|
+
port,
|
|
13771
|
+
error: `docker could not stop the container "${docker.container}" publishing port ${port} — check \`docker logs ${docker.container}\``
|
|
13772
|
+
};
|
|
13773
|
+
}
|
|
13774
|
+
return {
|
|
13775
|
+
...empty,
|
|
13776
|
+
port,
|
|
13777
|
+
error: `nothing is listening on port ${port} any more`
|
|
13778
|
+
};
|
|
13779
|
+
}
|
|
13128
13780
|
if (foreign.length === 0) {
|
|
13129
13781
|
const reason = `port ${port} is held by pid ${ours.join(", ")}, which this panel supervises — stop that server instead`;
|
|
13130
13782
|
return {
|
|
@@ -13228,13 +13880,14 @@ var init_supervisor = __esmMin((() => {
|
|
|
13228
13880
|
for (const dependency of dependenciesOf(entry.config, this.store.servers)) {
|
|
13229
13881
|
const target = this.entries.get(dependency.id);
|
|
13230
13882
|
if (!target || !dependency.enabled) continue;
|
|
13231
|
-
if (target.status
|
|
13232
|
-
|
|
13233
|
-
|
|
13883
|
+
if (target.status !== "running" && target.child === null) {
|
|
13884
|
+
this.log(entry, "system", `starting dependency "${dependency.id}" first`);
|
|
13885
|
+
await this.start(dependency.id);
|
|
13886
|
+
}
|
|
13234
13887
|
const deadline = Date.now() + dependency.health.startTimeoutMs;
|
|
13235
13888
|
const isReady = () => {
|
|
13236
13889
|
if (this.statusOf(target) !== "running") return false;
|
|
13237
|
-
return target.health
|
|
13890
|
+
return target.health === "healthy" || target.health === "disabled";
|
|
13238
13891
|
};
|
|
13239
13892
|
while (!isReady() && Date.now() < deadline) await delay(250);
|
|
13240
13893
|
if (!isReady()) {
|
|
@@ -13348,15 +14001,18 @@ var init_supervisor = __esmMin((() => {
|
|
|
13348
14001
|
exitCode: null,
|
|
13349
14002
|
exitSignal: null,
|
|
13350
14003
|
restarts: persisted?.restarts ?? 0,
|
|
14004
|
+
healthRestarts: persisted?.healthRestarts ?? 0,
|
|
13351
14005
|
lastError: null,
|
|
13352
14006
|
nextRetryAt: null,
|
|
13353
14007
|
retryTimer: null,
|
|
13354
14008
|
healthFailures: 0,
|
|
13355
14009
|
unhealthySince: null,
|
|
14010
|
+
pendingRestart: null,
|
|
13356
14011
|
lastProbeAt: 0,
|
|
13357
14012
|
lastOccupancyProbeAt: 0,
|
|
13358
14013
|
probing: false,
|
|
13359
14014
|
adopted: false,
|
|
14015
|
+
stoppedByPanel: false,
|
|
13360
14016
|
nannyExit: null,
|
|
13361
14017
|
starting: false,
|
|
13362
14018
|
stopping: false,
|
|
@@ -13462,7 +14118,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
13462
14118
|
const { ours, foreign } = await this.portHolders(port);
|
|
13463
14119
|
const holders = [...ours, ...foreign];
|
|
13464
14120
|
const own = await this.ownPortHolder(entry, foreign);
|
|
13465
|
-
const
|
|
14121
|
+
const docker = holders.length === 0 ? await findDockerPortHolder(port) : null;
|
|
14122
|
+
const suffix = holders.length > 0 ? ` (pid ${holders.join(", ")})` : docker === null ? "" : ` (published by the docker container "${docker.container}")`;
|
|
13466
14123
|
if (entry.config.onPortConflict === "kill") {
|
|
13467
14124
|
if (ours.length > 0) {
|
|
13468
14125
|
entry.status = "conflict";
|
|
@@ -13475,6 +14132,17 @@ var init_supervisor = __esmMin((() => {
|
|
|
13475
14132
|
};
|
|
13476
14133
|
}
|
|
13477
14134
|
if (foreign.length === 0) {
|
|
14135
|
+
if (docker !== null) {
|
|
14136
|
+
this.log(entry, "system", `port ${port} is published by the docker container "${docker.container}" — onPortConflict: kill, stopping it`);
|
|
14137
|
+
if (await releaseDockerPort(docker) && await this.waitForPortRelease(entry, port)) return { kind: "free" };
|
|
14138
|
+
entry.status = "conflict";
|
|
14139
|
+
entry.lastError = `docker could not stop the container "${docker.container}" publishing port ${port}`;
|
|
14140
|
+
this.publishServer(entry);
|
|
14141
|
+
return {
|
|
14142
|
+
kind: "blocked",
|
|
14143
|
+
error: entry.lastError
|
|
14144
|
+
};
|
|
14145
|
+
}
|
|
13478
14146
|
this.log(entry, "system", `port ${port} looks busy but no listener could be found — starting anyway`);
|
|
13479
14147
|
return { kind: "free" };
|
|
13480
14148
|
}
|
|
@@ -13489,7 +14157,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13489
14157
|
this.log(entry, "system", `port ${port} is held by pid ${own}, a detached restart of this entry — replacing it with a supervised process`);
|
|
13490
14158
|
return await this.stopPortHolders(entry, [own], port, "replacing", freeOnAll);
|
|
13491
14159
|
}
|
|
13492
|
-
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` : "";
|
|
14160
|
+
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`;
|
|
13493
14161
|
if (entry.config.onPortConflict !== "warn") {
|
|
13494
14162
|
entry.status = "conflict";
|
|
13495
14163
|
entry.lastError = `port ${port} is already in use${suffix}${hint}`;
|
|
@@ -13615,6 +14283,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13615
14283
|
this.forgetRecordedChild(entry, adoptedPid);
|
|
13616
14284
|
entry.resources = null;
|
|
13617
14285
|
entry.responseMs = null;
|
|
14286
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
13618
14287
|
entry.exitCode = null;
|
|
13619
14288
|
entry.exitSignal = null;
|
|
13620
14289
|
if (!entry.removed) this.options.history.record(entry.config.id, {
|
|
@@ -13838,7 +14507,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13838
14507
|
entry.unhealthySince = null;
|
|
13839
14508
|
this.publishServer(entry);
|
|
13840
14509
|
child.once("error", (error) => {
|
|
13841
|
-
entry.lastError = error.
|
|
14510
|
+
entry.lastError = describeSpawnError(error, entry.config.command);
|
|
13842
14511
|
this.log(entry, "system", `process error: ${entry.lastError}`);
|
|
13843
14512
|
flush?.();
|
|
13844
14513
|
this.handleExit(entry, child, null, null);
|
|
@@ -13957,6 +14626,21 @@ var init_supervisor = __esmMin((() => {
|
|
|
13957
14626
|
clearNannyState(statePath);
|
|
13958
14627
|
this.drainRelay(entry);
|
|
13959
14628
|
}
|
|
14629
|
+
/**
|
|
14630
|
+
* Announces the outcome of a force restart, once, the first moment the entry is serving.
|
|
14631
|
+
*
|
|
14632
|
+
* Every "it is up again" path calls this — spawn with no port, readiness accepted, and the
|
|
14633
|
+
* first healthy probe — and the pending flag makes it idempotent, so whichever happens
|
|
14634
|
+
* first is the one that reports.
|
|
14635
|
+
*/
|
|
14636
|
+
settleRestart(entry, detail) {
|
|
14637
|
+
const pending = entry.pendingRestart;
|
|
14638
|
+
if (pending === null) return;
|
|
14639
|
+
entry.pendingRestart = null;
|
|
14640
|
+
const message = `after ${pending.cause}: ${detail}`;
|
|
14641
|
+
this.log(entry, "system", `restarted, and it is serving again — ${message}`);
|
|
14642
|
+
this.notify(entry, "restart-ok", message);
|
|
14643
|
+
}
|
|
13960
14644
|
/** One probe using the configured mode (TCP or HTTP), with timing. */
|
|
13961
14645
|
async probeEntryHealth(entry) {
|
|
13962
14646
|
const { port, health } = entry.config;
|
|
@@ -13980,6 +14664,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13980
14664
|
entry.status = "running";
|
|
13981
14665
|
entry.health = health.enabled ? "unknown" : "disabled";
|
|
13982
14666
|
this.log(entry, "system", "running (no port configured; readiness assumed on spawn)");
|
|
14667
|
+
this.settleRestart(entry, "it spawned and is running");
|
|
13983
14668
|
this.publishServer(entry);
|
|
13984
14669
|
return;
|
|
13985
14670
|
}
|
|
@@ -13988,10 +14673,11 @@ var init_supervisor = __esmMin((() => {
|
|
|
13988
14673
|
if (entry.child !== child || entry.status !== "starting" || this.disposed) return;
|
|
13989
14674
|
if (await this.portAccepts(entry, port, Math.min(health.timeoutMs, 1e3))) {
|
|
13990
14675
|
entry.portState = "in-use";
|
|
13991
|
-
entry.health = health.enabled ? "
|
|
14676
|
+
entry.health = !health.enabled ? "disabled" : health.mode === "http" ? "unknown" : "healthy";
|
|
13992
14677
|
entry.status = "running";
|
|
13993
|
-
entry.lastProbeAt =
|
|
14678
|
+
entry.lastProbeAt = 0;
|
|
13994
14679
|
this.log(entry, "system", `accepting connections on port ${port}`);
|
|
14680
|
+
if (health.mode !== "http") this.settleRestart(entry, `accepting connections on port ${port}`);
|
|
13995
14681
|
this.publishServer(entry);
|
|
13996
14682
|
return;
|
|
13997
14683
|
}
|
|
@@ -14016,6 +14702,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14016
14702
|
entry.adopted = false;
|
|
14017
14703
|
entry.resources = null;
|
|
14018
14704
|
entry.responseMs = null;
|
|
14705
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
14019
14706
|
entry.exitCode = code;
|
|
14020
14707
|
entry.exitSignal = signal;
|
|
14021
14708
|
this.forgetRecordedChild(entry, child.pid ?? null);
|
|
@@ -14067,6 +14754,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14067
14754
|
} else {
|
|
14068
14755
|
entry.status = "crashed";
|
|
14069
14756
|
entry.nextRetryAt = null;
|
|
14757
|
+
entry.pendingRestart = null;
|
|
14070
14758
|
entry.lastError = restart.enabled ? `gave up after ${restart.maxRetries} retries (${detail})` : `${detail} (automatic restart disabled)`;
|
|
14071
14759
|
this.log(entry, "system", entry.lastError);
|
|
14072
14760
|
this.options.history.record(entry.config.id, {
|
|
@@ -14082,6 +14770,9 @@ var init_supervisor = __esmMin((() => {
|
|
|
14082
14770
|
if (this.disposed) return;
|
|
14083
14771
|
const now = Date.now();
|
|
14084
14772
|
await this.sampleResources(now);
|
|
14773
|
+
await this.refreshOrphans().catch((error) => {
|
|
14774
|
+
logger.warn("could not refresh the orphaned-process list", error);
|
|
14775
|
+
});
|
|
14085
14776
|
await Promise.allSettled([...this.entries.values()].map((entry) => this.probeEntry(entry, now)));
|
|
14086
14777
|
for (const entry of this.entries.values()) {
|
|
14087
14778
|
if (entry.adopted && entry.pid !== null && !isProcessAlive(entry.pid)) {
|
|
@@ -14089,6 +14780,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
14089
14780
|
continue;
|
|
14090
14781
|
}
|
|
14091
14782
|
if (await this.enforceMemoryLimit(entry)) continue;
|
|
14783
|
+
if (this.healthBudgetSpent(entry)) {
|
|
14784
|
+
await this.giveUpOnHealth(entry);
|
|
14785
|
+
continue;
|
|
14786
|
+
}
|
|
14092
14787
|
if (this.shouldForceRestart(entry, now)) {
|
|
14093
14788
|
await this.restart(entry.config.id);
|
|
14094
14789
|
continue;
|
|
@@ -14133,9 +14828,15 @@ var init_supervisor = __esmMin((() => {
|
|
|
14133
14828
|
});
|
|
14134
14829
|
this.notify(entry, "recovered", probe.detail);
|
|
14135
14830
|
}
|
|
14831
|
+
this.settleRestart(entry, `${probe.detail} (${probe.ms}ms)`);
|
|
14136
14832
|
entry.health = "healthy";
|
|
14137
14833
|
entry.healthFailures = 0;
|
|
14138
14834
|
entry.unhealthySince = null;
|
|
14835
|
+
const servedForMs = entry.startedAt === null ? 0 : Date.now() - entry.startedAt;
|
|
14836
|
+
if (entry.healthRestarts > 0 && servedForMs >= entry.config.restart.resetAfterMs) {
|
|
14837
|
+
entry.healthRestarts = 0;
|
|
14838
|
+
this.persistEntryState(entry);
|
|
14839
|
+
}
|
|
14139
14840
|
return;
|
|
14140
14841
|
}
|
|
14141
14842
|
entry.healthFailures += 1;
|
|
@@ -14166,22 +14867,58 @@ var init_supervisor = __esmMin((() => {
|
|
|
14166
14867
|
detail
|
|
14167
14868
|
});
|
|
14168
14869
|
this.notify(entry, "rss", detail);
|
|
14870
|
+
entry.pendingRestart = { cause: "exceeding its memory limit" };
|
|
14169
14871
|
await this.restart(entry.config.id);
|
|
14170
14872
|
return true;
|
|
14171
14873
|
}
|
|
14172
14874
|
shouldForceRestart(entry, now) {
|
|
14173
|
-
const { port, health } = entry.config;
|
|
14875
|
+
const { port, health, restart } = entry.config;
|
|
14174
14876
|
if (port === null || entry.status !== "running" || entry.health !== "unhealthy") return false;
|
|
14175
14877
|
if (entry.unhealthySince === null || health.forceRestartAfterMs <= 0) return false;
|
|
14176
14878
|
if (now - entry.unhealthySince < health.forceRestartAfterMs) return false;
|
|
14177
|
-
|
|
14879
|
+
if (!restart.enabled || entry.healthRestarts >= restart.maxRetries) return false;
|
|
14880
|
+
entry.healthRestarts += 1;
|
|
14881
|
+
this.persistEntryState(entry);
|
|
14882
|
+
this.log(entry, "system", `unhealthy for ${health.forceRestartAfterMs}ms — forcing a restart (${entry.healthRestarts}/${restart.maxRetries})`);
|
|
14178
14883
|
this.options.history.record(entry.config.id, {
|
|
14179
14884
|
type: "forced-restart",
|
|
14180
14885
|
detail: `health check stayed unhealthy`
|
|
14181
14886
|
});
|
|
14182
14887
|
this.notify(entry, "forced-restart", `unhealthy for ${Math.round(health.forceRestartAfterMs / 1e3)}s`);
|
|
14888
|
+
entry.pendingRestart = { cause: "staying unhealthy through its health check" };
|
|
14183
14889
|
return true;
|
|
14184
14890
|
}
|
|
14891
|
+
/** Whether this entry's health budget is spent, so the tick should stop it. */
|
|
14892
|
+
healthBudgetSpent(entry) {
|
|
14893
|
+
const { port, health, restart } = entry.config;
|
|
14894
|
+
if (port === null || entry.status !== "running" || entry.health !== "unhealthy") return false;
|
|
14895
|
+
if (entry.unhealthySince === null || health.forceRestartAfterMs <= 0) return false;
|
|
14896
|
+
return !restart.enabled || entry.healthRestarts >= restart.maxRetries;
|
|
14897
|
+
}
|
|
14898
|
+
/**
|
|
14899
|
+
* Stops an entry that cannot pass its own health check, once the restart budget is spent.
|
|
14900
|
+
*
|
|
14901
|
+
* `stopped` because the process really is stopped; the reason stays on `lastError`, so the card
|
|
14902
|
+
* and the notification still say why. Marking it `crashed` while leaving it running would report
|
|
14903
|
+
* a live pid and a serving port as down.
|
|
14904
|
+
*/
|
|
14905
|
+
async giveUpOnHealth(entry) {
|
|
14906
|
+
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";
|
|
14907
|
+
entry.pendingRestart = null;
|
|
14908
|
+
entry.healthRestarts = 0;
|
|
14909
|
+
entry.stoppedByPanel = true;
|
|
14910
|
+
this.log(entry, "system", detail);
|
|
14911
|
+
this.options.history.record(entry.config.id, {
|
|
14912
|
+
type: "crash",
|
|
14913
|
+
detail
|
|
14914
|
+
});
|
|
14915
|
+
this.notify(entry, "crash", detail);
|
|
14916
|
+
await this.stopEntry(entry);
|
|
14917
|
+
if (!entry.removed) {
|
|
14918
|
+
entry.lastError = detail;
|
|
14919
|
+
this.publishServer(entry);
|
|
14920
|
+
}
|
|
14921
|
+
}
|
|
14185
14922
|
clearRetry(entry) {
|
|
14186
14923
|
if (entry.retryTimer !== null) {
|
|
14187
14924
|
clearTimeout(entry.retryTimer);
|
|
@@ -14193,6 +14930,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14193
14930
|
if (entry.removed) return;
|
|
14194
14931
|
writeEntryState(entryStatePath(this.options.nannyDir, entry.config.id), {
|
|
14195
14932
|
restarts: entry.restarts,
|
|
14933
|
+
healthRestarts: entry.healthRestarts,
|
|
14196
14934
|
bootstrapDone: entry.bootstrapDone,
|
|
14197
14935
|
lastPid: entry.config.persistent ? null : entry.lastChild?.pid ?? null,
|
|
14198
14936
|
lastStartedAt: entry.config.persistent ? null : entry.lastChild?.startedAt ?? null
|
|
@@ -14215,6 +14953,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14215
14953
|
portState: entry.portState,
|
|
14216
14954
|
pid: entry.pid,
|
|
14217
14955
|
...entry.adopted ? { adopted: true } : {},
|
|
14956
|
+
...entry.stoppedByPanel ? { stoppedByPanel: true } : {},
|
|
14218
14957
|
startedAt: entry.startedAt,
|
|
14219
14958
|
exitCode: entry.exitCode,
|
|
14220
14959
|
exitSignal: entry.exitSignal,
|
|
@@ -14452,6 +15191,39 @@ function readableGlobalSettings(text) {
|
|
|
14452
15191
|
}
|
|
14453
15192
|
}
|
|
14454
15193
|
/**
|
|
15194
|
+
* The workspaces an archive's registry names.
|
|
15195
|
+
*
|
|
15196
|
+
* Tolerant on purpose: an archive written before the registry was captured has no such
|
|
15197
|
+
* file, and a damaged one must not fail a restore whose leaves are perfectly readable.
|
|
15198
|
+
* The registry only contributes labels, so anything unreadable is simply dropped.
|
|
15199
|
+
*/
|
|
15200
|
+
function readArchivedRegistry(file) {
|
|
15201
|
+
const text = readText(file);
|
|
15202
|
+
if (text === null) return [];
|
|
15203
|
+
try {
|
|
15204
|
+
const parsed = workspacesFileSchema(JSON.parse(text));
|
|
15205
|
+
if (parsed instanceof type.errors) return [];
|
|
15206
|
+
return parsed.workspaces;
|
|
15207
|
+
} catch {
|
|
15208
|
+
return [];
|
|
15209
|
+
}
|
|
15210
|
+
}
|
|
15211
|
+
/**
|
|
15212
|
+
* Where a workspace created by a restore keeps its three leaves.
|
|
15213
|
+
*
|
|
15214
|
+
* Derived from the service's own `dataRoot` (the `.hh` directory the panel passes) rather
|
|
15215
|
+
* than the module-level path helpers, so a restore writes under the state root of the panel
|
|
15216
|
+
* running it — not under whatever `HHOSTED_HOME` resolves to at import time.
|
|
15217
|
+
*/
|
|
15218
|
+
function workspacePathsFor(dataRoot, id) {
|
|
15219
|
+
const dir = path.join(dataRoot, id);
|
|
15220
|
+
return {
|
|
15221
|
+
settingsPath: path.join(dir, "settings.json"),
|
|
15222
|
+
serversPath: path.join(dir, "servers.config.json"),
|
|
15223
|
+
secretsPath: path.join(dir, ".secrets.json")
|
|
15224
|
+
};
|
|
15225
|
+
}
|
|
15226
|
+
/**
|
|
14455
15227
|
* The manifest is written by us, but an uploaded archive's copy is attacker
|
|
14456
15228
|
* controlled: never join an unvalidated slug into a path.
|
|
14457
15229
|
*/
|
|
@@ -14527,11 +15299,12 @@ function readableWorkspaceSettings(text) {
|
|
|
14527
15299
|
return false;
|
|
14528
15300
|
}
|
|
14529
15301
|
}
|
|
14530
|
-
var MANIFEST, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
15302
|
+
var MANIFEST, REGISTRY, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
14531
15303
|
var init_backups = __esmMin((() => {
|
|
14532
15304
|
init_migrations();
|
|
14533
15305
|
init_parse();
|
|
14534
15306
|
init_secret_parts();
|
|
15307
|
+
init_workspaces();
|
|
14535
15308
|
init_atomic();
|
|
14536
15309
|
init_env_file();
|
|
14537
15310
|
init_logger();
|
|
@@ -14540,10 +15313,12 @@ var init_backups = __esmMin((() => {
|
|
|
14540
15313
|
init_version();
|
|
14541
15314
|
init_archive();
|
|
14542
15315
|
init_supervisor();
|
|
15316
|
+
init_contracts();
|
|
14543
15317
|
init_error_message();
|
|
14544
15318
|
init_generated();
|
|
14545
15319
|
init_shape();
|
|
14546
15320
|
MANIFEST = "manifest.json";
|
|
15321
|
+
REGISTRY = "workspaces.json";
|
|
14547
15322
|
ALLOWED_ROOTS = /* @__PURE__ */ new Set([
|
|
14548
15323
|
"global",
|
|
14549
15324
|
"workspaces",
|
|
@@ -14590,6 +15365,8 @@ var init_backups = __esmMin((() => {
|
|
|
14590
15365
|
* long as the failure lasts. This is the in-memory backstop for that case.
|
|
14591
15366
|
*/
|
|
14592
15367
|
lastAttemptAt = null;
|
|
15368
|
+
/** Why the most recent scheduled pass failed, cleared by the next that works. */
|
|
15369
|
+
scheduleError = null;
|
|
14593
15370
|
constructor(options) {
|
|
14594
15371
|
this.options = options;
|
|
14595
15372
|
}
|
|
@@ -14613,6 +15390,7 @@ var init_backups = __esmMin((() => {
|
|
|
14613
15390
|
keep: config.keep,
|
|
14614
15391
|
schedule: { ...config.schedule },
|
|
14615
15392
|
lastAutomaticAt: this.lastAutomatic(),
|
|
15393
|
+
...this.scheduleError === null ? {} : { scheduleError: { ...this.scheduleError } },
|
|
14616
15394
|
includePaths: [...sources.includePaths],
|
|
14617
15395
|
entries: this.entries(sources),
|
|
14618
15396
|
files: this.list()
|
|
@@ -14705,6 +15483,7 @@ var init_backups = __esmMin((() => {
|
|
|
14705
15483
|
if (capturesGlobal("global:settings")) copy("global/settings.json", sources.globalSettingsPath);
|
|
14706
15484
|
if (capturesSecrets("global:secrets")) copySecrets("global/secrets.json", sources.globalSecretsPath, "global:secrets", "global");
|
|
14707
15485
|
if (capturesGlobal("global:tls")) copy("global/tls", sources.tlsDir);
|
|
15486
|
+
this.copyInto(staging, `global/${REGISTRY}`, sources.registryPath);
|
|
14708
15487
|
const data = [];
|
|
14709
15488
|
for (const workspace of sources.workspaces) {
|
|
14710
15489
|
const root = `workspaces/${workspace.id}`;
|
|
@@ -14803,7 +15582,9 @@ var init_backups = __esmMin((() => {
|
|
|
14803
15582
|
skipped: [],
|
|
14804
15583
|
skippedItems: [],
|
|
14805
15584
|
restartRequired: false,
|
|
14806
|
-
reloaded: false
|
|
15585
|
+
reloaded: false,
|
|
15586
|
+
createdWorkspaces: [],
|
|
15587
|
+
replacedUnderRunning: []
|
|
14807
15588
|
};
|
|
14808
15589
|
if (!isZipArchive(archivePath)) return {
|
|
14809
15590
|
...plan,
|
|
@@ -14962,54 +15743,47 @@ var init_backups = __esmMin((() => {
|
|
|
14962
15743
|
}
|
|
14963
15744
|
}, ["tls"]);
|
|
14964
15745
|
}
|
|
15746
|
+
/**
|
|
15747
|
+
* The workspaces the archive names, from its registry file.
|
|
15748
|
+
*
|
|
15749
|
+
* Optional: an archive written before the registry was captured carries none, and
|
|
15750
|
+
* then every archived workspace is still restorable under its own id — the label is
|
|
15751
|
+
* the only thing the registry adds.
|
|
15752
|
+
*/
|
|
15753
|
+
const archivedWorkspaces = /* @__PURE__ */ new Map();
|
|
15754
|
+
for (const entry of readArchivedRegistry(path.join(staging, "global", REGISTRY))) archivedWorkspaces.set(entry.id, entry);
|
|
14965
15755
|
/** Every archived servers file this release can read, selected or not. */
|
|
14966
15756
|
const archivedServers = /* @__PURE__ */ new Map();
|
|
15757
|
+
/**
|
|
15758
|
+
* Workspaces the archive names that this host does not have, with the paths a
|
|
15759
|
+
* restore will create them under. The directories are made only when one of
|
|
15760
|
+
* their leaves is actually applied, so a dry run writes nothing.
|
|
15761
|
+
*/
|
|
15762
|
+
const createdWorkspaces = /* @__PURE__ */ new Map();
|
|
14967
15763
|
const archiveWorkspaces = path.join(staging, "workspaces");
|
|
14968
15764
|
if (fs.existsSync(archiveWorkspaces)) for (const entry of fs.readdirSync(archiveWorkspaces, { withFileTypes: true })) {
|
|
14969
15765
|
if (!entry.isDirectory()) continue;
|
|
14970
15766
|
const id = entry.name;
|
|
14971
15767
|
const dir = path.join(archiveWorkspaces, id);
|
|
14972
|
-
const workspace = sources.workspaces.find((candidate) => candidate.id === id);
|
|
14973
15768
|
const settings = readText(path.join(dir, "settings.json"));
|
|
14974
15769
|
const servers = readText(path.join(dir, "servers.config.json"));
|
|
14975
15770
|
const secrets = readText(path.join(dir, "secrets.json"));
|
|
15771
|
+
const archivedLabel = archivedWorkspaces.get(id)?.label ?? id;
|
|
15772
|
+
const workspace = sources.workspaces.find((candidate) => candidate.id === id) ?? createdWorkspaces.get(id) ?? (workspaceIdSchema(id) instanceof type.errors ? void 0 : {
|
|
15773
|
+
id,
|
|
15774
|
+
label: archivedLabel,
|
|
15775
|
+
...workspacePathsFor(this.options.dataRoot, id),
|
|
15776
|
+
servers: []
|
|
15777
|
+
});
|
|
14976
15778
|
if (workspace === void 0) {
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
],
|
|
14983
|
-
[
|
|
14984
|
-
"servers",
|
|
14985
|
-
"Servers",
|
|
14986
|
-
servers
|
|
14987
|
-
],
|
|
14988
|
-
[
|
|
14989
|
-
"secrets",
|
|
14990
|
-
"Secrets",
|
|
14991
|
-
secrets
|
|
14992
|
-
]
|
|
14993
|
-
];
|
|
14994
|
-
for (const [suffix, label, text] of leaves) {
|
|
14995
|
-
if (text === null) continue;
|
|
14996
|
-
addItem({
|
|
14997
|
-
id: `workspace:${id}:${suffix}`,
|
|
14998
|
-
label: `${id}: ${label}`,
|
|
14999
|
-
labelKey: "settings.backup.restoreItemLabel",
|
|
15000
|
-
labelParams: {
|
|
15001
|
-
workspace: id,
|
|
15002
|
-
item: suffix
|
|
15003
|
-
},
|
|
15004
|
-
kind: suffix,
|
|
15005
|
-
workspaceId: id,
|
|
15006
|
-
restorable: false,
|
|
15007
|
-
note: "unknown workspace",
|
|
15008
|
-
noteKey: "settings.backup.noteUnknownWorkspace"
|
|
15009
|
-
}, null);
|
|
15010
|
-
}
|
|
15779
|
+
plan.skipped.push(`${id} (not a usable workspace id)`);
|
|
15780
|
+
plan.skippedItems.push({
|
|
15781
|
+
label: id,
|
|
15782
|
+
reasonKey: "settings.restore.reasonInvalidWorkspace"
|
|
15783
|
+
});
|
|
15011
15784
|
continue;
|
|
15012
15785
|
}
|
|
15786
|
+
if (!sources.workspaces.some((candidate) => candidate.id === id)) createdWorkspaces.set(id, workspace);
|
|
15013
15787
|
if (settings !== null) {
|
|
15014
15788
|
if (readableWorkspaceSettings(settings)) addItem({
|
|
15015
15789
|
id: `workspace:${id}:settings`,
|
|
@@ -15024,6 +15798,7 @@ var init_backups = __esmMin((() => {
|
|
|
15024
15798
|
restorable: true,
|
|
15025
15799
|
note: null
|
|
15026
15800
|
}, () => {
|
|
15801
|
+
fs.mkdirSync(path.dirname(workspace.settingsPath), { recursive: true });
|
|
15027
15802
|
writeFileAtomic(workspace.settingsPath, settings);
|
|
15028
15803
|
});
|
|
15029
15804
|
else {
|
|
@@ -15056,6 +15831,7 @@ var init_backups = __esmMin((() => {
|
|
|
15056
15831
|
restorable: true,
|
|
15057
15832
|
note: null
|
|
15058
15833
|
}, () => {
|
|
15834
|
+
fs.mkdirSync(path.dirname(workspace.serversPath), { recursive: true });
|
|
15059
15835
|
writeFileAtomic(workspace.serversPath, servers);
|
|
15060
15836
|
});
|
|
15061
15837
|
} else {
|
|
@@ -15085,6 +15861,7 @@ var init_backups = __esmMin((() => {
|
|
|
15085
15861
|
restorable: true,
|
|
15086
15862
|
note: null
|
|
15087
15863
|
}, () => {
|
|
15864
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15088
15865
|
writeFileAtomic(workspace.secretsPath, secrets, { mode: 384 });
|
|
15089
15866
|
});
|
|
15090
15867
|
for (const part of secretParts("workspace", presentSecretKeys(parseSecrets(secrets)))) addItem({
|
|
@@ -15100,6 +15877,7 @@ var init_backups = __esmMin((() => {
|
|
|
15100
15877
|
restorable: true,
|
|
15101
15878
|
note: null
|
|
15102
15879
|
}, () => {
|
|
15880
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15103
15881
|
mergeIntoFile(workspace.secretsPath, secrets, part.fields);
|
|
15104
15882
|
});
|
|
15105
15883
|
}
|
|
@@ -15134,16 +15912,30 @@ var init_backups = __esmMin((() => {
|
|
|
15134
15912
|
used.add(found);
|
|
15135
15913
|
return found;
|
|
15136
15914
|
};
|
|
15915
|
+
/**
|
|
15916
|
+
* Where one archived data path lands, never across a workspace boundary.
|
|
15917
|
+
*
|
|
15918
|
+
* An archive that names a workspace is only ever matched against that workspace's
|
|
15919
|
+
* declarations: the un-scoped fallbacks below exist to survive a re-labelled or
|
|
15920
|
+
* re-ordered config, and letting them cross workspaces wrote one workspace's data
|
|
15921
|
+
* over a path another one had declared. A path only one workspace declares has no
|
|
15922
|
+
* candidate at all in the other, so the entry is reported instead of guessed at.
|
|
15923
|
+
*/
|
|
15137
15924
|
const matchTarget = (origin, workspace, archivedPath) => {
|
|
15138
|
-
|
|
15139
|
-
|
|
15140
|
-
|
|
15141
|
-
|
|
15142
|
-
|
|
15143
|
-
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);
|
|
15144
|
-
}
|
|
15145
|
-
return take(archiveTargets, usedArchive, (target) => target.path === archivedPath) ?? take(instanceTargets, usedInstance, (target) => target.path === archivedPath);
|
|
15925
|
+
const inScope = (target) => workspace === void 0 || target.workspace === workspace;
|
|
15926
|
+
const archive = archiveTargets.filter(inScope);
|
|
15927
|
+
const instance = instanceTargets.filter(inScope);
|
|
15928
|
+
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);
|
|
15929
|
+
return take(archive, usedArchive, (target) => target.path === archivedPath) ?? take(instance, usedInstance, (target) => target.path === archivedPath);
|
|
15146
15930
|
};
|
|
15931
|
+
/**
|
|
15932
|
+
* `workspace:serverId` for every entry running at this moment.
|
|
15933
|
+
*
|
|
15934
|
+
* Built once, before anything is copied: a data path whose owner is running is about to be
|
|
15935
|
+
* replaced under a live process, and the plan has to name it. Read here rather than in the
|
|
15936
|
+
* apply closure so a dry run reports the same list the apply would.
|
|
15937
|
+
*/
|
|
15938
|
+
const runningOwners = new Set((sources.runningServers?.() ?? []).map((entry) => `${entry.workspaceId}:${entry.serverId}`));
|
|
15147
15939
|
const archivedEntries = Array.isArray(manifest.data) ? manifest.data.filter(isRecord) : [];
|
|
15148
15940
|
for (const entry of archivedEntries) {
|
|
15149
15941
|
const archivedPath = typeof entry.path === "string" ? entry.path : "";
|
|
@@ -15178,6 +15970,12 @@ var init_backups = __esmMin((() => {
|
|
|
15178
15970
|
}, null, aliases);
|
|
15179
15971
|
continue;
|
|
15180
15972
|
}
|
|
15973
|
+
const ownerId = target.origin.split(":")[0] ?? "";
|
|
15974
|
+
if ((selectedIds === null || selectedIds.has(base.id) || aliases.includes(base.id)) && runningOwners.has(`${target.workspace}:${ownerId}`)) plan.replacedUnderRunning.push({
|
|
15975
|
+
workspaceId: target.workspace,
|
|
15976
|
+
serverId: ownerId,
|
|
15977
|
+
path: target.path
|
|
15978
|
+
});
|
|
15181
15979
|
addItem({
|
|
15182
15980
|
...base,
|
|
15183
15981
|
restorable: true,
|
|
@@ -15186,11 +15984,13 @@ var init_backups = __esmMin((() => {
|
|
|
15186
15984
|
noteKey: "settings.backup.noteRestoredFrom",
|
|
15187
15985
|
noteParams: { path: archivedPath }
|
|
15188
15986
|
}
|
|
15189
|
-
}, () =>
|
|
15190
|
-
|
|
15191
|
-
|
|
15192
|
-
|
|
15193
|
-
|
|
15987
|
+
}, () => {
|
|
15988
|
+
fs.cpSync(from, target.path, {
|
|
15989
|
+
recursive: true,
|
|
15990
|
+
force: true,
|
|
15991
|
+
filter: (_source, destination) => isInsideResolved(target.path, destination)
|
|
15992
|
+
});
|
|
15993
|
+
}, aliases);
|
|
15194
15994
|
}
|
|
15195
15995
|
if (parsedGlobal !== null && actions.has("global:settings") && settingsText !== null) {
|
|
15196
15996
|
const currentText = readText(sources.globalSettingsPath);
|
|
@@ -15207,6 +16007,14 @@ var init_backups = __esmMin((() => {
|
|
|
15207
16007
|
plan.applied.push(labelOf(plan, id));
|
|
15208
16008
|
}
|
|
15209
16009
|
plan.appliedIds = [...actions.keys()];
|
|
16010
|
+
for (const workspace of createdWorkspaces.values()) {
|
|
16011
|
+
if (![...actions.keys()].some((id) => id.startsWith(`workspace:${workspace.id}:`))) continue;
|
|
16012
|
+
this.options.ensureWorkspace?.({
|
|
16013
|
+
id: workspace.id,
|
|
16014
|
+
label: workspace.label
|
|
16015
|
+
});
|
|
16016
|
+
plan.createdWorkspaces.push(workspace.id);
|
|
16017
|
+
}
|
|
15210
16018
|
if (this.options.onRestored !== void 0 && [...actions.keys()].some((id) => RELOADABLE.test(id))) {
|
|
15211
16019
|
plan.reloaded = true;
|
|
15212
16020
|
this.options.onRestored();
|
|
@@ -15480,8 +16288,20 @@ var init_backups = __esmMin((() => {
|
|
|
15480
16288
|
this.running = true;
|
|
15481
16289
|
this.lastAttemptAt = now;
|
|
15482
16290
|
this.create({ automatic: true }).then((result) => {
|
|
15483
|
-
if (
|
|
16291
|
+
if (result.ok) {
|
|
16292
|
+
this.scheduleError = null;
|
|
16293
|
+
return;
|
|
16294
|
+
}
|
|
16295
|
+
this.scheduleError = {
|
|
16296
|
+
message: result.error ?? "the scheduled backup failed",
|
|
16297
|
+
at: Date.now()
|
|
16298
|
+
};
|
|
16299
|
+
logger.warn("the scheduled backup failed", result.error);
|
|
15484
16300
|
}).catch((error) => {
|
|
16301
|
+
this.scheduleError = {
|
|
16302
|
+
message: errorMessage(error),
|
|
16303
|
+
at: Date.now()
|
|
16304
|
+
};
|
|
15485
16305
|
logger.error("the scheduled backup failed", error);
|
|
15486
16306
|
}).finally(() => {
|
|
15487
16307
|
this.running = false;
|
|
@@ -16743,6 +17563,14 @@ var init_notifications = __esmMin((() => {
|
|
|
16743
17563
|
"crash": "gave up restarting",
|
|
16744
17564
|
"unhealthy": "health check failing",
|
|
16745
17565
|
"forced-restart": "force restarted",
|
|
17566
|
+
/**
|
|
17567
|
+
* The other half of `forced-restart`: the entry came back and is serving.
|
|
17568
|
+
*
|
|
17569
|
+
* Without it a force restart was announced and then never closed, so a reader could not
|
|
17570
|
+
* tell "it restarted and is fine now" from "it restarted and is still broken" — the two
|
|
17571
|
+
* cases looked identical until the next crash.
|
|
17572
|
+
*/
|
|
17573
|
+
"restart-ok": "restarted and healthy again",
|
|
16746
17574
|
"recovered": "recovered",
|
|
16747
17575
|
"rss": "exceeded its memory limit",
|
|
16748
17576
|
"host": "host thresholds breached",
|
|
@@ -16754,6 +17582,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16754
17582
|
"crash": "🔴 server down",
|
|
16755
17583
|
"unhealthy": "🟠 server unhealthy",
|
|
16756
17584
|
"forced-restart": "🔁 server force restarted",
|
|
17585
|
+
"restart-ok": "🟢 server back up",
|
|
16757
17586
|
"recovered": "🟢 server recovered",
|
|
16758
17587
|
"rss": "🔴 server over its memory limit",
|
|
16759
17588
|
"host": "🟠 host warning",
|
|
@@ -16766,6 +17595,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16766
17595
|
"rss": (policy) => policy.onCrash,
|
|
16767
17596
|
"unhealthy": (policy) => policy.onUnhealthy,
|
|
16768
17597
|
"forced-restart": (policy) => policy.onForcedRestart,
|
|
17598
|
+
"restart-ok": (policy) => policy.onForcedRestart,
|
|
16769
17599
|
"recovered": (policy) => policy.onRecovered,
|
|
16770
17600
|
"host": (policy) => policy.onHost,
|
|
16771
17601
|
"host-recovered": (policy) => policy.onHost,
|
|
@@ -17191,7 +18021,12 @@ var init_panel = __esmMin((() => {
|
|
|
17191
18021
|
globalSettingsPath: this.options.settings.path,
|
|
17192
18022
|
globalSecretsPath: this.options.secrets.path,
|
|
17193
18023
|
tlsDir: this.options.tls.directory,
|
|
18024
|
+
registryPath: this.options.registry.path,
|
|
17194
18025
|
includePaths: this.options.settings.backups.includePaths,
|
|
18026
|
+
runningServers: () => this.workspaces().flatMap((runtime) => runtime.supervisor.views().filter((view) => view.status === "running").map((view) => ({
|
|
18027
|
+
workspaceId: runtime.id,
|
|
18028
|
+
serverId: view.id
|
|
18029
|
+
}))),
|
|
17195
18030
|
workspaces: this.workspaces().map((runtime) => ({
|
|
17196
18031
|
id: runtime.id,
|
|
17197
18032
|
label: runtime.label,
|
|
@@ -17210,6 +18045,22 @@ var init_panel = __esmMin((() => {
|
|
|
17210
18045
|
this.scheduleState();
|
|
17211
18046
|
return runtime.view();
|
|
17212
18047
|
}
|
|
18048
|
+
/**
|
|
18049
|
+
* Registers a workspace an archive brought but this host did not have, then builds
|
|
18050
|
+
* its runtime so the files a restore is about to write have an owner.
|
|
18051
|
+
*
|
|
18052
|
+
* Idempotent, and it never touches an existing workspace: a restore must fill one
|
|
18053
|
+
* that is already here, not replace its label or its runtime.
|
|
18054
|
+
*/
|
|
18055
|
+
ensureWorkspace(input) {
|
|
18056
|
+
if (this.options.registry.has(input.id)) return;
|
|
18057
|
+
const workspace = this.options.registry.create(input);
|
|
18058
|
+
const runtime = this.createRuntime(workspace);
|
|
18059
|
+
this.runtimes.set(workspace.id, runtime);
|
|
18060
|
+
logger.info(`workspace "${workspace.id}" restored from an archive`);
|
|
18061
|
+
this.startRestored(runtime, /* @__PURE__ */ new Set());
|
|
18062
|
+
this.scheduleState();
|
|
18063
|
+
}
|
|
17213
18064
|
rename(id, label) {
|
|
17214
18065
|
const workspace = this.options.registry.rename(id, label);
|
|
17215
18066
|
const runtime = this.runtimes.get(id);
|
|
@@ -17249,16 +18100,35 @@ var init_panel = __esmMin((() => {
|
|
|
17249
18100
|
this.scheduleState();
|
|
17250
18101
|
return entry;
|
|
17251
18102
|
}
|
|
17252
|
-
/**
|
|
18103
|
+
/**
|
|
18104
|
+
* Re-reads every workspace and the global settings, e.g. after a restore.
|
|
18105
|
+
*
|
|
18106
|
+
* `store.load()` resets the byte baseline the config watcher compares against, so the
|
|
18107
|
+
* poll that follows sees "no change" and never reaches its autostart pass. The entries
|
|
18108
|
+
* an archive brought therefore waited for a panel restart — which is why the start of
|
|
18109
|
+
* newly appeared autostart entries belongs here, the one place that knows what was new.
|
|
18110
|
+
*/
|
|
17253
18111
|
reloadAll() {
|
|
17254
18112
|
this.options.settings.load();
|
|
17255
18113
|
for (const runtime of this.workspaces()) {
|
|
18114
|
+
const before = new Set(runtime.store.servers.map((server) => server.id));
|
|
17256
18115
|
runtime.store.load();
|
|
17257
18116
|
runtime.history.load();
|
|
17258
18117
|
this.reportWorkspaceErrors(runtime.id);
|
|
18118
|
+
this.startRestored(runtime, before);
|
|
17259
18119
|
}
|
|
17260
18120
|
this.scheduleState();
|
|
17261
18121
|
}
|
|
18122
|
+
/** Starts the autostart entries a reload just revealed, exactly as a hand edit would. */
|
|
18123
|
+
startRestored(runtime, before) {
|
|
18124
|
+
if (!this.options.autostart) return;
|
|
18125
|
+
for (const server of runtime.store.servers) {
|
|
18126
|
+
if (before.has(server.id) || !server.enabled || !server.autostart) continue;
|
|
18127
|
+
runtime.supervisor.start(server.id, { actor: "boot" }).catch((error) => {
|
|
18128
|
+
logger.error(`could not start the restored server ${server.id}`, error);
|
|
18129
|
+
});
|
|
18130
|
+
}
|
|
18131
|
+
}
|
|
17262
18132
|
/** Starts whatever the config marks autostart, across every workspace. */
|
|
17263
18133
|
async startAll(workspaces = this.workspaces().map((runtime) => runtime.id)) {
|
|
17264
18134
|
for (const id of workspaces) {
|
|
@@ -18306,6 +19176,7 @@ async function runControlPlane(options) {
|
|
|
18306
19176
|
dataRoot: hhDir,
|
|
18307
19177
|
getConfig: () => settings.backups,
|
|
18308
19178
|
getSources: () => panel.backupSources(),
|
|
19179
|
+
ensureWorkspace: (input) => panel?.ensureWorkspace(input),
|
|
18309
19180
|
onRestored: () => panel?.reloadAll()
|
|
18310
19181
|
});
|
|
18311
19182
|
panel = new PanelService({
|
|
@@ -18531,7 +19402,7 @@ async function runUp(flags, entry) {
|
|
|
18531
19402
|
process.stdout.write(`${green("already running")} home-hosted ${existing.version} (pid ${existing.pid}) at ${existing.url}\n`);
|
|
18532
19403
|
const note = versionMismatchNote(existing.version);
|
|
18533
19404
|
if (note !== null) process.stdout.write(`${dim(note)}\n`);
|
|
18534
|
-
process.stdout.write(`${dim(
|
|
19405
|
+
process.stdout.write(`${dim(`stop it with \`${invocation()} down\``)}\n`);
|
|
18535
19406
|
return;
|
|
18536
19407
|
}
|
|
18537
19408
|
if (existing !== null && await runtimeIsGone(existing)) clearRuntime();
|
|
@@ -18767,7 +19638,7 @@ async function runServerAction(action, id, workspace) {
|
|
|
18767
19638
|
const runtime = readRuntime();
|
|
18768
19639
|
if (runtime === null || !await runtimeIsAlive(runtime)) {
|
|
18769
19640
|
if (runtime !== null && await runtimeIsGone(runtime)) clearRuntime();
|
|
18770
|
-
fail(
|
|
19641
|
+
fail(`home-hosted is not running — start it with \`${invocation()} up\``);
|
|
18771
19642
|
}
|
|
18772
19643
|
const query = workspace === void 0 || workspace.length === 0 ? "" : `?workspace=${encodeURIComponent(workspace)}`;
|
|
18773
19644
|
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}/${action}${query}`);
|
|
@@ -18799,7 +19670,7 @@ function serverCommand(action) {
|
|
|
18799
19670
|
},
|
|
18800
19671
|
run: async ({ args }) => {
|
|
18801
19672
|
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
18802
|
-
if (id.length === 0) fail(`${action} needs a server id — see
|
|
19673
|
+
if (id.length === 0) fail(`${action} needs a server id — see \`${invocation()} status\` or the workspace's servers.config.json`);
|
|
18803
19674
|
await runServerAction(action, id, typeof args.workspace === "string" ? args.workspace.trim() : void 0);
|
|
18804
19675
|
}
|
|
18805
19676
|
});
|
|
@@ -18873,8 +19744,8 @@ async function runStatus(json) {
|
|
|
18873
19744
|
running: false,
|
|
18874
19745
|
initialised
|
|
18875
19746
|
}, null, 2)}\n`);
|
|
18876
|
-
else if (initialised) process.stdout.write(
|
|
18877
|
-
else process.stdout.write(
|
|
19747
|
+
else if (initialised) process.stdout.write(`home-hosted is not running — start it with \`${invocation()} up\`\n`);
|
|
19748
|
+
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`);
|
|
18878
19749
|
process.exitCode = 1;
|
|
18879
19750
|
return;
|
|
18880
19751
|
}
|
|
@@ -18919,7 +19790,7 @@ async function runStatus(json) {
|
|
|
18919
19790
|
const dir = path.join(workspaceDir(DEFAULT_WORKSPACE_ID), ".logs");
|
|
18920
19791
|
return fs.existsSync(dir) ? `${dir} (one file per server: <id>.log)` : dir;
|
|
18921
19792
|
})()],
|
|
18922
|
-
["ui", ui.custom ? `custom — ${uiLabel} (revert with
|
|
19793
|
+
["ui", ui.custom ? `custom — ${uiLabel} (revert with \`${invocation()} ui-revert\`)` : "stock"]
|
|
18923
19794
|
];
|
|
18924
19795
|
process.stdout.write(`${bold(`home-hosted ${runtime.version}`)}\n`);
|
|
18925
19796
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
@@ -19104,7 +19975,7 @@ async function runSetPassword(clear) {
|
|
|
19104
19975
|
store.setPassword(password);
|
|
19105
19976
|
process.stdout.write(`${green("password stored")} in ${globalSecretsPath} (mode 0600)\n`);
|
|
19106
19977
|
if (password.length < 8) process.stdout.write(`${dim(`"${password}" is short — easy to guess if the panel is reachable beyond loopback`)}\n`);
|
|
19107
|
-
process.stdout.write(`${dim("
|
|
19978
|
+
process.stdout.write(`${dim("a running panel picks it up immediately, and every existing browser session is signed out")}\n`);
|
|
19108
19979
|
}
|
|
19109
19980
|
var setPasswordArgs, setPasswordCommand;
|
|
19110
19981
|
var init_set_password = __esmMin((() => {
|
|
@@ -20218,7 +21089,7 @@ var SUMMARIES = {
|
|
|
20218
21089
|
"ui-revert": "go back to the stock control panel UI"
|
|
20219
21090
|
};
|
|
20220
21091
|
/** Every section lays its left column out at this width, so the two views align. */
|
|
20221
|
-
var OPTION_WIDTH =
|
|
21092
|
+
var OPTION_WIDTH = 21;
|
|
20222
21093
|
var UP_SECTION = {
|
|
20223
21094
|
heading: "Options for up/restart",
|
|
20224
21095
|
lines: [
|
|
@@ -20245,7 +21116,7 @@ var LOGS_SECTION = {
|
|
|
20245
21116
|
};
|
|
20246
21117
|
var SERVER_SECTION = {
|
|
20247
21118
|
heading: "Arguments for start/stop",
|
|
20248
|
-
lines: [["<id>", "the server id from servers.config.json"]]
|
|
21119
|
+
lines: [["<id>", "the server id from servers.config.json"], ["-w, --workspace <id>", "the workspace to act in (default: the default workspace)"]]
|
|
20249
21120
|
};
|
|
20250
21121
|
var RESTART_SECTION = {
|
|
20251
21122
|
heading: "Options for restart",
|
|
@@ -20265,7 +21136,11 @@ var SET_TOKEN_SECTION = {
|
|
|
20265
21136
|
};
|
|
20266
21137
|
var MIGRATE_SECTION = {
|
|
20267
21138
|
heading: "Options for migrate",
|
|
20268
|
-
lines: [
|
|
21139
|
+
lines: [
|
|
21140
|
+
["-c, --config <file>", "one config file to migrate (default: every file this state root owns)"],
|
|
21141
|
+
["--dry-run", "print what would change, write nothing"],
|
|
21142
|
+
["-y, --yes", "apply without asking (or set HHOSTED_MIGRATE=allow)"]
|
|
21143
|
+
]
|
|
20269
21144
|
};
|
|
20270
21145
|
var INIT_SECTION = {
|
|
20271
21146
|
heading: "Options for init",
|