home-hosted 0.9.3 → 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 +1016 -150
- 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-DVmJrO-t.js → index-JBfH8bkX.js} +10 -8
- package/uis/stock/dist/assets/ja-CTGEGJ4n.js +1 -0
- package/uis/stock/dist/assets/ko-BSVsEsYY.js +1 -0
- package/uis/stock/dist/assets/ru-DvSoJlxX.js +1 -0
- package/uis/stock/dist/assets/vi-BTIQb_8V.js +1 -0
- package/uis/stock/dist/assets/zh-CN-D2-g9feN.js +1 -0
- package/uis/stock/dist/index.html +2 -2
- package/uis/stock/dist/ui.json +3 -3
- package/uis/stock/dist/assets/de-BVk31frd.js +0 -1
- package/uis/stock/dist/assets/es-BLevhZGM.js +0 -1
- package/uis/stock/dist/assets/fr-S3YXRHdG.js +0 -1
- package/uis/stock/dist/assets/index-GxTN2fYn.css +0 -2
- package/uis/stock/dist/assets/ja-BOB-E8_K.js +0 -1
- package/uis/stock/dist/assets/ko-Dc88YLt7.js +0 -1
- package/uis/stock/dist/assets/ru-BBxCT8MK.js +0 -1
- package/uis/stock/dist/assets/vi-CxubJ_Mw.js +0 -1
- package/uis/stock/dist/assets/zh-CN-BIvisZnl.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -278,6 +278,21 @@ var init_args = __esmMin((() => {
|
|
|
278
278
|
}));
|
|
279
279
|
//#endregion
|
|
280
280
|
//#region src/cli/io.ts
|
|
281
|
+
/**
|
|
282
|
+
* How this process was invoked, so a hint names a command the person can actually run.
|
|
283
|
+
*
|
|
284
|
+
* `npx home-hosted` leaves no `home-hosted` on `PATH`, so a hard-coded "run `home-hosted down`"
|
|
285
|
+
* fails with `command not found`. A package-manager cache path means npx/dlx; `cli.ts` means a
|
|
286
|
+
* source checkout. A string to print, not a parser. `HHOSTED_INVOCATION` overrides it.
|
|
287
|
+
*/
|
|
288
|
+
function invocation() {
|
|
289
|
+
const override = process.env.HHOSTED_INVOCATION?.trim();
|
|
290
|
+
if (override !== void 0 && override.length > 0) return override;
|
|
291
|
+
const entry = process.argv[1] ?? "";
|
|
292
|
+
if (/[\\/](?:_npx|dlx)[\\/]/.test(entry)) return "npx home-hosted";
|
|
293
|
+
if (/[\\/]cli\.ts$/.test(entry)) return "pnpm exec tsx src/cli.ts";
|
|
294
|
+
return "home-hosted";
|
|
295
|
+
}
|
|
281
296
|
/** One shape for every failure: a red `error <message>` on stderr and exit 1. */
|
|
282
297
|
function fail(message) {
|
|
283
298
|
process.stderr.write(`${paint("31", "error")} ${message}\n`);
|
|
@@ -724,7 +739,7 @@ function duplicateWebhookIds(targets) {
|
|
|
724
739
|
}
|
|
725
740
|
return [...duplicates];
|
|
726
741
|
}
|
|
727
|
-
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, backupFileSchema, backupEntrySchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, workspaceViewSchema, appStateSchema, logQuerySchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
742
|
+
var bindSchema, workspaceIdSchema, workspaceSchema, workspaceCreateSchema, workspaceRenameSchema, portSchema, onPortConflictSchema, onPortConflictDefaultSchema, restartSchema, httpCheckSchema, resourcesSchema, healthSchema, stopSchema, bootstrapSchema, bootstrapOrNullSchema, labelOrNullSchema, logBufferLinesSchema, serverSchema, authSchema, notificationPolicyShape, notificationDefaultsSchema, notificationDefaultsViewSchema, useOwnSettingsSchema, telegramDestinationSchema, webhookTargetSchema, notificationTargetSchema, destinationListSchema, notificationsSchema, logsSchema, tlsSchema, hostSchema, ddnsRecordTypeSchema, ddnsAccountSchema, ddnsDomainSchema, ddnsIpv4Schema, ddnsIpv6Schema, ddnsConfigSchema, ddnsRecordStateSchema, ddnsRecordViewSchema, ddnsStatusSchema, ddnsProviderFieldSchema, ddnsProviderInfoSchema, ddnsViewSchema, ddnsCredentialsSchema, backupScheduleSchema, backupsSchema, controlSchema, defaultsSchema, restartPatchSchema, httpCheckPatchSchema, resourcesPatchSchema, healthPatchSchema, stopPatchSchema, authPatchSchema, notificationPolicyPatchShape, destinationPatchSchema, notificationsPatchSchema, hostPatchSchema, backupSchedulePatchSchema, backupsPatchSchema, logsPatchSchema, tlsPatchSchema, controlPatchSchema, defaultsPatchSchema, editableFields, serverPatchSchema, serverCreateSchema, nannySpecSchema, nannyExitSchema, nannyStateSchema, entryStateSchema, settingsPatchSchema, workspaceSettingsPatchSchema, authStatusSchema, tlsStatusSchema, proxyEngineSchema, proxyTargetSchema, proxyTlsModeSchema, proxyRouteSchema, proxyCertificateSchema, proxyCertificateStateSchema, proxyDns01Schema, proxyConfigSchema, proxyEngineSourceSchema, proxyEngineStatusSchema, proxyEngineInfoSchema, proxyRouteStatusSchema, proxyRouteViewSchema, proxyRunStateSchema, proxyStatusSchema, proxyCertificateViewSchema, proxyDnsAccountViewSchema, proxyViewSchema, proxyRoutePatchSchema, proxyPatchSchema, proxyCertificateUploadSchema, proxyEngineInstallSchema, notificationPolicyStatusShape, destinationStatusSchema, telegramChatsSchema, notificationViewSchema, sessionViewSchema, loginSchema, passwordValueSchema, passwordSchema, serverStatusSchema, healthStateSchema, portStateSchema, logStreamSchema, logLineSchema, historyActorSchema, historyEventSchema, serverHistorySchema, processResourcesSchema, hostDiskSchema, hostViewSchema, backupFileSchema, backupEntrySchema, backupsViewSchema, restoreItemSchema, restoreSkipSchema, restorePlanSchema, backupCreateSchema, restoreRequestSchema, serverViewSchema, healthResponseSchema, controlViewSchema, uiMetaSchema, uiStatusSchema, serverOrphanSchema, workspaceViewSchema, appStateSchema, logQuerySchema, actionResultSchema, deliveryResultSchema, passwordSetResponseSchema, tlsReviewResponseSchema, okResponseSchema, backupFilesResponseSchema, uiInstallResponseSchema, backupCreatedResponseSchema, logLinesResponseSchema, freePortResultSchema, logHistoryQuerySchema, logFileInfoSchema, logServerViewSchema, logServersViewSchema, notificationActionSchema, destinationIdParamSchema, destinationTestSchema, telegramTokenSchema, apiErrorSchema, tlsUploadSchema, settingsViewSchema, settingsSavedSchema, workspaceSettingsViewSchema, workspaceSettingsSavedSchema;
|
|
728
743
|
var init_contracts = __esmMin((() => {
|
|
729
744
|
bindSchema = type("\"local\" | \"lan\" | /^\\d{1,3}(?:\\.\\d{1,3}){3}$/");
|
|
730
745
|
workspaceIdSchema = type("/^[a-z0-9][a-z0-9_-]*$/");
|
|
@@ -1252,6 +1267,15 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1252
1267
|
entryStateSchema = type({
|
|
1253
1268
|
/** Attempts spent on the current crash sequence; reset once the process stays up. */
|
|
1254
1269
|
"restarts": "number.integer >= 0",
|
|
1270
|
+
/**
|
|
1271
|
+
* Force restarts spent on the current unhealthy sequence.
|
|
1272
|
+
*
|
|
1273
|
+
* Separate from `restarts` because the two are different failures — a process that keeps dying
|
|
1274
|
+
* and a process that stays up but cannot serve. Persisted for the same reason the crash counter
|
|
1275
|
+
* is: a budget that lives only in memory is handed back fresh by every panel restart, so a
|
|
1276
|
+
* health-storm that is restarted often enough never exhausts it.
|
|
1277
|
+
*/
|
|
1278
|
+
"healthRestarts?": "number.integer >= 0",
|
|
1255
1279
|
/** The `runOnce` bootstrap already ran for this entry. */
|
|
1256
1280
|
"bootstrapDone": "boolean",
|
|
1257
1281
|
/**
|
|
@@ -1652,6 +1676,17 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1652
1676
|
"schedule?": backupScheduleSchema,
|
|
1653
1677
|
/** When the last automatic archive was written; null until one has run. Optional for the same reason. */
|
|
1654
1678
|
"lastAutomaticAt?": "number | null",
|
|
1679
|
+
/**
|
|
1680
|
+
* Why the last scheduled pass failed, and when it tried.
|
|
1681
|
+
*
|
|
1682
|
+
* A failed pass wrote only a panel-console warning, so "enabled, zero archives" looked the same
|
|
1683
|
+
* as "failing every interval since the day it was enabled" — indistinguishable from the page,
|
|
1684
|
+
* which is the only place a person looks. Null once a pass succeeds.
|
|
1685
|
+
*/
|
|
1686
|
+
"scheduleError?": type({
|
|
1687
|
+
message: "string",
|
|
1688
|
+
at: "number"
|
|
1689
|
+
}),
|
|
1655
1690
|
/** Extra paths from the global config, in addition to each server's own. */
|
|
1656
1691
|
"includePaths": type("string[]"),
|
|
1657
1692
|
/** Every selectable entry, global first, then each workspace. */
|
|
@@ -1708,6 +1743,27 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1708
1743
|
"restartRequired": "boolean",
|
|
1709
1744
|
/** The panel re-read the restored config within this same restore. */
|
|
1710
1745
|
"reloaded": "boolean",
|
|
1746
|
+
/**
|
|
1747
|
+
* Servers that are **running now** and whose declared data path this restore overwrote.
|
|
1748
|
+
*
|
|
1749
|
+
* A data path is copied over while its owner keeps running, holding open handles to files
|
|
1750
|
+
* that were just replaced — the process keeps its old view and the archive's copy wins on
|
|
1751
|
+
* disk, so anything written since the archive was taken is gone. The plan has to say which
|
|
1752
|
+
* entries that happened to, because nothing else in the result mentions them.
|
|
1753
|
+
*
|
|
1754
|
+
* Optional: an older panel does not send it, and a plan that touched no running entry sends none.
|
|
1755
|
+
*/
|
|
1756
|
+
"replacedUnderRunning?": type({
|
|
1757
|
+
workspaceId: "string",
|
|
1758
|
+
serverId: "string",
|
|
1759
|
+
path: "string"
|
|
1760
|
+
}).array(),
|
|
1761
|
+
/**
|
|
1762
|
+
* Workspaces this restore created because the archive named them and the host did not
|
|
1763
|
+
* have them. Optional: an older panel never sends the row, and an archive written
|
|
1764
|
+
* before the registry was captured creates none.
|
|
1765
|
+
*/
|
|
1766
|
+
"createdWorkspaces?": type("string[]"),
|
|
1711
1767
|
"error": "string?"
|
|
1712
1768
|
});
|
|
1713
1769
|
backupCreateSchema = type({
|
|
@@ -1735,6 +1791,14 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1735
1791
|
"pid": "number | null",
|
|
1736
1792
|
/** True when the process serving this entry was adopted, not spawned by the panel. */
|
|
1737
1793
|
"adopted": "boolean?",
|
|
1794
|
+
/**
|
|
1795
|
+
* The panel stopped this entry because it could not serve, rather than someone asking.
|
|
1796
|
+
*
|
|
1797
|
+
* Optional, like every new field: an older panel does not send it. `/healthz` needs it because
|
|
1798
|
+
* the status alone cannot tell "the operator switched this off" (never a problem) from "the
|
|
1799
|
+
* panel gave up on it" (a broken service) — both are `stopped`.
|
|
1800
|
+
*/
|
|
1801
|
+
"stoppedByPanel?": "boolean",
|
|
1738
1802
|
"startedAt": "number | null",
|
|
1739
1803
|
"exitCode": "number | null",
|
|
1740
1804
|
"exitSignal": "string | null",
|
|
@@ -1799,6 +1863,13 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1799
1863
|
dir: "string",
|
|
1800
1864
|
meta: uiMetaSchema.or(type("null"))
|
|
1801
1865
|
});
|
|
1866
|
+
serverOrphanSchema = type({
|
|
1867
|
+
/** The id it was started as, which is also the key of the state file it was found in. */
|
|
1868
|
+
serverId: "string",
|
|
1869
|
+
pid: "number",
|
|
1870
|
+
/** When the panel spawned it; null when the record predates the stamp. */
|
|
1871
|
+
startedAt: "number | null"
|
|
1872
|
+
});
|
|
1802
1873
|
workspaceViewSchema = type({
|
|
1803
1874
|
"id": "string",
|
|
1804
1875
|
"label": "string",
|
|
@@ -1817,6 +1888,18 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1817
1888
|
"serverCount": "number",
|
|
1818
1889
|
"runningCount": "number",
|
|
1819
1890
|
"crashedCount": "number",
|
|
1891
|
+
/**
|
|
1892
|
+
* Processes this panel started that no current entry owns.
|
|
1893
|
+
*
|
|
1894
|
+
* A detached child outlives a hard panel death, and its handle is the entry-state file keyed by
|
|
1895
|
+
* the *id* it was started under. Rename the entry and nothing ever reads that file again; delete
|
|
1896
|
+
* the entry while the panel is down and the file is reclaimed, destroying the last handle. The
|
|
1897
|
+
* orphan then runs with no card, no `/healthz` line and no CLI action — for a queue consumer,
|
|
1898
|
+
* two consumers of the same queue. This is the view that makes it actionable.
|
|
1899
|
+
*
|
|
1900
|
+
* Optional: an older panel never sends it.
|
|
1901
|
+
*/
|
|
1902
|
+
"orphans?": serverOrphanSchema.array(),
|
|
1820
1903
|
"servers": serverViewSchema.array()
|
|
1821
1904
|
});
|
|
1822
1905
|
appStateSchema = type({
|
|
@@ -1844,6 +1927,51 @@ maxRssBytes: "number.integer >= 0 = 0" }).onUndeclaredKey("reject");
|
|
|
1844
1927
|
"lines": logLineSchema.array().optional()
|
|
1845
1928
|
});
|
|
1846
1929
|
logQuerySchema = type({ limit: "string?" });
|
|
1930
|
+
actionResultSchema = type({
|
|
1931
|
+
"ok": "boolean",
|
|
1932
|
+
"error?": "string",
|
|
1933
|
+
"code?": "string"
|
|
1934
|
+
});
|
|
1935
|
+
deliveryResultSchema = type({
|
|
1936
|
+
"ok": "boolean",
|
|
1937
|
+
"error?": "string"
|
|
1938
|
+
});
|
|
1939
|
+
passwordSetResponseSchema = type({
|
|
1940
|
+
ok: "boolean",
|
|
1941
|
+
enabled: "boolean",
|
|
1942
|
+
sessionsInvalidated: "boolean"
|
|
1943
|
+
});
|
|
1944
|
+
tlsReviewResponseSchema = type({
|
|
1945
|
+
control: controlViewSchema,
|
|
1946
|
+
rebinding: "boolean",
|
|
1947
|
+
targetUrl: "string"
|
|
1948
|
+
});
|
|
1949
|
+
okResponseSchema = type({ ok: "boolean" });
|
|
1950
|
+
backupFilesResponseSchema = type({
|
|
1951
|
+
ok: "boolean",
|
|
1952
|
+
files: backupFileSchema.array()
|
|
1953
|
+
});
|
|
1954
|
+
uiInstallResponseSchema = type({
|
|
1955
|
+
"ok": "boolean",
|
|
1956
|
+
"meta?": uiStatusSchema.get("meta"),
|
|
1957
|
+
"ui": uiStatusSchema,
|
|
1958
|
+
/** Revert only: whether there was a custom UI to remove. */
|
|
1959
|
+
"removed?": "boolean"
|
|
1960
|
+
});
|
|
1961
|
+
backupCreatedResponseSchema = type({
|
|
1962
|
+
file: backupFileSchema,
|
|
1963
|
+
files: backupFileSchema.array()
|
|
1964
|
+
});
|
|
1965
|
+
logLinesResponseSchema = type({
|
|
1966
|
+
serverId: "string",
|
|
1967
|
+
enabled: "boolean",
|
|
1968
|
+
sizeBytes: "number",
|
|
1969
|
+
/** The rotated files this entry has, newest first. */
|
|
1970
|
+
files: "string[]",
|
|
1971
|
+
/** The whole search window, or null when the request carried no `search`. */
|
|
1972
|
+
searched: logLineSchema.array().or(type("null")),
|
|
1973
|
+
lines: logLineSchema.array()
|
|
1974
|
+
});
|
|
1847
1975
|
freePortResultSchema = type({
|
|
1848
1976
|
ok: "boolean",
|
|
1849
1977
|
port: "number | null",
|
|
@@ -2634,6 +2762,10 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2634
2762
|
if (!token) return null;
|
|
2635
2763
|
const session = this.sessions.get(token);
|
|
2636
2764
|
if (!session) return null;
|
|
2765
|
+
if (session.passwordRevision !== this.secrets.passwordUpdatedAt) {
|
|
2766
|
+
this.sessions.delete(token);
|
|
2767
|
+
return null;
|
|
2768
|
+
}
|
|
2637
2769
|
const now = Date.now();
|
|
2638
2770
|
if (session.expiresAt <= now) {
|
|
2639
2771
|
this.sessions.delete(token);
|
|
@@ -2699,6 +2831,7 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2699
2831
|
const token = crypto.randomBytes(32).toString("base64url");
|
|
2700
2832
|
this.sessions.set(token, {
|
|
2701
2833
|
token,
|
|
2834
|
+
passwordRevision: this.secrets.passwordUpdatedAt,
|
|
2702
2835
|
expiresAt: now + config.sessionTtlMs,
|
|
2703
2836
|
lastSeenAt: now,
|
|
2704
2837
|
ip
|
|
@@ -2723,7 +2856,10 @@ var init_auth$1 = __esmMin((() => {
|
|
|
2723
2856
|
*/
|
|
2724
2857
|
setPassword(password, options = {}) {
|
|
2725
2858
|
this.secrets.setPassword(password, options);
|
|
2726
|
-
|
|
2859
|
+
const keep = options.keepToken ?? null;
|
|
2860
|
+
this.logoutOthers(keep);
|
|
2861
|
+
const session = keep === null ? void 0 : this.sessions.get(keep);
|
|
2862
|
+
if (session !== void 0) session.passwordRevision = this.secrets.passwordUpdatedAt;
|
|
2727
2863
|
}
|
|
2728
2864
|
/** Drops every session except one, which is how a password change stays signed in. */
|
|
2729
2865
|
logoutOthers(keep) {
|
|
@@ -2982,7 +3118,10 @@ function createAuthRoute(deps) {
|
|
|
2982
3118
|
}).post("/auth/logout", describeRoute({
|
|
2983
3119
|
tags: ["auth"],
|
|
2984
3120
|
summary: "Drop the session cookie",
|
|
2985
|
-
responses: { 200: {
|
|
3121
|
+
responses: { 200: {
|
|
3122
|
+
description: "Signed out",
|
|
3123
|
+
content: jsonBody(okResponseSchema)
|
|
3124
|
+
} }
|
|
2986
3125
|
}), (c) => {
|
|
2987
3126
|
deps.auth.logout(deps.auth.tokenFromCookie(c.req.header("cookie")));
|
|
2988
3127
|
c.header("Set-Cookie", serializeCookie(SESSION_COOKIE, "", {
|
|
@@ -2996,7 +3135,10 @@ function createAuthRoute(deps) {
|
|
|
2996
3135
|
tags: ["auth"],
|
|
2997
3136
|
summary: "Set, change or enable the panel password",
|
|
2998
3137
|
responses: {
|
|
2999
|
-
200: {
|
|
3138
|
+
200: {
|
|
3139
|
+
description: "Updated",
|
|
3140
|
+
content: jsonBody(passwordSetResponseSchema)
|
|
3141
|
+
},
|
|
3000
3142
|
400: ERROR_RESPONSES[400],
|
|
3001
3143
|
401: ERROR_RESPONSES[401]
|
|
3002
3144
|
}
|
|
@@ -3034,7 +3176,10 @@ function createAuthRoute(deps) {
|
|
|
3034
3176
|
tags: ["auth"],
|
|
3035
3177
|
summary: "Clear the password and turn authentication off",
|
|
3036
3178
|
responses: {
|
|
3037
|
-
200: {
|
|
3179
|
+
200: {
|
|
3180
|
+
description: "Cleared",
|
|
3181
|
+
content: jsonBody(okResponseSchema)
|
|
3182
|
+
},
|
|
3038
3183
|
400: ERROR_RESPONSES[400],
|
|
3039
3184
|
401: ERROR_RESPONSES[401]
|
|
3040
3185
|
}
|
|
@@ -3295,6 +3440,7 @@ function buildWorkspaceView(source) {
|
|
|
3295
3440
|
serverCount: servers.length,
|
|
3296
3441
|
runningCount: servers.filter((server) => server.status === "running").length,
|
|
3297
3442
|
crashedCount: servers.filter((server) => server.status === "crashed").length,
|
|
3443
|
+
orphans: source.supervisor.orphans?.() ?? [],
|
|
3298
3444
|
servers
|
|
3299
3445
|
};
|
|
3300
3446
|
}
|
|
@@ -3323,7 +3469,10 @@ function createBackupsRoute(deps) {
|
|
|
3323
3469
|
tags: ["backups"],
|
|
3324
3470
|
summary: "Create a backup (optionally password-protected)",
|
|
3325
3471
|
responses: {
|
|
3326
|
-
200: {
|
|
3472
|
+
200: {
|
|
3473
|
+
description: "Created",
|
|
3474
|
+
content: jsonBody(backupCreatedResponseSchema)
|
|
3475
|
+
},
|
|
3327
3476
|
400: ERROR_RESPONSES[400]
|
|
3328
3477
|
}
|
|
3329
3478
|
}), validate("json", backupCreateSchema), async (c) => {
|
|
@@ -3360,7 +3509,10 @@ function createBackupsRoute(deps) {
|
|
|
3360
3509
|
tags: ["backups"],
|
|
3361
3510
|
summary: "Delete one archive",
|
|
3362
3511
|
responses: {
|
|
3363
|
-
200: {
|
|
3512
|
+
200: {
|
|
3513
|
+
description: "Removed",
|
|
3514
|
+
content: jsonBody(backupFilesResponseSchema)
|
|
3515
|
+
},
|
|
3364
3516
|
404: ERROR_RESPONSES[404]
|
|
3365
3517
|
}
|
|
3366
3518
|
}), validate("param", nameParam), (c) => {
|
|
@@ -3518,6 +3670,27 @@ function unknownServerError(id) {
|
|
|
3518
3670
|
code: "UNKNOWN_SERVER"
|
|
3519
3671
|
});
|
|
3520
3672
|
}
|
|
3673
|
+
/**
|
|
3674
|
+
* The stable code for a failed action, so a script branches on it rather than on English.
|
|
3675
|
+
*
|
|
3676
|
+
* Two values, not one per message: a missing id is what the caller must fix, and everything else
|
|
3677
|
+
* ("disabled", "stopping", "port in use") is the entry refusing right now. `code` is added beside
|
|
3678
|
+
* `ok`/`error` rather than replacing them, because an older UI reads those.
|
|
3679
|
+
*/
|
|
3680
|
+
function actionCode(result) {
|
|
3681
|
+
return result[UNKNOWN_SERVER] === true ? "UNKNOWN_SERVER" : "ACTION_FAILED";
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* What a lifecycle route puts on the wire: the result it already had, plus its code.
|
|
3685
|
+
*
|
|
3686
|
+
* A success carries no code — a code names a failure.
|
|
3687
|
+
*/
|
|
3688
|
+
function actionAnswer(result) {
|
|
3689
|
+
return result.ok ? { ...result } : {
|
|
3690
|
+
...result,
|
|
3691
|
+
code: actionCode(result)
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3521
3694
|
/** Unknown ids are 404; a server that exists but cannot act is a 409. */
|
|
3522
3695
|
function statusForAction(result) {
|
|
3523
3696
|
if (result.ok) return 200;
|
|
@@ -3829,7 +4002,10 @@ function createControlRoute(deps) {
|
|
|
3829
4002
|
tags: ["panel"],
|
|
3830
4003
|
summary: "Stop the panel and everything it supervises (local token required)",
|
|
3831
4004
|
responses: {
|
|
3832
|
-
200: {
|
|
4005
|
+
200: {
|
|
4006
|
+
description: "Stopping",
|
|
4007
|
+
content: jsonBody(okResponseSchema)
|
|
4008
|
+
},
|
|
3833
4009
|
403: { description: "Bad token, or not a local caller" }
|
|
3834
4010
|
}
|
|
3835
4011
|
}), (c) => {
|
|
@@ -3840,7 +4016,10 @@ function createControlRoute(deps) {
|
|
|
3840
4016
|
tags: ["panel"],
|
|
3841
4017
|
summary: "Start one server, without a session (local token required)",
|
|
3842
4018
|
responses: {
|
|
3843
|
-
200: {
|
|
4019
|
+
200: {
|
|
4020
|
+
description: "Started",
|
|
4021
|
+
content: jsonBody(okResponseSchema)
|
|
4022
|
+
},
|
|
3844
4023
|
403: { description: "Bad token, or not a local caller" },
|
|
3845
4024
|
404: { description: "No such server" }
|
|
3846
4025
|
}
|
|
@@ -3852,7 +4031,10 @@ function createControlRoute(deps) {
|
|
|
3852
4031
|
tags: ["panel"],
|
|
3853
4032
|
summary: "Stop one server, without a session (local token required)",
|
|
3854
4033
|
responses: {
|
|
3855
|
-
200: {
|
|
4034
|
+
200: {
|
|
4035
|
+
description: "Stopped",
|
|
4036
|
+
content: jsonBody(okResponseSchema)
|
|
4037
|
+
},
|
|
3856
4038
|
403: { description: "Bad token, or not a local caller" },
|
|
3857
4039
|
404: { description: "No such server" }
|
|
3858
4040
|
}
|
|
@@ -3864,7 +4046,10 @@ function createControlRoute(deps) {
|
|
|
3864
4046
|
tags: ["panel"],
|
|
3865
4047
|
summary: "Restart one server, without a session (local token required)",
|
|
3866
4048
|
responses: {
|
|
3867
|
-
200: {
|
|
4049
|
+
200: {
|
|
4050
|
+
description: "Restarted",
|
|
4051
|
+
content: jsonBody(okResponseSchema)
|
|
4052
|
+
},
|
|
3868
4053
|
403: { description: "Bad token, or not a local caller" },
|
|
3869
4054
|
404: { description: "No such server" }
|
|
3870
4055
|
}
|
|
@@ -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`
|
|
@@ -12597,18 +13116,28 @@ function dependentsOf(server, servers) {
|
|
|
12597
13116
|
var init_dependencies = __esmMin((() => {}));
|
|
12598
13117
|
//#endregion
|
|
12599
13118
|
//#region src/services/log-buffer.ts
|
|
12600
|
-
var MAX_PENDING_CHARS, LogBuffer, LineSplitter;
|
|
13119
|
+
var MAX_PENDING_CHARS, MAX_TOTAL_CHARS, LogBuffer, LineSplitter;
|
|
12601
13120
|
var init_log_buffer = __esmMin((() => {
|
|
12602
13121
|
MAX_PENDING_CHARS = 65536;
|
|
13122
|
+
MAX_TOTAL_CHARS = 4194304;
|
|
12603
13123
|
LogBuffer = class {
|
|
12604
13124
|
capacity;
|
|
12605
13125
|
lines = [];
|
|
13126
|
+
/** Characters held, so the byte ceiling never needs a rescan. */
|
|
13127
|
+
chars = 0;
|
|
12606
13128
|
constructor(capacity) {
|
|
12607
13129
|
this.capacity = capacity;
|
|
12608
13130
|
}
|
|
12609
13131
|
push(line) {
|
|
12610
13132
|
this.lines.push(line);
|
|
12611
|
-
|
|
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;
|
|
12612
13141
|
}
|
|
12613
13142
|
extend(lines) {
|
|
12614
13143
|
for (const line of lines) this.push(line);
|
|
@@ -12619,6 +13148,7 @@ var init_log_buffer = __esmMin((() => {
|
|
|
12619
13148
|
}
|
|
12620
13149
|
clear() {
|
|
12621
13150
|
this.lines = [];
|
|
13151
|
+
this.chars = 0;
|
|
12622
13152
|
}
|
|
12623
13153
|
get size() {
|
|
12624
13154
|
return this.lines.length;
|
|
@@ -12970,6 +13500,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
12970
13500
|
*/
|
|
12971
13501
|
relay = new LogRelay({ onLines: (serverId, lines) => this.ingestExternalLines(serverId, lines) });
|
|
12972
13502
|
entries = /* @__PURE__ */ new Map();
|
|
13503
|
+
/** Processes no entry owns, refreshed by the tick; read synchronously by the state frame. */
|
|
13504
|
+
orphanCache = [];
|
|
12973
13505
|
tickTimer;
|
|
12974
13506
|
/** Detaches this supervisor from the store's listener set in `dispose()`. */
|
|
12975
13507
|
storeUnsubscribe;
|
|
@@ -12990,6 +13522,82 @@ var init_supervisor = __esmMin((() => {
|
|
|
12990
13522
|
views() {
|
|
12991
13523
|
return [...this.entries.values()].map((entry) => this.view(entry));
|
|
12992
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
|
+
}
|
|
12993
13601
|
logLines(id, limit) {
|
|
12994
13602
|
return this.entries.get(id)?.logs.list(limit) ?? [];
|
|
12995
13603
|
}
|
|
@@ -13041,9 +13649,12 @@ var init_supervisor = __esmMin((() => {
|
|
|
13041
13649
|
};
|
|
13042
13650
|
entry.starting = true;
|
|
13043
13651
|
entry.actor = options.retry ? "policy" : options.actor ?? "policy";
|
|
13652
|
+
entry.stoppedByPanel = false;
|
|
13044
13653
|
this.clearRetry(entry);
|
|
13045
13654
|
if (!options.retry) {
|
|
13046
13655
|
entry.restarts = 0;
|
|
13656
|
+
if (entry.actor !== "policy") entry.healthRestarts = 0;
|
|
13657
|
+
if (entry.actor !== "policy") entry.pendingRestart = null;
|
|
13047
13658
|
entry.healthFailures = 0;
|
|
13048
13659
|
entry.unhealthySince = null;
|
|
13049
13660
|
this.persistEntryState(entry);
|
|
@@ -13093,7 +13704,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
13093
13704
|
return this.stopEntry(entry);
|
|
13094
13705
|
}
|
|
13095
13706
|
async restart(id, options = {}) {
|
|
13707
|
+
const owed = this.entries.get(id)?.pendingRestart ?? null;
|
|
13096
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;
|
|
13097
13711
|
return this.start(id, options);
|
|
13098
13712
|
}
|
|
13099
13713
|
/**
|
|
@@ -13129,11 +13743,40 @@ var init_supervisor = __esmMin((() => {
|
|
|
13129
13743
|
error: `server "${id}" is busy — try again in a moment`
|
|
13130
13744
|
};
|
|
13131
13745
|
const { ours, foreign } = await this.portHolders(port);
|
|
13132
|
-
if ([...ours, ...foreign].length === 0)
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
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
|
+
}
|
|
13137
13780
|
if (foreign.length === 0) {
|
|
13138
13781
|
const reason = `port ${port} is held by pid ${ours.join(", ")}, which this panel supervises — stop that server instead`;
|
|
13139
13782
|
return {
|
|
@@ -13237,13 +13880,14 @@ var init_supervisor = __esmMin((() => {
|
|
|
13237
13880
|
for (const dependency of dependenciesOf(entry.config, this.store.servers)) {
|
|
13238
13881
|
const target = this.entries.get(dependency.id);
|
|
13239
13882
|
if (!target || !dependency.enabled) continue;
|
|
13240
|
-
if (target.status
|
|
13241
|
-
|
|
13242
|
-
|
|
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
|
+
}
|
|
13243
13887
|
const deadline = Date.now() + dependency.health.startTimeoutMs;
|
|
13244
13888
|
const isReady = () => {
|
|
13245
13889
|
if (this.statusOf(target) !== "running") return false;
|
|
13246
|
-
return target.health
|
|
13890
|
+
return target.health === "healthy" || target.health === "disabled";
|
|
13247
13891
|
};
|
|
13248
13892
|
while (!isReady() && Date.now() < deadline) await delay(250);
|
|
13249
13893
|
if (!isReady()) {
|
|
@@ -13357,15 +14001,18 @@ var init_supervisor = __esmMin((() => {
|
|
|
13357
14001
|
exitCode: null,
|
|
13358
14002
|
exitSignal: null,
|
|
13359
14003
|
restarts: persisted?.restarts ?? 0,
|
|
14004
|
+
healthRestarts: persisted?.healthRestarts ?? 0,
|
|
13360
14005
|
lastError: null,
|
|
13361
14006
|
nextRetryAt: null,
|
|
13362
14007
|
retryTimer: null,
|
|
13363
14008
|
healthFailures: 0,
|
|
13364
14009
|
unhealthySince: null,
|
|
14010
|
+
pendingRestart: null,
|
|
13365
14011
|
lastProbeAt: 0,
|
|
13366
14012
|
lastOccupancyProbeAt: 0,
|
|
13367
14013
|
probing: false,
|
|
13368
14014
|
adopted: false,
|
|
14015
|
+
stoppedByPanel: false,
|
|
13369
14016
|
nannyExit: null,
|
|
13370
14017
|
starting: false,
|
|
13371
14018
|
stopping: false,
|
|
@@ -13471,7 +14118,8 @@ var init_supervisor = __esmMin((() => {
|
|
|
13471
14118
|
const { ours, foreign } = await this.portHolders(port);
|
|
13472
14119
|
const holders = [...ours, ...foreign];
|
|
13473
14120
|
const own = await this.ownPortHolder(entry, foreign);
|
|
13474
|
-
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}")`;
|
|
13475
14123
|
if (entry.config.onPortConflict === "kill") {
|
|
13476
14124
|
if (ours.length > 0) {
|
|
13477
14125
|
entry.status = "conflict";
|
|
@@ -13484,6 +14132,17 @@ var init_supervisor = __esmMin((() => {
|
|
|
13484
14132
|
};
|
|
13485
14133
|
}
|
|
13486
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
|
+
}
|
|
13487
14146
|
this.log(entry, "system", `port ${port} looks busy but no listener could be found — starting anyway`);
|
|
13488
14147
|
return { kind: "free" };
|
|
13489
14148
|
}
|
|
@@ -13498,7 +14157,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13498
14157
|
this.log(entry, "system", `port ${port} is held by pid ${own}, a detached restart of this entry — replacing it with a supervised process`);
|
|
13499
14158
|
return await this.stopPortHolders(entry, [own], port, "replacing", freeOnAll);
|
|
13500
14159
|
}
|
|
13501
|
-
const hint = own !== null ? ` — pid ${own} is a detached restart of this entry: set onPortConflict to "follow" to adopt it, "reclaim" to replace it with a supervised process, or "kill" to stop whatever holds the port` : "";
|
|
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`;
|
|
13502
14161
|
if (entry.config.onPortConflict !== "warn") {
|
|
13503
14162
|
entry.status = "conflict";
|
|
13504
14163
|
entry.lastError = `port ${port} is already in use${suffix}${hint}`;
|
|
@@ -13624,6 +14283,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13624
14283
|
this.forgetRecordedChild(entry, adoptedPid);
|
|
13625
14284
|
entry.resources = null;
|
|
13626
14285
|
entry.responseMs = null;
|
|
14286
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
13627
14287
|
entry.exitCode = null;
|
|
13628
14288
|
entry.exitSignal = null;
|
|
13629
14289
|
if (!entry.removed) this.options.history.record(entry.config.id, {
|
|
@@ -13847,7 +14507,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13847
14507
|
entry.unhealthySince = null;
|
|
13848
14508
|
this.publishServer(entry);
|
|
13849
14509
|
child.once("error", (error) => {
|
|
13850
|
-
entry.lastError = error.
|
|
14510
|
+
entry.lastError = describeSpawnError(error, entry.config.command);
|
|
13851
14511
|
this.log(entry, "system", `process error: ${entry.lastError}`);
|
|
13852
14512
|
flush?.();
|
|
13853
14513
|
this.handleExit(entry, child, null, null);
|
|
@@ -13966,6 +14626,21 @@ var init_supervisor = __esmMin((() => {
|
|
|
13966
14626
|
clearNannyState(statePath);
|
|
13967
14627
|
this.drainRelay(entry);
|
|
13968
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
|
+
}
|
|
13969
14644
|
/** One probe using the configured mode (TCP or HTTP), with timing. */
|
|
13970
14645
|
async probeEntryHealth(entry) {
|
|
13971
14646
|
const { port, health } = entry.config;
|
|
@@ -13989,6 +14664,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
13989
14664
|
entry.status = "running";
|
|
13990
14665
|
entry.health = health.enabled ? "unknown" : "disabled";
|
|
13991
14666
|
this.log(entry, "system", "running (no port configured; readiness assumed on spawn)");
|
|
14667
|
+
this.settleRestart(entry, "it spawned and is running");
|
|
13992
14668
|
this.publishServer(entry);
|
|
13993
14669
|
return;
|
|
13994
14670
|
}
|
|
@@ -13997,10 +14673,11 @@ var init_supervisor = __esmMin((() => {
|
|
|
13997
14673
|
if (entry.child !== child || entry.status !== "starting" || this.disposed) return;
|
|
13998
14674
|
if (await this.portAccepts(entry, port, Math.min(health.timeoutMs, 1e3))) {
|
|
13999
14675
|
entry.portState = "in-use";
|
|
14000
|
-
entry.health = health.enabled ? "
|
|
14676
|
+
entry.health = !health.enabled ? "disabled" : health.mode === "http" ? "unknown" : "healthy";
|
|
14001
14677
|
entry.status = "running";
|
|
14002
|
-
entry.lastProbeAt =
|
|
14678
|
+
entry.lastProbeAt = 0;
|
|
14003
14679
|
this.log(entry, "system", `accepting connections on port ${port}`);
|
|
14680
|
+
if (health.mode !== "http") this.settleRestart(entry, `accepting connections on port ${port}`);
|
|
14004
14681
|
this.publishServer(entry);
|
|
14005
14682
|
return;
|
|
14006
14683
|
}
|
|
@@ -14025,6 +14702,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14025
14702
|
entry.adopted = false;
|
|
14026
14703
|
entry.resources = null;
|
|
14027
14704
|
entry.responseMs = null;
|
|
14705
|
+
entry.health = entry.config.health.enabled ? "unknown" : "disabled";
|
|
14028
14706
|
entry.exitCode = code;
|
|
14029
14707
|
entry.exitSignal = signal;
|
|
14030
14708
|
this.forgetRecordedChild(entry, child.pid ?? null);
|
|
@@ -14076,6 +14754,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14076
14754
|
} else {
|
|
14077
14755
|
entry.status = "crashed";
|
|
14078
14756
|
entry.nextRetryAt = null;
|
|
14757
|
+
entry.pendingRestart = null;
|
|
14079
14758
|
entry.lastError = restart.enabled ? `gave up after ${restart.maxRetries} retries (${detail})` : `${detail} (automatic restart disabled)`;
|
|
14080
14759
|
this.log(entry, "system", entry.lastError);
|
|
14081
14760
|
this.options.history.record(entry.config.id, {
|
|
@@ -14091,6 +14770,9 @@ var init_supervisor = __esmMin((() => {
|
|
|
14091
14770
|
if (this.disposed) return;
|
|
14092
14771
|
const now = Date.now();
|
|
14093
14772
|
await this.sampleResources(now);
|
|
14773
|
+
await this.refreshOrphans().catch((error) => {
|
|
14774
|
+
logger.warn("could not refresh the orphaned-process list", error);
|
|
14775
|
+
});
|
|
14094
14776
|
await Promise.allSettled([...this.entries.values()].map((entry) => this.probeEntry(entry, now)));
|
|
14095
14777
|
for (const entry of this.entries.values()) {
|
|
14096
14778
|
if (entry.adopted && entry.pid !== null && !isProcessAlive(entry.pid)) {
|
|
@@ -14098,6 +14780,10 @@ var init_supervisor = __esmMin((() => {
|
|
|
14098
14780
|
continue;
|
|
14099
14781
|
}
|
|
14100
14782
|
if (await this.enforceMemoryLimit(entry)) continue;
|
|
14783
|
+
if (this.healthBudgetSpent(entry)) {
|
|
14784
|
+
await this.giveUpOnHealth(entry);
|
|
14785
|
+
continue;
|
|
14786
|
+
}
|
|
14101
14787
|
if (this.shouldForceRestart(entry, now)) {
|
|
14102
14788
|
await this.restart(entry.config.id);
|
|
14103
14789
|
continue;
|
|
@@ -14142,9 +14828,15 @@ var init_supervisor = __esmMin((() => {
|
|
|
14142
14828
|
});
|
|
14143
14829
|
this.notify(entry, "recovered", probe.detail);
|
|
14144
14830
|
}
|
|
14831
|
+
this.settleRestart(entry, `${probe.detail} (${probe.ms}ms)`);
|
|
14145
14832
|
entry.health = "healthy";
|
|
14146
14833
|
entry.healthFailures = 0;
|
|
14147
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
|
+
}
|
|
14148
14840
|
return;
|
|
14149
14841
|
}
|
|
14150
14842
|
entry.healthFailures += 1;
|
|
@@ -14175,22 +14867,58 @@ var init_supervisor = __esmMin((() => {
|
|
|
14175
14867
|
detail
|
|
14176
14868
|
});
|
|
14177
14869
|
this.notify(entry, "rss", detail);
|
|
14870
|
+
entry.pendingRestart = { cause: "exceeding its memory limit" };
|
|
14178
14871
|
await this.restart(entry.config.id);
|
|
14179
14872
|
return true;
|
|
14180
14873
|
}
|
|
14181
14874
|
shouldForceRestart(entry, now) {
|
|
14182
|
-
const { port, health } = entry.config;
|
|
14875
|
+
const { port, health, restart } = entry.config;
|
|
14183
14876
|
if (port === null || entry.status !== "running" || entry.health !== "unhealthy") return false;
|
|
14184
14877
|
if (entry.unhealthySince === null || health.forceRestartAfterMs <= 0) return false;
|
|
14185
14878
|
if (now - entry.unhealthySince < health.forceRestartAfterMs) return false;
|
|
14186
|
-
|
|
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})`);
|
|
14187
14883
|
this.options.history.record(entry.config.id, {
|
|
14188
14884
|
type: "forced-restart",
|
|
14189
14885
|
detail: `health check stayed unhealthy`
|
|
14190
14886
|
});
|
|
14191
14887
|
this.notify(entry, "forced-restart", `unhealthy for ${Math.round(health.forceRestartAfterMs / 1e3)}s`);
|
|
14888
|
+
entry.pendingRestart = { cause: "staying unhealthy through its health check" };
|
|
14192
14889
|
return true;
|
|
14193
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
|
+
}
|
|
14194
14922
|
clearRetry(entry) {
|
|
14195
14923
|
if (entry.retryTimer !== null) {
|
|
14196
14924
|
clearTimeout(entry.retryTimer);
|
|
@@ -14202,6 +14930,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14202
14930
|
if (entry.removed) return;
|
|
14203
14931
|
writeEntryState(entryStatePath(this.options.nannyDir, entry.config.id), {
|
|
14204
14932
|
restarts: entry.restarts,
|
|
14933
|
+
healthRestarts: entry.healthRestarts,
|
|
14205
14934
|
bootstrapDone: entry.bootstrapDone,
|
|
14206
14935
|
lastPid: entry.config.persistent ? null : entry.lastChild?.pid ?? null,
|
|
14207
14936
|
lastStartedAt: entry.config.persistent ? null : entry.lastChild?.startedAt ?? null
|
|
@@ -14224,6 +14953,7 @@ var init_supervisor = __esmMin((() => {
|
|
|
14224
14953
|
portState: entry.portState,
|
|
14225
14954
|
pid: entry.pid,
|
|
14226
14955
|
...entry.adopted ? { adopted: true } : {},
|
|
14956
|
+
...entry.stoppedByPanel ? { stoppedByPanel: true } : {},
|
|
14227
14957
|
startedAt: entry.startedAt,
|
|
14228
14958
|
exitCode: entry.exitCode,
|
|
14229
14959
|
exitSignal: entry.exitSignal,
|
|
@@ -14461,6 +15191,39 @@ function readableGlobalSettings(text) {
|
|
|
14461
15191
|
}
|
|
14462
15192
|
}
|
|
14463
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
|
+
/**
|
|
14464
15227
|
* The manifest is written by us, but an uploaded archive's copy is attacker
|
|
14465
15228
|
* controlled: never join an unvalidated slug into a path.
|
|
14466
15229
|
*/
|
|
@@ -14536,11 +15299,12 @@ function readableWorkspaceSettings(text) {
|
|
|
14536
15299
|
return false;
|
|
14537
15300
|
}
|
|
14538
15301
|
}
|
|
14539
|
-
var MANIFEST, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
15302
|
+
var MANIFEST, REGISTRY, ALLOWED_ROOTS, SUFFIX, AUTO_PREFIX, RELOADABLE, SECRET_LABELS, BackupService;
|
|
14540
15303
|
var init_backups = __esmMin((() => {
|
|
14541
15304
|
init_migrations();
|
|
14542
15305
|
init_parse();
|
|
14543
15306
|
init_secret_parts();
|
|
15307
|
+
init_workspaces();
|
|
14544
15308
|
init_atomic();
|
|
14545
15309
|
init_env_file();
|
|
14546
15310
|
init_logger();
|
|
@@ -14549,10 +15313,12 @@ var init_backups = __esmMin((() => {
|
|
|
14549
15313
|
init_version();
|
|
14550
15314
|
init_archive();
|
|
14551
15315
|
init_supervisor();
|
|
15316
|
+
init_contracts();
|
|
14552
15317
|
init_error_message();
|
|
14553
15318
|
init_generated();
|
|
14554
15319
|
init_shape();
|
|
14555
15320
|
MANIFEST = "manifest.json";
|
|
15321
|
+
REGISTRY = "workspaces.json";
|
|
14556
15322
|
ALLOWED_ROOTS = /* @__PURE__ */ new Set([
|
|
14557
15323
|
"global",
|
|
14558
15324
|
"workspaces",
|
|
@@ -14599,6 +15365,8 @@ var init_backups = __esmMin((() => {
|
|
|
14599
15365
|
* long as the failure lasts. This is the in-memory backstop for that case.
|
|
14600
15366
|
*/
|
|
14601
15367
|
lastAttemptAt = null;
|
|
15368
|
+
/** Why the most recent scheduled pass failed, cleared by the next that works. */
|
|
15369
|
+
scheduleError = null;
|
|
14602
15370
|
constructor(options) {
|
|
14603
15371
|
this.options = options;
|
|
14604
15372
|
}
|
|
@@ -14622,6 +15390,7 @@ var init_backups = __esmMin((() => {
|
|
|
14622
15390
|
keep: config.keep,
|
|
14623
15391
|
schedule: { ...config.schedule },
|
|
14624
15392
|
lastAutomaticAt: this.lastAutomatic(),
|
|
15393
|
+
...this.scheduleError === null ? {} : { scheduleError: { ...this.scheduleError } },
|
|
14625
15394
|
includePaths: [...sources.includePaths],
|
|
14626
15395
|
entries: this.entries(sources),
|
|
14627
15396
|
files: this.list()
|
|
@@ -14714,6 +15483,7 @@ var init_backups = __esmMin((() => {
|
|
|
14714
15483
|
if (capturesGlobal("global:settings")) copy("global/settings.json", sources.globalSettingsPath);
|
|
14715
15484
|
if (capturesSecrets("global:secrets")) copySecrets("global/secrets.json", sources.globalSecretsPath, "global:secrets", "global");
|
|
14716
15485
|
if (capturesGlobal("global:tls")) copy("global/tls", sources.tlsDir);
|
|
15486
|
+
this.copyInto(staging, `global/${REGISTRY}`, sources.registryPath);
|
|
14717
15487
|
const data = [];
|
|
14718
15488
|
for (const workspace of sources.workspaces) {
|
|
14719
15489
|
const root = `workspaces/${workspace.id}`;
|
|
@@ -14812,7 +15582,9 @@ var init_backups = __esmMin((() => {
|
|
|
14812
15582
|
skipped: [],
|
|
14813
15583
|
skippedItems: [],
|
|
14814
15584
|
restartRequired: false,
|
|
14815
|
-
reloaded: false
|
|
15585
|
+
reloaded: false,
|
|
15586
|
+
createdWorkspaces: [],
|
|
15587
|
+
replacedUnderRunning: []
|
|
14816
15588
|
};
|
|
14817
15589
|
if (!isZipArchive(archivePath)) return {
|
|
14818
15590
|
...plan,
|
|
@@ -14971,54 +15743,47 @@ var init_backups = __esmMin((() => {
|
|
|
14971
15743
|
}
|
|
14972
15744
|
}, ["tls"]);
|
|
14973
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);
|
|
14974
15755
|
/** Every archived servers file this release can read, selected or not. */
|
|
14975
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();
|
|
14976
15763
|
const archiveWorkspaces = path.join(staging, "workspaces");
|
|
14977
15764
|
if (fs.existsSync(archiveWorkspaces)) for (const entry of fs.readdirSync(archiveWorkspaces, { withFileTypes: true })) {
|
|
14978
15765
|
if (!entry.isDirectory()) continue;
|
|
14979
15766
|
const id = entry.name;
|
|
14980
15767
|
const dir = path.join(archiveWorkspaces, id);
|
|
14981
|
-
const workspace = sources.workspaces.find((candidate) => candidate.id === id);
|
|
14982
15768
|
const settings = readText(path.join(dir, "settings.json"));
|
|
14983
15769
|
const servers = readText(path.join(dir, "servers.config.json"));
|
|
14984
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
|
+
});
|
|
14985
15778
|
if (workspace === void 0) {
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
],
|
|
14992
|
-
[
|
|
14993
|
-
"servers",
|
|
14994
|
-
"Servers",
|
|
14995
|
-
servers
|
|
14996
|
-
],
|
|
14997
|
-
[
|
|
14998
|
-
"secrets",
|
|
14999
|
-
"Secrets",
|
|
15000
|
-
secrets
|
|
15001
|
-
]
|
|
15002
|
-
];
|
|
15003
|
-
for (const [suffix, label, text] of leaves) {
|
|
15004
|
-
if (text === null) continue;
|
|
15005
|
-
addItem({
|
|
15006
|
-
id: `workspace:${id}:${suffix}`,
|
|
15007
|
-
label: `${id}: ${label}`,
|
|
15008
|
-
labelKey: "settings.backup.restoreItemLabel",
|
|
15009
|
-
labelParams: {
|
|
15010
|
-
workspace: id,
|
|
15011
|
-
item: suffix
|
|
15012
|
-
},
|
|
15013
|
-
kind: suffix,
|
|
15014
|
-
workspaceId: id,
|
|
15015
|
-
restorable: false,
|
|
15016
|
-
note: "unknown workspace",
|
|
15017
|
-
noteKey: "settings.backup.noteUnknownWorkspace"
|
|
15018
|
-
}, null);
|
|
15019
|
-
}
|
|
15779
|
+
plan.skipped.push(`${id} (not a usable workspace id)`);
|
|
15780
|
+
plan.skippedItems.push({
|
|
15781
|
+
label: id,
|
|
15782
|
+
reasonKey: "settings.restore.reasonInvalidWorkspace"
|
|
15783
|
+
});
|
|
15020
15784
|
continue;
|
|
15021
15785
|
}
|
|
15786
|
+
if (!sources.workspaces.some((candidate) => candidate.id === id)) createdWorkspaces.set(id, workspace);
|
|
15022
15787
|
if (settings !== null) {
|
|
15023
15788
|
if (readableWorkspaceSettings(settings)) addItem({
|
|
15024
15789
|
id: `workspace:${id}:settings`,
|
|
@@ -15033,6 +15798,7 @@ var init_backups = __esmMin((() => {
|
|
|
15033
15798
|
restorable: true,
|
|
15034
15799
|
note: null
|
|
15035
15800
|
}, () => {
|
|
15801
|
+
fs.mkdirSync(path.dirname(workspace.settingsPath), { recursive: true });
|
|
15036
15802
|
writeFileAtomic(workspace.settingsPath, settings);
|
|
15037
15803
|
});
|
|
15038
15804
|
else {
|
|
@@ -15065,6 +15831,7 @@ var init_backups = __esmMin((() => {
|
|
|
15065
15831
|
restorable: true,
|
|
15066
15832
|
note: null
|
|
15067
15833
|
}, () => {
|
|
15834
|
+
fs.mkdirSync(path.dirname(workspace.serversPath), { recursive: true });
|
|
15068
15835
|
writeFileAtomic(workspace.serversPath, servers);
|
|
15069
15836
|
});
|
|
15070
15837
|
} else {
|
|
@@ -15094,6 +15861,7 @@ var init_backups = __esmMin((() => {
|
|
|
15094
15861
|
restorable: true,
|
|
15095
15862
|
note: null
|
|
15096
15863
|
}, () => {
|
|
15864
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15097
15865
|
writeFileAtomic(workspace.secretsPath, secrets, { mode: 384 });
|
|
15098
15866
|
});
|
|
15099
15867
|
for (const part of secretParts("workspace", presentSecretKeys(parseSecrets(secrets)))) addItem({
|
|
@@ -15109,6 +15877,7 @@ var init_backups = __esmMin((() => {
|
|
|
15109
15877
|
restorable: true,
|
|
15110
15878
|
note: null
|
|
15111
15879
|
}, () => {
|
|
15880
|
+
fs.mkdirSync(path.dirname(workspace.secretsPath), { recursive: true });
|
|
15112
15881
|
mergeIntoFile(workspace.secretsPath, secrets, part.fields);
|
|
15113
15882
|
});
|
|
15114
15883
|
}
|
|
@@ -15143,16 +15912,30 @@ var init_backups = __esmMin((() => {
|
|
|
15143
15912
|
used.add(found);
|
|
15144
15913
|
return found;
|
|
15145
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
|
+
*/
|
|
15146
15924
|
const matchTarget = (origin, workspace, archivedPath) => {
|
|
15147
|
-
|
|
15148
|
-
|
|
15149
|
-
|
|
15150
|
-
|
|
15151
|
-
|
|
15152
|
-
return take(archiveTargets, usedArchive, (target) => target.origin === origin) ?? take(instanceTargets, usedInstance, (target) => target.origin === origin) ?? take(archiveTargets, usedArchive, (target) => target.path === archivedPath) ?? take(instanceTargets, usedInstance, (target) => target.path === archivedPath);
|
|
15153
|
-
}
|
|
15154
|
-
return take(archiveTargets, usedArchive, (target) => target.path === archivedPath) ?? take(instanceTargets, usedInstance, (target) => target.path === archivedPath);
|
|
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);
|
|
15155
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}`));
|
|
15156
15939
|
const archivedEntries = Array.isArray(manifest.data) ? manifest.data.filter(isRecord) : [];
|
|
15157
15940
|
for (const entry of archivedEntries) {
|
|
15158
15941
|
const archivedPath = typeof entry.path === "string" ? entry.path : "";
|
|
@@ -15187,6 +15970,12 @@ var init_backups = __esmMin((() => {
|
|
|
15187
15970
|
}, null, aliases);
|
|
15188
15971
|
continue;
|
|
15189
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
|
+
});
|
|
15190
15979
|
addItem({
|
|
15191
15980
|
...base,
|
|
15192
15981
|
restorable: true,
|
|
@@ -15195,11 +15984,13 @@ var init_backups = __esmMin((() => {
|
|
|
15195
15984
|
noteKey: "settings.backup.noteRestoredFrom",
|
|
15196
15985
|
noteParams: { path: archivedPath }
|
|
15197
15986
|
}
|
|
15198
|
-
}, () =>
|
|
15199
|
-
|
|
15200
|
-
|
|
15201
|
-
|
|
15202
|
-
|
|
15987
|
+
}, () => {
|
|
15988
|
+
fs.cpSync(from, target.path, {
|
|
15989
|
+
recursive: true,
|
|
15990
|
+
force: true,
|
|
15991
|
+
filter: (_source, destination) => isInsideResolved(target.path, destination)
|
|
15992
|
+
});
|
|
15993
|
+
}, aliases);
|
|
15203
15994
|
}
|
|
15204
15995
|
if (parsedGlobal !== null && actions.has("global:settings") && settingsText !== null) {
|
|
15205
15996
|
const currentText = readText(sources.globalSettingsPath);
|
|
@@ -15216,6 +16007,14 @@ var init_backups = __esmMin((() => {
|
|
|
15216
16007
|
plan.applied.push(labelOf(plan, id));
|
|
15217
16008
|
}
|
|
15218
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
|
+
}
|
|
15219
16018
|
if (this.options.onRestored !== void 0 && [...actions.keys()].some((id) => RELOADABLE.test(id))) {
|
|
15220
16019
|
plan.reloaded = true;
|
|
15221
16020
|
this.options.onRestored();
|
|
@@ -15489,8 +16288,20 @@ var init_backups = __esmMin((() => {
|
|
|
15489
16288
|
this.running = true;
|
|
15490
16289
|
this.lastAttemptAt = now;
|
|
15491
16290
|
this.create({ automatic: true }).then((result) => {
|
|
15492
|
-
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);
|
|
15493
16300
|
}).catch((error) => {
|
|
16301
|
+
this.scheduleError = {
|
|
16302
|
+
message: errorMessage(error),
|
|
16303
|
+
at: Date.now()
|
|
16304
|
+
};
|
|
15494
16305
|
logger.error("the scheduled backup failed", error);
|
|
15495
16306
|
}).finally(() => {
|
|
15496
16307
|
this.running = false;
|
|
@@ -16752,6 +17563,14 @@ var init_notifications = __esmMin((() => {
|
|
|
16752
17563
|
"crash": "gave up restarting",
|
|
16753
17564
|
"unhealthy": "health check failing",
|
|
16754
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",
|
|
16755
17574
|
"recovered": "recovered",
|
|
16756
17575
|
"rss": "exceeded its memory limit",
|
|
16757
17576
|
"host": "host thresholds breached",
|
|
@@ -16763,6 +17582,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16763
17582
|
"crash": "🔴 server down",
|
|
16764
17583
|
"unhealthy": "🟠 server unhealthy",
|
|
16765
17584
|
"forced-restart": "🔁 server force restarted",
|
|
17585
|
+
"restart-ok": "🟢 server back up",
|
|
16766
17586
|
"recovered": "🟢 server recovered",
|
|
16767
17587
|
"rss": "🔴 server over its memory limit",
|
|
16768
17588
|
"host": "🟠 host warning",
|
|
@@ -16775,6 +17595,7 @@ var init_notifications = __esmMin((() => {
|
|
|
16775
17595
|
"rss": (policy) => policy.onCrash,
|
|
16776
17596
|
"unhealthy": (policy) => policy.onUnhealthy,
|
|
16777
17597
|
"forced-restart": (policy) => policy.onForcedRestart,
|
|
17598
|
+
"restart-ok": (policy) => policy.onForcedRestart,
|
|
16778
17599
|
"recovered": (policy) => policy.onRecovered,
|
|
16779
17600
|
"host": (policy) => policy.onHost,
|
|
16780
17601
|
"host-recovered": (policy) => policy.onHost,
|
|
@@ -17200,7 +18021,12 @@ var init_panel = __esmMin((() => {
|
|
|
17200
18021
|
globalSettingsPath: this.options.settings.path,
|
|
17201
18022
|
globalSecretsPath: this.options.secrets.path,
|
|
17202
18023
|
tlsDir: this.options.tls.directory,
|
|
18024
|
+
registryPath: this.options.registry.path,
|
|
17203
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
|
+
}))),
|
|
17204
18030
|
workspaces: this.workspaces().map((runtime) => ({
|
|
17205
18031
|
id: runtime.id,
|
|
17206
18032
|
label: runtime.label,
|
|
@@ -17219,6 +18045,22 @@ var init_panel = __esmMin((() => {
|
|
|
17219
18045
|
this.scheduleState();
|
|
17220
18046
|
return runtime.view();
|
|
17221
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
|
+
}
|
|
17222
18064
|
rename(id, label) {
|
|
17223
18065
|
const workspace = this.options.registry.rename(id, label);
|
|
17224
18066
|
const runtime = this.runtimes.get(id);
|
|
@@ -17258,16 +18100,35 @@ var init_panel = __esmMin((() => {
|
|
|
17258
18100
|
this.scheduleState();
|
|
17259
18101
|
return entry;
|
|
17260
18102
|
}
|
|
17261
|
-
/**
|
|
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
|
+
*/
|
|
17262
18111
|
reloadAll() {
|
|
17263
18112
|
this.options.settings.load();
|
|
17264
18113
|
for (const runtime of this.workspaces()) {
|
|
18114
|
+
const before = new Set(runtime.store.servers.map((server) => server.id));
|
|
17265
18115
|
runtime.store.load();
|
|
17266
18116
|
runtime.history.load();
|
|
17267
18117
|
this.reportWorkspaceErrors(runtime.id);
|
|
18118
|
+
this.startRestored(runtime, before);
|
|
17268
18119
|
}
|
|
17269
18120
|
this.scheduleState();
|
|
17270
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
|
+
}
|
|
17271
18132
|
/** Starts whatever the config marks autostart, across every workspace. */
|
|
17272
18133
|
async startAll(workspaces = this.workspaces().map((runtime) => runtime.id)) {
|
|
17273
18134
|
for (const id of workspaces) {
|
|
@@ -18315,6 +19176,7 @@ async function runControlPlane(options) {
|
|
|
18315
19176
|
dataRoot: hhDir,
|
|
18316
19177
|
getConfig: () => settings.backups,
|
|
18317
19178
|
getSources: () => panel.backupSources(),
|
|
19179
|
+
ensureWorkspace: (input) => panel?.ensureWorkspace(input),
|
|
18318
19180
|
onRestored: () => panel?.reloadAll()
|
|
18319
19181
|
});
|
|
18320
19182
|
panel = new PanelService({
|
|
@@ -18540,7 +19402,7 @@ async function runUp(flags, entry) {
|
|
|
18540
19402
|
process.stdout.write(`${green("already running")} home-hosted ${existing.version} (pid ${existing.pid}) at ${existing.url}\n`);
|
|
18541
19403
|
const note = versionMismatchNote(existing.version);
|
|
18542
19404
|
if (note !== null) process.stdout.write(`${dim(note)}\n`);
|
|
18543
|
-
process.stdout.write(`${dim(
|
|
19405
|
+
process.stdout.write(`${dim(`stop it with \`${invocation()} down\``)}\n`);
|
|
18544
19406
|
return;
|
|
18545
19407
|
}
|
|
18546
19408
|
if (existing !== null && await runtimeIsGone(existing)) clearRuntime();
|
|
@@ -18776,7 +19638,7 @@ async function runServerAction(action, id, workspace) {
|
|
|
18776
19638
|
const runtime = readRuntime();
|
|
18777
19639
|
if (runtime === null || !await runtimeIsAlive(runtime)) {
|
|
18778
19640
|
if (runtime !== null && await runtimeIsGone(runtime)) clearRuntime();
|
|
18779
|
-
fail(
|
|
19641
|
+
fail(`home-hosted is not running — start it with \`${invocation()} up\``);
|
|
18780
19642
|
}
|
|
18781
19643
|
const query = workspace === void 0 || workspace.length === 0 ? "" : `?workspace=${encodeURIComponent(workspace)}`;
|
|
18782
19644
|
const answer = await requestControl(runtime, `/_hh/servers/${encodeURIComponent(id)}/${action}${query}`);
|
|
@@ -18808,7 +19670,7 @@ function serverCommand(action) {
|
|
|
18808
19670
|
},
|
|
18809
19671
|
run: async ({ args }) => {
|
|
18810
19672
|
const id = typeof args.id === "string" ? args.id.trim() : "";
|
|
18811
|
-
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`);
|
|
18812
19674
|
await runServerAction(action, id, typeof args.workspace === "string" ? args.workspace.trim() : void 0);
|
|
18813
19675
|
}
|
|
18814
19676
|
});
|
|
@@ -18882,8 +19744,8 @@ async function runStatus(json) {
|
|
|
18882
19744
|
running: false,
|
|
18883
19745
|
initialised
|
|
18884
19746
|
}, null, 2)}\n`);
|
|
18885
|
-
else if (initialised) process.stdout.write(
|
|
18886
|
-
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`);
|
|
18887
19749
|
process.exitCode = 1;
|
|
18888
19750
|
return;
|
|
18889
19751
|
}
|
|
@@ -18928,7 +19790,7 @@ async function runStatus(json) {
|
|
|
18928
19790
|
const dir = path.join(workspaceDir(DEFAULT_WORKSPACE_ID), ".logs");
|
|
18929
19791
|
return fs.existsSync(dir) ? `${dir} (one file per server: <id>.log)` : dir;
|
|
18930
19792
|
})()],
|
|
18931
|
-
["ui", ui.custom ? `custom — ${uiLabel} (revert with
|
|
19793
|
+
["ui", ui.custom ? `custom — ${uiLabel} (revert with \`${invocation()} ui-revert\`)` : "stock"]
|
|
18932
19794
|
];
|
|
18933
19795
|
process.stdout.write(`${bold(`home-hosted ${runtime.version}`)}\n`);
|
|
18934
19796
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
@@ -19113,7 +19975,7 @@ async function runSetPassword(clear) {
|
|
|
19113
19975
|
store.setPassword(password);
|
|
19114
19976
|
process.stdout.write(`${green("password stored")} in ${globalSecretsPath} (mode 0600)\n`);
|
|
19115
19977
|
if (password.length < 8) process.stdout.write(`${dim(`"${password}" is short — easy to guess if the panel is reachable beyond loopback`)}\n`);
|
|
19116
|
-
process.stdout.write(`${dim("
|
|
19978
|
+
process.stdout.write(`${dim("a running panel picks it up immediately, and every existing browser session is signed out")}\n`);
|
|
19117
19979
|
}
|
|
19118
19980
|
var setPasswordArgs, setPasswordCommand;
|
|
19119
19981
|
var init_set_password = __esmMin((() => {
|
|
@@ -20227,7 +21089,7 @@ var SUMMARIES = {
|
|
|
20227
21089
|
"ui-revert": "go back to the stock control panel UI"
|
|
20228
21090
|
};
|
|
20229
21091
|
/** Every section lays its left column out at this width, so the two views align. */
|
|
20230
|
-
var OPTION_WIDTH =
|
|
21092
|
+
var OPTION_WIDTH = 21;
|
|
20231
21093
|
var UP_SECTION = {
|
|
20232
21094
|
heading: "Options for up/restart",
|
|
20233
21095
|
lines: [
|
|
@@ -20254,7 +21116,7 @@ var LOGS_SECTION = {
|
|
|
20254
21116
|
};
|
|
20255
21117
|
var SERVER_SECTION = {
|
|
20256
21118
|
heading: "Arguments for start/stop",
|
|
20257
|
-
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)"]]
|
|
20258
21120
|
};
|
|
20259
21121
|
var RESTART_SECTION = {
|
|
20260
21122
|
heading: "Options for restart",
|
|
@@ -20274,7 +21136,11 @@ var SET_TOKEN_SECTION = {
|
|
|
20274
21136
|
};
|
|
20275
21137
|
var MIGRATE_SECTION = {
|
|
20276
21138
|
heading: "Options for migrate",
|
|
20277
|
-
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
|
+
]
|
|
20278
21144
|
};
|
|
20279
21145
|
var INIT_SECTION = {
|
|
20280
21146
|
heading: "Options for init",
|