home-hosted 0.13.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -322
- package/bin/home-hosted.mjs +41 -0
- package/dist/chunks/account-DiLrSyww.js +359 -0
- package/dist/chunks/account-DiLrSyww.js.map +1 -0
- package/dist/chunks/add-DEIYVkNK.js +183 -0
- package/dist/chunks/add-DEIYVkNK.js.map +1 -0
- package/dist/chunks/{archive-DP-XQR8X.js → archive-DFi3qK1c.js} +25 -73
- package/dist/chunks/archive-DFi3qK1c.js.map +1 -0
- package/dist/chunks/{atomic-C1PfJpE7.js → atomic-SZUwDtGD.js} +3 -6
- package/dist/chunks/atomic-SZUwDtGD.js.map +1 -0
- package/dist/chunks/{backup-CZcVca2a.js → backup-DnyxIzw0.js} +110 -190
- package/dist/chunks/backup-DnyxIzw0.js.map +1 -0
- package/dist/chunks/backups-BrrN6cwW.js +2203 -0
- package/dist/chunks/backups-BrrN6cwW.js.map +1 -0
- package/dist/chunks/bind-DIxrnUst.js +43 -0
- package/dist/chunks/bind-DIxrnUst.js.map +1 -0
- package/dist/chunks/config-text-DxMOQQnk.js +34 -0
- package/dist/chunks/config-text-DxMOQQnk.js.map +1 -0
- package/dist/chunks/{contracts-CMBD1TF9.js → contracts-CxZ7u1L3.js} +1239 -1454
- package/dist/chunks/contracts-CxZ7u1L3.js.map +1 -0
- package/dist/chunks/daemon-BAAYUYQC.js +211 -0
- package/dist/chunks/daemon-BAAYUYQC.js.map +1 -0
- package/dist/chunks/daemon-log-Ccu-69vB.js +179 -0
- package/dist/chunks/daemon-log-Ccu-69vB.js.map +1 -0
- package/dist/chunks/deploy-CggSOEkq.js +144 -0
- package/dist/chunks/deploy-CggSOEkq.js.map +1 -0
- package/dist/chunks/{docker-Cy9Lyvda.js → docker--Un0uLfF.js} +32 -68
- package/dist/chunks/docker--Un0uLfF.js.map +1 -0
- package/dist/chunks/{down-pKbGCW9d.js → down-CpIN7LEQ.js} +34 -94
- package/dist/chunks/down-CpIN7LEQ.js.map +1 -0
- package/dist/chunks/exposure-CDJNvOCK.js +229 -0
- package/dist/chunks/exposure-CDJNvOCK.js.map +1 -0
- package/dist/chunks/import-Bd4VZH0f.js +205 -0
- package/dist/chunks/import-Bd4VZH0f.js.map +1 -0
- package/dist/chunks/import-plan--fDS_l5r.js +147 -0
- package/dist/chunks/import-plan--fDS_l5r.js.map +1 -0
- package/dist/chunks/import-write-BTfbeV26.js +42 -0
- package/dist/chunks/import-write-BTfbeV26.js.map +1 -0
- package/dist/chunks/{init-BZ7hK9Vf.js → init-Bv3oH65x.js} +14 -50
- package/dist/chunks/init-Bv3oH65x.js.map +1 -0
- package/dist/chunks/job-CYOdN6Ub.js +341 -0
- package/dist/chunks/job-CYOdN6Ub.js.map +1 -0
- package/dist/chunks/jobs-BX4ahcfh.js +489 -0
- package/dist/chunks/jobs-BX4ahcfh.js.map +1 -0
- package/dist/chunks/last-stop-DD3lHwo_.js +42 -0
- package/dist/chunks/last-stop-DD3lHwo_.js.map +1 -0
- package/dist/chunks/layout-D0ysDNav.js +18 -0
- package/dist/chunks/layout-D0ysDNav.js.map +1 -0
- package/dist/chunks/lazy-kfcBNeqj.js +48 -0
- package/dist/chunks/lazy-kfcBNeqj.js.map +1 -0
- package/dist/chunks/log-buffer-B7jmn7ts.js +110 -0
- package/dist/chunks/log-buffer-B7jmn7ts.js.map +1 -0
- package/dist/chunks/log-files-CZL2UhuE.js +488 -0
- package/dist/chunks/log-files-CZL2UhuE.js.map +1 -0
- package/dist/chunks/{logger-B5U4GD3j.js → logger-BnrKTBHQ.js} +2 -6
- package/dist/chunks/logger-BnrKTBHQ.js.map +1 -0
- package/dist/chunks/{logs---TI_bxM.js → logs-DxKI6OW2.js} +23 -73
- package/dist/chunks/logs-DxKI6OW2.js.map +1 -0
- package/dist/chunks/ls-BseUHy_m.js +128 -0
- package/dist/chunks/ls-BseUHy_m.js.map +1 -0
- package/dist/chunks/migrate-D4w_dXDm.js +268 -0
- package/dist/chunks/migrate-D4w_dXDm.js.map +1 -0
- package/dist/chunks/{nanny-B-Eu0sFW.js → nanny-BWh7nuvv.js} +21 -14
- package/dist/chunks/nanny-BWh7nuvv.js.map +1 -0
- package/dist/chunks/{nanny-ChMtq1Zl.js → nanny-BjF2-1pv.js} +3 -3
- package/dist/chunks/{nanny-ChMtq1Zl.js.map → nanny-BjF2-1pv.js.map} +1 -1
- package/dist/chunks/nanny-DGTXVq5d.js +806 -0
- package/dist/chunks/nanny-DGTXVq5d.js.map +1 -0
- package/dist/chunks/{nanny-sweep-DErnlPY1.js → nanny-sweep-hjmZ_p7S.js} +14 -24
- package/dist/chunks/nanny-sweep-hjmZ_p7S.js.map +1 -0
- package/dist/chunks/{nearest-6KgQEDUe.js → nearest-DOx4jySJ.js} +2 -10
- package/dist/chunks/nearest-DOx4jySJ.js.map +1 -0
- package/dist/chunks/{parse-DhmG26fI.js → parse-DVMPLUDe.js} +47 -72
- package/dist/chunks/parse-DVMPLUDe.js.map +1 -0
- package/dist/chunks/password-policy-Clq6PGE-.js +9 -0
- package/dist/chunks/password-policy-Clq6PGE-.js.map +1 -0
- package/dist/chunks/{paths-CGlGDrOU.js → paths-C34-TJLh.js} +32 -56
- package/dist/chunks/paths-C34-TJLh.js.map +1 -0
- package/dist/chunks/{port-B8WBTRMk.js → port-CnsrxKNR.js} +27 -71
- package/dist/chunks/port-CnsrxKNR.js.map +1 -0
- package/dist/chunks/process-CboOFPU_.js +192 -0
- package/dist/chunks/process-CboOFPU_.js.map +1 -0
- package/dist/chunks/{restart-Des4DrAN.js → restart-C0J8dZ2L.js} +11 -29
- package/dist/chunks/restart-C0J8dZ2L.js.map +1 -0
- package/dist/chunks/run-deploy-DoNDvwT4.js +91 -0
- package/dist/chunks/run-deploy-DoNDvwT4.js.map +1 -0
- package/dist/chunks/{schema-B240VXcV.js → schema-CZ6f-PHD.js} +7 -20
- package/dist/chunks/schema-CZ6f-PHD.js.map +1 -0
- package/dist/chunks/secret-MY397r90.js +219 -0
- package/dist/chunks/secret-MY397r90.js.map +1 -0
- package/dist/chunks/secrets-CG5N4lwY.js +1061 -0
- package/dist/chunks/secrets-CG5N4lwY.js.map +1 -0
- package/dist/chunks/server-Dm_dXfTW.js +255 -0
- package/dist/chunks/server-Dm_dXfTW.js.map +1 -0
- package/dist/chunks/server-attention-UQwYXqKe.js +10 -0
- package/dist/chunks/server-attention-UQwYXqKe.js.map +1 -0
- package/dist/chunks/server-create-D7nvhgBd.js +96 -0
- package/dist/chunks/server-create-D7nvhgBd.js.map +1 -0
- package/dist/chunks/server-ids-BEQD2rFz.js +23 -0
- package/dist/chunks/server-ids-BEQD2rFz.js.map +1 -0
- package/dist/chunks/server-vars-DMYmHutL.js +27 -0
- package/dist/chunks/server-vars-DMYmHutL.js.map +1 -0
- package/dist/chunks/service-C8l-ewNA.js +585 -0
- package/dist/chunks/service-C8l-ewNA.js.map +1 -0
- package/dist/chunks/{settings-xu-XTfWg.js → settings-CtYDs5PX.js} +62 -78
- package/dist/chunks/settings-CtYDs5PX.js.map +1 -0
- package/dist/chunks/{setup-temp-CAN4_bA-.js → setup-temp-TAtDmMMU.js} +43 -37
- package/dist/chunks/setup-temp-TAtDmMMU.js.map +1 -0
- package/dist/chunks/shape-CDGeYl_J.js +9 -0
- package/dist/chunks/shape-CDGeYl_J.js.map +1 -0
- package/dist/chunks/{src-BtWMFmzZ.js → src-BnzkVy_M.js} +12548 -10576
- package/dist/chunks/src-BnzkVy_M.js.map +1 -0
- package/dist/chunks/{status-DT1EsA-B.js → status-efbbfYZQ.js} +53 -26
- package/dist/chunks/status-efbbfYZQ.js.map +1 -0
- package/dist/chunks/store-Bs_Lljjm.js +2082 -0
- package/dist/chunks/store-Bs_Lljjm.js.map +1 -0
- package/dist/chunks/template-xan58bJh.js +28 -0
- package/dist/chunks/template-xan58bJh.js.map +1 -0
- package/dist/chunks/token-DDeWfZA4.js +142 -0
- package/dist/chunks/token-DDeWfZA4.js.map +1 -0
- package/dist/chunks/{ui-D562aqw5.js → ui-BcIAtyxE.js} +68 -79
- package/dist/chunks/ui-BcIAtyxE.js.map +1 -0
- package/dist/chunks/{ui-dir-CsU3uLNV.js → ui-dir-ClCzVRc3.js} +3 -7
- package/dist/chunks/ui-dir-ClCzVRc3.js.map +1 -0
- package/dist/chunks/ui-format-CDvvqOoi.js +53 -0
- package/dist/chunks/ui-format-CDvvqOoi.js.map +1 -0
- package/dist/chunks/{ui-release-DKzVvlLd.js → ui-release-XbJ85pYI.js} +36 -38
- package/dist/chunks/ui-release-XbJ85pYI.js.map +1 -0
- package/dist/chunks/{ui-revert-EkBBwRTt.js → ui-revert-Dgawq7ze.js} +4 -4
- package/dist/chunks/ui-revert-Dgawq7ze.js.map +1 -0
- package/dist/chunks/{ui-switch-BnZTdMDd.js → ui-switch-CfQMbZ0g.js} +31 -38
- package/dist/chunks/ui-switch-CfQMbZ0g.js.map +1 -0
- package/dist/chunks/{ui-update-_xryLYxw.js → ui-update-B3PPivUm.js} +30 -48
- package/dist/chunks/ui-update-B3PPivUm.js.map +1 -0
- package/dist/chunks/ui-update-CAiH2tFb.js +109 -0
- package/dist/chunks/ui-update-CAiH2tFb.js.map +1 -0
- package/dist/chunks/{up-Pdz-l6IH.js → up-BQSnYxYd.js} +47 -53
- package/dist/chunks/up-BQSnYxYd.js.map +1 -0
- package/dist/chunks/{usage-DFrCVXpT.js → usage-KG8TeOio.js} +7 -20
- package/dist/chunks/usage-KG8TeOio.js.map +1 -0
- package/dist/chunks/{workspaces-DYcfvKV_.js → workspaces-D9akpzU8.js} +80 -68
- package/dist/chunks/workspaces-D9akpzU8.js.map +1 -0
- package/dist/chunks/{wsl-temperature-BiCI4iK6.js → wsl-temperature-D-_d4Yk1.js} +47 -42
- package/dist/chunks/wsl-temperature-D-_d4Yk1.js.map +1 -0
- package/dist/cli.js +306 -238
- package/dist/cli.js.map +1 -1
- package/dist/client.js +76 -29
- package/dist/client.js.map +1 -1
- package/dist/types/api/acme.d.ts +3 -7
- package/dist/types/api/auth/$.routes.d.ts +107 -16
- package/dist/types/api/backups.d.ts +5 -5
- package/dist/types/api/control.d.ts +747 -38
- package/dist/types/api/ddns.d.ts +13 -18
- package/dist/types/api/events.d.ts +9 -3
- package/dist/types/api/health.d.ts +2 -4
- package/dist/types/api/jobs.d.ts +438 -0
- package/dist/types/api/logs.d.ts +20 -0
- package/dist/types/api/metrics.d.ts +2 -5
- package/dist/types/api/notifications.d.ts +3 -6
- package/dist/types/api/proxy.d.ts +63 -23
- package/dist/types/api/server-ops.d.ts +17 -0
- package/dist/types/api/servers/$.routes.d.ts +418 -186
- package/dist/types/api/session-required.d.ts +16 -0
- package/dist/types/api/settings.d.ts +7 -7
- package/dist/types/api/state.d.ts +100 -10
- package/dist/types/api/static.d.ts +2 -2
- package/dist/types/api/tls.d.ts +2 -5
- package/dist/types/api/workspaces/$.routes.d.ts +186 -12
- package/dist/types/api/wsl-temperature.d.ts +4 -10
- package/dist/types/app.d.ts +4511 -2778
- package/dist/types/cli/account.d.ts +23 -0
- package/dist/types/cli/add.d.ts +96 -0
- package/dist/types/cli/args.d.ts +24 -35
- package/dist/types/cli/backup-offline.d.ts +2 -8
- package/dist/types/cli/backup.d.ts +12 -21
- package/dist/types/cli/down.d.ts +15 -41
- package/dist/types/cli/import-plan.d.ts +55 -0
- package/dist/types/cli/import-write.d.ts +5 -0
- package/dist/types/cli/import.d.ts +86 -0
- package/dist/types/cli/io.d.ts +26 -35
- package/dist/types/cli/job.d.ts +99 -0
- package/dist/types/cli/logs.d.ts +1 -10
- package/dist/types/cli/ls.d.ts +57 -0
- package/dist/types/cli/migrate.d.ts +31 -8
- package/dist/types/cli/nearest.d.ts +1 -9
- package/dist/types/cli/run-deploy.d.ts +36 -0
- package/dist/types/cli/secret.d.ts +90 -0
- package/dist/types/cli/server.d.ts +6 -15
- package/dist/types/cli/service.d.ts +135 -0
- package/dist/types/cli/setup-temp.d.ts +17 -13
- package/dist/types/cli/status.d.ts +7 -1
- package/dist/types/cli/token.d.ts +6 -0
- package/dist/types/cli/ui-switch.d.ts +3 -14
- package/dist/types/cli/ui-update.d.ts +3 -16
- package/dist/types/cli/up.d.ts +9 -22
- package/dist/types/cli/usage.d.ts +2 -6
- package/dist/types/cli.d.ts +1 -10
- package/dist/types/client.d.ts +4099 -1142
- package/dist/types/config/accounts.d.ts +16 -0
- package/dist/types/config/jobs.d.ts +68 -0
- package/dist/types/config/layout.d.ts +2 -8
- package/dist/types/config/migrations.d.ts +9 -41
- package/dist/types/config/parse.d.ts +8 -13
- package/dist/types/config/patch.d.ts +1 -6
- package/dist/types/config/schema.d.ts +16 -18
- package/dist/types/config/secret-parts.d.ts +6 -27
- package/dist/types/config/secrets.d.ts +167 -88
- package/dist/types/config/seed.d.ts +1 -6
- package/dist/types/config/server-ids.d.ts +2 -11
- package/dist/types/config/settings.d.ts +13 -49
- package/dist/types/config/store.d.ts +17 -54
- package/dist/types/config/workspaces.d.ts +24 -56
- package/dist/types/helpers/action-result.d.ts +18 -32
- package/dist/types/helpers/atomic.d.ts +1 -4
- package/dist/types/helpers/backoff.d.ts +0 -1
- package/dist/types/helpers/bind.d.ts +3 -11
- package/dist/types/helpers/config-text.d.ts +4 -19
- package/dist/types/helpers/cookies.d.ts +2 -7
- package/dist/types/helpers/copy-tree.d.ts +4 -12
- package/dist/types/helpers/daemon-log.d.ts +8 -33
- package/dist/types/helpers/daemon.d.ts +20 -70
- package/dist/types/helpers/deferred.d.ts +2 -4
- package/dist/types/helpers/env-file.d.ts +2 -7
- package/dist/types/helpers/error.d.ts +3 -14
- package/dist/types/helpers/event-stream.d.ts +18 -10
- package/dist/types/helpers/factory.d.ts +2 -3
- package/dist/types/helpers/last-stop.d.ts +5 -12
- package/dist/types/helpers/logger.d.ts +1 -5
- package/dist/types/helpers/open.d.ts +0 -1
- package/dist/types/helpers/openapi.d.ts +19 -5
- package/dist/types/helpers/paths.d.ts +18 -53
- package/dist/types/helpers/restore-lock.d.ts +2 -17
- package/dist/types/helpers/runtime.d.ts +3 -13
- package/dist/types/helpers/secret-compare.d.ts +2 -10
- package/dist/types/helpers/server-create.d.ts +15 -0
- package/dist/types/helpers/shell.d.ts +2 -16
- package/dist/types/helpers/sse.d.ts +8 -6
- package/dist/types/helpers/ui-dir.d.ts +1 -5
- package/dist/types/helpers/utf8-chunks.d.ts +2 -8
- package/dist/types/helpers/validate.d.ts +2 -4
- package/dist/types/helpers/validator.d.ts +8 -4
- package/dist/types/helpers/version.d.ts +1 -6
- package/dist/types/helpers/workspace.d.ts +24 -16
- package/dist/types/index.d.ts +2 -3
- package/dist/types/middleware/auth.d.ts +8 -27
- package/dist/types/middleware/body-limit.d.ts +10 -0
- package/dist/types/middleware/host.d.ts +4 -23
- package/dist/types/middleware/loopback.d.ts +1 -8
- package/dist/types/middleware/token-scope.d.ts +34 -0
- package/dist/types/node-compat.d.ts +43 -0
- package/dist/types/openapi-reference.d.ts +4 -19
- package/dist/types/openapi.d.ts +5 -8
- package/dist/types/providers/archive.d.ts +8 -25
- package/dist/types/providers/backup-hook.d.ts +4 -19
- package/dist/types/providers/ddns/dyndns2.d.ts +0 -3
- package/dist/types/providers/ddns/index.d.ts +2 -3
- package/dist/types/providers/ddns/ip.d.ts +2 -12
- package/dist/types/providers/ddns/namecheap-api.d.ts +3 -2
- package/dist/types/providers/ddns/types.d.ts +6 -32
- package/dist/types/providers/ddns/zone.d.ts +1 -4
- package/dist/types/providers/docker.d.ts +18 -45
- package/dist/types/providers/entry-state.d.ts +4 -9
- package/dist/types/providers/health-check.d.ts +1 -5
- package/dist/types/providers/host.d.ts +33 -108
- package/dist/types/providers/identity.d.ts +9 -34
- package/dist/types/providers/log-tail.d.ts +14 -24
- package/dist/types/providers/nanny-sweep.d.ts +8 -25
- package/dist/types/providers/nanny.d.ts +16 -58
- package/dist/types/providers/port.d.ts +28 -83
- package/dist/types/providers/proc.d.ts +22 -80
- package/dist/types/providers/process.d.ts +12 -36
- package/dist/types/providers/proxy/admin.d.ts +11 -0
- package/dist/types/providers/proxy/types.d.ts +4 -16
- package/dist/types/providers/telegram.d.ts +1 -17
- package/dist/types/providers/ui-release.d.ts +15 -25
- package/dist/types/providers/webhook.d.ts +8 -29
- package/dist/types/providers/wsl-temperature.d.ts +13 -22
- package/dist/types/services/acme-challenge.d.ts +2 -16
- package/dist/types/services/auth.d.ts +65 -80
- package/dist/types/services/backups/archive-safety.d.ts +30 -0
- package/dist/types/services/backups/paths.d.ts +31 -0
- package/dist/types/services/backups.d.ts +61 -271
- package/dist/types/services/config-watch.d.ts +3 -15
- package/dist/types/services/control-server.d.ts +6 -10
- package/dist/types/services/ddns.d.ts +12 -13
- package/dist/types/services/dependencies.d.ts +3 -14
- package/dist/types/services/deploy.d.ts +34 -0
- package/dist/types/services/events.d.ts +15 -9
- package/dist/types/services/exposure.d.ts +13 -63
- package/dist/types/services/history.d.ts +5 -14
- package/dist/types/services/host-monitor.d.ts +6 -11
- package/dist/types/services/init.d.ts +5 -35
- package/dist/types/services/job-ledger.d.ts +27 -0
- package/dist/types/services/jobs.d.ts +113 -0
- package/dist/types/services/log-buffer.d.ts +7 -8
- package/dist/types/services/log-files.d.ts +12 -42
- package/dist/types/services/log-relay.d.ts +3 -13
- package/dist/types/services/nanny.d.ts +3 -10
- package/dist/types/services/notifications.d.ts +31 -61
- package/dist/types/services/panel.d.ts +32 -78
- package/dist/types/services/proxy-certificates/certificates.d.ts +31 -69
- package/dist/types/services/proxy-config.d.ts +15 -36
- package/dist/types/services/proxy-dns01.d.ts +14 -0
- package/dist/types/services/proxy.d.ts +73 -254
- package/dist/types/services/scheduler.d.ts +46 -0
- package/dist/types/services/state.d.ts +17 -8
- package/dist/types/services/supervisor/compose.d.ts +2 -6
- package/dist/types/services/supervisor/entry.d.ts +29 -32
- package/dist/types/services/supervisor/health.d.ts +8 -31
- package/dist/types/services/supervisor/job-run.d.ts +36 -0
- package/dist/types/services/supervisor/output.d.ts +13 -77
- package/dist/types/services/supervisor/persistent.d.ts +5 -11
- package/dist/types/services/supervisor/port-preflight.d.ts +4 -10
- package/dist/types/services/supervisor/records.d.ts +27 -60
- package/dist/types/services/supervisor/restart-required.d.ts +13 -0
- package/dist/types/services/supervisor/spawn.d.ts +3 -5
- package/dist/types/services/supervisor/view.d.ts +3 -1
- package/dist/types/services/supervisor.d.ts +31 -43
- package/dist/types/services/tls.d.ts +6 -17
- package/dist/types/services/ui-update.d.ts +19 -17
- package/dist/types/services/ui.d.ts +10 -19
- package/dist/types/shared/action-outcome.d.ts +2 -7
- package/dist/types/shared/api-client.d.ts +133 -177
- package/dist/types/shared/api-scopes.d.ts +17 -0
- package/dist/types/shared/backup-scope.d.ts +16 -90
- package/dist/types/shared/clone.d.ts +2 -11
- package/dist/types/shared/contracts/accounts.d.ts +99 -0
- package/dist/types/shared/contracts/backups.d.ts +219 -0
- package/dist/types/shared/contracts/ddns.d.ts +208 -0
- package/dist/types/shared/contracts/frames.d.ts +1395 -0
- package/dist/types/shared/contracts/index.d.ts +3 -0
- package/dist/types/shared/contracts/logs.d.ts +107 -0
- package/dist/types/shared/contracts/proxy.d.ts +303 -0
- package/dist/types/shared/contracts.d.ts +852 -1982
- package/dist/types/shared/cpu-scale.d.ts +3 -19
- package/dist/types/shared/crash-cause.d.ts +8 -0
- package/dist/types/shared/cron.d.ts +70 -0
- package/dist/types/shared/ddns-form.d.ts +9 -43
- package/dist/types/shared/endpoint.d.ts +1 -7
- package/dist/types/shared/error-codes.d.ts +438 -0
- package/dist/types/shared/error-message.d.ts +1 -7
- package/dist/types/shared/fields.d.ts +7 -17
- package/dist/types/shared/form-repair.d.ts +1 -5
- package/dist/types/shared/generated.d.ts +3 -19
- package/dist/types/shared/host-readings.d.ts +25 -128
- package/dist/types/shared/lazy.d.ts +1 -1
- package/dist/types/shared/live-frames.d.ts +2 -8
- package/dist/types/shared/live-series.d.ts +2 -8
- package/dist/types/shared/live-store.d.ts +4 -8
- package/dist/types/shared/log-download.d.ts +6 -0
- package/dist/types/shared/meta.d.ts +6 -0
- package/dist/types/shared/password-policy.d.ts +10 -0
- package/dist/types/shared/patch-diff.d.ts +13 -72
- package/dist/types/shared/port-reading.d.ts +18 -0
- package/dist/types/shared/probe-latency.d.ts +3 -21
- package/dist/types/shared/proxy-form.d.ts +33 -74
- package/dist/types/shared/proxy-validate.d.ts +11 -0
- package/dist/types/shared/query-params.d.ts +8 -0
- package/dist/types/shared/server-attention.d.ts +2 -27
- package/dist/types/shared/server-form.d.ts +15 -54
- package/dist/types/shared/server-key.d.ts +1 -12
- package/dist/types/shared/server-readings.d.ts +7 -32
- package/dist/types/shared/server-url.d.ts +9 -31
- package/dist/types/shared/shape.d.ts +1 -16
- package/dist/types/shared/stream-access.d.ts +2 -8
- package/dist/types/shared/ui-format.d.ts +25 -65
- package/docs/API.md +315 -107
- package/docs/BACKUPS.md +61 -56
- package/docs/CLI.md +255 -49
- package/docs/DDNS.md +35 -49
- package/docs/JOBS.md +129 -0
- package/docs/NOTIFICATIONS.md +58 -90
- package/docs/REVERSE_PROXY.md +116 -188
- package/docs/SECURITY.md +126 -44
- package/docs/SERVERS.md +282 -409
- package/docs/UI_CREATION.md +90 -47
- package/docs/demo/blank-host-restore.sh +31 -7
- package/package.json +15 -6
- package/scripts/prepare.mjs +47 -0
- package/uis/stock/dist/assets/CopyButton-8mliL0xi.js +1 -0
- package/uis/stock/dist/assets/GlobalSettingsView-BINXY77E.js +1 -0
- package/uis/stock/dist/assets/LogViewer-kiSnTwdY.js +1 -0
- package/uis/stock/dist/assets/LogsView-DDXf_ONs.js +1 -0
- package/uis/stock/dist/assets/Modal-lrUuViF2.js +39 -0
- package/uis/stock/dist/assets/ProxyView-uXMaJdSQ.js +1 -0
- package/uis/stock/dist/assets/ServerDetailView-CW0Vb_c0.js +4 -0
- package/uis/stock/dist/assets/SettingsShell-B135xWjJ.js +1 -0
- package/uis/stock/dist/assets/SettingsView-BLtWxVkl.js +2 -0
- package/uis/stock/dist/assets/de-BIoTrHBQ.js +1 -0
- package/uis/stock/dist/assets/es-x4-ih8lH.js +1 -0
- package/uis/stock/dist/assets/fr-DatqBBkO.js +1 -0
- package/uis/stock/dist/assets/index-CnojaKcA.css +2 -0
- package/uis/stock/dist/assets/index-D-CiZReu.js +16 -0
- package/uis/stock/dist/assets/ja-CW1703Gw.js +1 -0
- package/uis/stock/dist/assets/ko-wFbT4XtK.js +1 -0
- package/uis/stock/dist/assets/ru-C1p5C4VN.js +1 -0
- package/uis/stock/dist/assets/useUnsavedGuard-BcsXsfCC.js +9 -0
- package/uis/stock/dist/assets/vi-CDqr0uie.js +1 -0
- package/uis/stock/dist/assets/zh-CN-BJ7iit-X.js +1 -0
- package/uis/stock/dist/index.html +4 -3
- package/uis/stock/dist/ui.json +3 -3
- package/dist/chunks/archive-DP-XQR8X.js.map +0 -1
- package/dist/chunks/atomic-C1PfJpE7.js.map +0 -1
- package/dist/chunks/backup-CZcVca2a.js.map +0 -1
- package/dist/chunks/backups-CFRaWe_m.js +0 -4691
- package/dist/chunks/backups-CFRaWe_m.js.map +0 -1
- package/dist/chunks/config-text-DifCHhnz.js +0 -50
- package/dist/chunks/config-text-DifCHhnz.js.map +0 -1
- package/dist/chunks/contracts-CMBD1TF9.js.map +0 -1
- package/dist/chunks/daemon-log-BVj8cDEo.js +0 -241
- package/dist/chunks/daemon-log-BVj8cDEo.js.map +0 -1
- package/dist/chunks/daemon-qKVECISl.js +0 -247
- package/dist/chunks/daemon-qKVECISl.js.map +0 -1
- package/dist/chunks/docker-Cy9Lyvda.js.map +0 -1
- package/dist/chunks/down-pKbGCW9d.js.map +0 -1
- package/dist/chunks/init-BZ7hK9Vf.js.map +0 -1
- package/dist/chunks/last-stop-C-BXz_XI.js +0 -53
- package/dist/chunks/last-stop-C-BXz_XI.js.map +0 -1
- package/dist/chunks/layout-DwTtmund.js +0 -24
- package/dist/chunks/layout-DwTtmund.js.map +0 -1
- package/dist/chunks/lazy-Ce5zEAq1.js +0 -66
- package/dist/chunks/lazy-Ce5zEAq1.js.map +0 -1
- package/dist/chunks/log-buffer-Dy9HHDMD.js +0 -414
- package/dist/chunks/log-buffer-Dy9HHDMD.js.map +0 -1
- package/dist/chunks/logger-B5U4GD3j.js.map +0 -1
- package/dist/chunks/logs---TI_bxM.js.map +0 -1
- package/dist/chunks/migrate-Cfoq-Vgh.js +0 -155
- package/dist/chunks/migrate-Cfoq-Vgh.js.map +0 -1
- package/dist/chunks/nanny-B-Eu0sFW.js.map +0 -1
- package/dist/chunks/nanny-BtWfy0QH.js +0 -1167
- package/dist/chunks/nanny-BtWfy0QH.js.map +0 -1
- package/dist/chunks/nanny-sweep-DErnlPY1.js.map +0 -1
- package/dist/chunks/nearest-6KgQEDUe.js.map +0 -1
- package/dist/chunks/parse-DhmG26fI.js.map +0 -1
- package/dist/chunks/paths-CGlGDrOU.js.map +0 -1
- package/dist/chunks/port-B8WBTRMk.js.map +0 -1
- package/dist/chunks/restart-Des4DrAN.js.map +0 -1
- package/dist/chunks/schema-B240VXcV.js.map +0 -1
- package/dist/chunks/secrets-BieELnZh.js +0 -562
- package/dist/chunks/secrets-BieELnZh.js.map +0 -1
- package/dist/chunks/server-Bge2r2qQ.js +0 -169
- package/dist/chunks/server-Bge2r2qQ.js.map +0 -1
- package/dist/chunks/server-ids-DRuNLVCV.js +0 -32
- package/dist/chunks/server-ids-DRuNLVCV.js.map +0 -1
- package/dist/chunks/set-password-D5vZqqSX.js +0 -43
- package/dist/chunks/set-password-D5vZqqSX.js.map +0 -1
- package/dist/chunks/set-token-obPiEJYk.js +0 -78
- package/dist/chunks/set-token-obPiEJYk.js.map +0 -1
- package/dist/chunks/settings-xu-XTfWg.js.map +0 -1
- package/dist/chunks/setup-temp-CAN4_bA-.js.map +0 -1
- package/dist/chunks/shape-DnTKzjQ2.js +0 -24
- package/dist/chunks/shape-DnTKzjQ2.js.map +0 -1
- package/dist/chunks/src-BtWMFmzZ.js.map +0 -1
- package/dist/chunks/status-DT1EsA-B.js.map +0 -1
- package/dist/chunks/ui-D562aqw5.js.map +0 -1
- package/dist/chunks/ui-dir-CsU3uLNV.js.map +0 -1
- package/dist/chunks/ui-release-DKzVvlLd.js.map +0 -1
- package/dist/chunks/ui-revert-EkBBwRTt.js.map +0 -1
- package/dist/chunks/ui-switch-BnZTdMDd.js.map +0 -1
- package/dist/chunks/ui-update-_xryLYxw.js.map +0 -1
- package/dist/chunks/up-Pdz-l6IH.js.map +0 -1
- package/dist/chunks/usage-DFrCVXpT.js.map +0 -1
- package/dist/chunks/workspaces-DYcfvKV_.js.map +0 -1
- package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +0 -1
- package/dist/types/cli/set-password.d.ts +0 -14
- package/dist/types/cli/set-token.d.ts +0 -21
- package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +0 -1
- package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +0 -1
- package/uis/stock/dist/assets/LogViewer-DIliXy62.js +0 -1
- package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +0 -1
- package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +0 -39
- package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +0 -1
- package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +0 -2
- package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +0 -1
- package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +0 -2
- package/uis/stock/dist/assets/de-BRITeb0H.js +0 -1
- package/uis/stock/dist/assets/es-B2zIEssV.js +0 -1
- package/uis/stock/dist/assets/fr-s0ZOBEqh.js +0 -1
- package/uis/stock/dist/assets/index-C1MehbKy.css +0 -2
- package/uis/stock/dist/assets/index-CnBN54wF.js +0 -15
- package/uis/stock/dist/assets/ja-CU7MR85V.js +0 -1
- package/uis/stock/dist/assets/ko-tL5Me6d-.js +0 -1
- package/uis/stock/dist/assets/ru-92yrvkNJ.js +0 -1
- package/uis/stock/dist/assets/vi-CzvY16k2.js +0 -1
- package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +0 -1
|
@@ -1,1167 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import "../cli.js";
|
|
3
|
-
import { f as projectDir } from "./paths-CGlGDrOU.js";
|
|
4
|
-
import { t as writeFileAtomic } from "./atomic-C1PfJpE7.js";
|
|
5
|
-
import { M as nannySpecSchema, N as nannyStateSchema } from "./contracts-CMBD1TF9.js";
|
|
6
|
-
import { c as processLiveness, r as isProcessAlive } from "./port-B8WBTRMk.js";
|
|
7
|
-
import process from "node:process";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
import { type } from "arktype";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import { execFile, spawn } from "node:child_process";
|
|
13
|
-
import { promisify } from "node:util";
|
|
14
|
-
//#region src/providers/proc.ts
|
|
15
|
-
var execFileAsync$2 = promisify(execFile);
|
|
16
|
-
function parsePsOutput(text) {
|
|
17
|
-
const rows = [];
|
|
18
|
-
for (const line of text.split("\n")) {
|
|
19
|
-
const parts = line.trim().split(/\s+/);
|
|
20
|
-
if (parts.length < 4) continue;
|
|
21
|
-
const [pid, ppid, rss, cpu] = parts.map((entry) => Number.parseFloat(entry));
|
|
22
|
-
if (pid === void 0 || ppid === void 0 || rss === void 0 || !Number.isFinite(pid)) continue;
|
|
23
|
-
rows.push({
|
|
24
|
-
pid,
|
|
25
|
-
ppid,
|
|
26
|
-
rssKb: rss,
|
|
27
|
-
cpuPercent: Number.isFinite(cpu) ? cpu : void 0
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return rows;
|
|
31
|
-
}
|
|
32
|
-
/** CSV from `Get-CimInstance ... | ConvertTo-Csv`, or wmic's `/format:csv`. */
|
|
33
|
-
function parseWindowsCsv(text) {
|
|
34
|
-
const rows = [];
|
|
35
|
-
const lines = text.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
36
|
-
const header = lines.shift();
|
|
37
|
-
if (header === void 0) return rows;
|
|
38
|
-
const columns = header.split(",").map((entry) => entry.replace(/"/g, "").trim().toLowerCase());
|
|
39
|
-
const index = (name) => columns.indexOf(name.toLowerCase());
|
|
40
|
-
const pidAt = index("ProcessId");
|
|
41
|
-
const ppidAt = index("ParentProcessId");
|
|
42
|
-
const rssAt = index("WorkingSetSize");
|
|
43
|
-
const kernelAt = index("KernelModeTime");
|
|
44
|
-
const userAt = index("UserModeTime");
|
|
45
|
-
for (const line of lines) {
|
|
46
|
-
const cells = line.split(",").map((entry) => entry.replace(/"/g, "").trim());
|
|
47
|
-
const pid = Number.parseInt(cells[pidAt] ?? "", 10);
|
|
48
|
-
if (!Number.isFinite(pid)) continue;
|
|
49
|
-
const kernel = kernelAt >= 0 ? Number.parseInt(cells[kernelAt] ?? "", 10) : NaN;
|
|
50
|
-
const user = userAt >= 0 ? Number.parseInt(cells[userAt] ?? "", 10) : NaN;
|
|
51
|
-
const hasTimes = Number.isFinite(kernel) && Number.isFinite(user);
|
|
52
|
-
rows.push({
|
|
53
|
-
pid,
|
|
54
|
-
ppid: Number.parseInt(cells[ppidAt] ?? "", 10) || 0,
|
|
55
|
-
rssKb: (Number.parseInt(cells[rssAt] ?? "", 10) || 0) / 1024,
|
|
56
|
-
cpuSeconds: hasTimes ? (kernel + user) / 1e7 : void 0
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return rows;
|
|
60
|
-
}
|
|
61
|
-
var clockTicks = null;
|
|
62
|
-
var pageKb = null;
|
|
63
|
-
/** The kernel page size in kB (4 on x86, often 16 or 64 on arm64), read once. */
|
|
64
|
-
async function getPageKb() {
|
|
65
|
-
if (pageKb !== null) return pageKb;
|
|
66
|
-
try {
|
|
67
|
-
const { stdout } = await execFileAsync$2("getconf", ["PAGESIZE"], { timeout: 2e3 });
|
|
68
|
-
const bytes = Number.parseInt(stdout.trim(), 10);
|
|
69
|
-
pageKb = Number.isFinite(bytes) && bytes > 0 ? bytes / 1024 : 4;
|
|
70
|
-
} catch {
|
|
71
|
-
pageKb = 4;
|
|
72
|
-
}
|
|
73
|
-
return pageKb;
|
|
74
|
-
}
|
|
75
|
-
/** Linux jiffies per second; `getconf` is POSIX, with the usual default behind it. */
|
|
76
|
-
async function getClockTicks() {
|
|
77
|
-
if (clockTicks !== null) return clockTicks;
|
|
78
|
-
try {
|
|
79
|
-
const { stdout } = await execFileAsync$2("getconf", ["CLK_TCK"], { timeout: 2e3 });
|
|
80
|
-
const parsed = Number.parseInt(stdout.trim(), 10);
|
|
81
|
-
clockTicks = Number.isFinite(parsed) && parsed > 0 ? parsed : 100;
|
|
82
|
-
} catch {
|
|
83
|
-
clockTicks = 100;
|
|
84
|
-
}
|
|
85
|
-
return clockTicks;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* `/proc/<pid>/stat` needs care: the comm field is parenthesised and may itself
|
|
89
|
-
* contain spaces or parentheses, so parsing starts after the last `)`.
|
|
90
|
-
*/
|
|
91
|
-
function parseStat(pid, content, pageSizeKb = 4) {
|
|
92
|
-
const close = content.lastIndexOf(")");
|
|
93
|
-
if (close < 0) return null;
|
|
94
|
-
const fields = content.slice(close + 2).split(" ");
|
|
95
|
-
const ppid = Number.parseInt(fields[1] ?? "", 10);
|
|
96
|
-
const utime = Number.parseInt(fields[11] ?? "", 10);
|
|
97
|
-
const stime = Number.parseInt(fields[12] ?? "", 10);
|
|
98
|
-
const rssPages = Number.parseInt(fields[21] ?? "", 10);
|
|
99
|
-
if (!Number.isFinite(ppid) || !Number.isFinite(utime) || !Number.isFinite(stime)) return null;
|
|
100
|
-
return {
|
|
101
|
-
pid,
|
|
102
|
-
ppid,
|
|
103
|
-
rssKb: Number.isFinite(rssPages) ? rssPages * pageSizeKb : 0,
|
|
104
|
-
cpuSeconds: utime + stime
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Processes read between two turns of the event loop, so a large host never stalls it. */
|
|
108
|
-
var SCAN_BATCH = 64;
|
|
109
|
-
async function readLinux() {
|
|
110
|
-
const rows = [];
|
|
111
|
-
let names = [];
|
|
112
|
-
try {
|
|
113
|
-
names = fs.readdirSync("/proc");
|
|
114
|
-
} catch {
|
|
115
|
-
return rows;
|
|
116
|
-
}
|
|
117
|
-
const pageSizeKb = await getPageKb();
|
|
118
|
-
let read = 0;
|
|
119
|
-
for (const name of names) {
|
|
120
|
-
if (!/^\d+$/.test(name)) continue;
|
|
121
|
-
const pid = Number.parseInt(name, 10);
|
|
122
|
-
try {
|
|
123
|
-
const row = parseStat(pid, fs.readFileSync(`/proc/${pid}/stat`, "utf8"), pageSizeKb);
|
|
124
|
-
if (row !== null) rows.push(row);
|
|
125
|
-
} catch {}
|
|
126
|
-
if (++read % SCAN_BATCH === 0) await new Promise((resolve) => setImmediate(resolve));
|
|
127
|
-
}
|
|
128
|
-
return rows;
|
|
129
|
-
}
|
|
130
|
-
async function readPosix() {
|
|
131
|
-
const { stdout } = await execFileAsync$2("ps", ["-Ao", "pid=,ppid=,rss=,%cpu="], {
|
|
132
|
-
timeout: 5e3,
|
|
133
|
-
maxBuffer: 16777216
|
|
134
|
-
});
|
|
135
|
-
return parsePsOutput(stdout);
|
|
136
|
-
}
|
|
137
|
-
async function readWindows() {
|
|
138
|
-
const script = "Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,WorkingSetSize,KernelModeTime,UserModeTime | ConvertTo-Csv -NoTypeInformation";
|
|
139
|
-
try {
|
|
140
|
-
const { stdout } = await execFileAsync$2("powershell.exe", [
|
|
141
|
-
"-NoProfile",
|
|
142
|
-
"-NonInteractive",
|
|
143
|
-
"-Command",
|
|
144
|
-
script
|
|
145
|
-
], {
|
|
146
|
-
timeout: 8e3,
|
|
147
|
-
maxBuffer: 16777216
|
|
148
|
-
});
|
|
149
|
-
return parseWindowsCsv(stdout);
|
|
150
|
-
} catch {
|
|
151
|
-
try {
|
|
152
|
-
const { stdout } = await execFileAsync$2("wmic", [
|
|
153
|
-
"process",
|
|
154
|
-
"get",
|
|
155
|
-
"ProcessId,ParentProcessId,WorkingSetSize,KernelModeTime,UserModeTime",
|
|
156
|
-
"/format:csv"
|
|
157
|
-
], {
|
|
158
|
-
timeout: 8e3,
|
|
159
|
-
maxBuffer: 16777216
|
|
160
|
-
});
|
|
161
|
-
return parseWindowsCsv(stdout);
|
|
162
|
-
} catch {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
var scans = 0;
|
|
168
|
-
function scanProcesses() {
|
|
169
|
-
scans += 1;
|
|
170
|
-
if (process.platform === "linux") return readLinux();
|
|
171
|
-
if (process.platform === "win32") return readWindows();
|
|
172
|
-
return readPosix();
|
|
173
|
-
}
|
|
174
|
-
var lastScan = null;
|
|
175
|
-
/**
|
|
176
|
-
* The process table. `reuseMs` lets a caller accept a scan that is in flight or that recent — the
|
|
177
|
-
* resource samplers do, because every workspace has one and entries come due on their own second,
|
|
178
|
-
* so one tick could otherwise walk `/proc` (or spawn PowerShell) once per workspace per due entry.
|
|
179
|
-
* Anything deciding *ownership* passes 0: a process spawned a moment ago must be in its answer.
|
|
180
|
-
*/
|
|
181
|
-
function readProcesses(now = Date.now(), reuseMs = 0) {
|
|
182
|
-
if (reuseMs > 0 && lastScan !== null && now - lastScan.at < reuseMs) return lastScan.scan;
|
|
183
|
-
const scan = scanProcesses().then((rows) => ({
|
|
184
|
-
at: now,
|
|
185
|
-
rows
|
|
186
|
-
}));
|
|
187
|
-
lastScan = {
|
|
188
|
-
at: now,
|
|
189
|
-
scan
|
|
190
|
-
};
|
|
191
|
-
scan.catch(() => {
|
|
192
|
-
if (lastScan?.scan === scan) lastScan = null;
|
|
193
|
-
});
|
|
194
|
-
return scan;
|
|
195
|
-
}
|
|
196
|
-
function collectTree(rootPid, children) {
|
|
197
|
-
const pids = [];
|
|
198
|
-
const stack = [rootPid];
|
|
199
|
-
const seen = /* @__PURE__ */ new Set();
|
|
200
|
-
while (stack.length > 0) {
|
|
201
|
-
const pid = stack.pop();
|
|
202
|
-
if (seen.has(pid)) continue;
|
|
203
|
-
seen.add(pid);
|
|
204
|
-
pids.push(pid);
|
|
205
|
-
for (const child of children.get(pid) ?? []) stack.push(child);
|
|
206
|
-
}
|
|
207
|
-
return pids;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* CPU time a tree used over one interval, from per-pid cumulative counters.
|
|
211
|
-
*
|
|
212
|
-
* Pure, and separated from the scan because this is where both CPU bugs lived — and a scan of the
|
|
213
|
-
* live process table cannot pin arithmetic that depends on a child appearing or vanishing between
|
|
214
|
-
* two reads.
|
|
215
|
-
*
|
|
216
|
-
* `previous` is the **whole process table** of the prior scan, not just this tree: that is what
|
|
217
|
-
* lets a process which joins the tree later be charged only its interval, and what the caller
|
|
218
|
-
* guarantees.
|
|
219
|
-
*
|
|
220
|
-
* Three rules make the answer a real interval:
|
|
221
|
-
*
|
|
222
|
-
* - A pid in both maps contributes the difference. `next >= previous` is required: a recycled pid
|
|
223
|
-
* reports less than the process that used to hold it, and that is not a delta.
|
|
224
|
-
* - A pid only in `next` was **born inside the window**, so its whole counter accrued in it.
|
|
225
|
-
* - A pid only in `previous` **exited inside the window**; its time is already accounted for by the
|
|
226
|
-
* samples where it was alive, and it contributes nothing. The old code summed the tree on both
|
|
227
|
-
* sides, so an exit made the total *drop*, the delta went negative and the reading was discarded
|
|
228
|
-
* — the gap. Summing only pids present in `next` is what removes it.
|
|
229
|
-
*
|
|
230
|
-
* `null` when the map has nothing usable, so a caller reports "unknown" instead of `0`.
|
|
231
|
-
*/
|
|
232
|
-
function treeCpuUsedSeconds(previous, next, treePids) {
|
|
233
|
-
let used = 0;
|
|
234
|
-
let sawAny = false;
|
|
235
|
-
for (const pid of treePids) {
|
|
236
|
-
const current = next.get(pid);
|
|
237
|
-
if (current === void 0) continue;
|
|
238
|
-
const before = previous.get(pid);
|
|
239
|
-
if (before === void 0) {
|
|
240
|
-
used += current;
|
|
241
|
-
sawAny = true;
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (current >= before) {
|
|
245
|
-
used += current - before;
|
|
246
|
-
sawAny = true;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return sawAny ? used : null;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* The same walk, keeping *which root* each pid belongs to.
|
|
253
|
-
*
|
|
254
|
-
* A refusal has to name the server to go and stop, and a pid on its own is not that: the panel
|
|
255
|
-
* supervised 14 entries and told the operator "held by pid 135113, which this panel supervises —
|
|
256
|
-
* stop that server instead", with no way to tell which of the 14 it meant. The tree loses that
|
|
257
|
-
* fact, so the attribution is collected here, where the walk already happens, rather than by a
|
|
258
|
-
* second scan.
|
|
259
|
-
*
|
|
260
|
-
* Ownership has to mean the *tree*: a persistent entry runs under a nanny, and a wrapper entry
|
|
261
|
-
* spawns the real server one generation down. Both keep the pid the panel recorded, but the process
|
|
262
|
-
* holding the port is a descendant of it — and a descendant classified as a stranger is one
|
|
263
|
-
* `kill`/`free-port` away from stopping a server this panel is responsible for.
|
|
264
|
-
*
|
|
265
|
-
* A backend that cannot run answers with the roots alone, which is the old, narrower behaviour
|
|
266
|
-
* rather than a wrong one.
|
|
267
|
-
*
|
|
268
|
-
* When two roots are nested, the ancestor keeps the pid: it is the older claim and still true.
|
|
269
|
-
*/
|
|
270
|
-
async function processTreeOwners(roots) {
|
|
271
|
-
const owners = /* @__PURE__ */ new Map();
|
|
272
|
-
for (const root of roots) if (!owners.has(root)) owners.set(root, root);
|
|
273
|
-
if (roots.length === 0) return owners;
|
|
274
|
-
try {
|
|
275
|
-
const { rows } = await readProcesses();
|
|
276
|
-
const children = /* @__PURE__ */ new Map();
|
|
277
|
-
for (const row of rows) {
|
|
278
|
-
const siblings = children.get(row.ppid) ?? [];
|
|
279
|
-
siblings.push(row.pid);
|
|
280
|
-
children.set(row.ppid, siblings);
|
|
281
|
-
}
|
|
282
|
-
for (const root of roots) for (const pid of collectTree(root, children)) if (!owners.has(pid)) owners.set(pid, root);
|
|
283
|
-
} catch {}
|
|
284
|
-
return owners;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Samples CPU and RSS for a process *and its descendants*.
|
|
288
|
-
*
|
|
289
|
-
* Descendants matter: a wrapper that spawns the real server detached owns the
|
|
290
|
-
* tree, and only the tree's RSS means anything.
|
|
291
|
-
*
|
|
292
|
-
* Backends: `/proc` on Linux, `ps` on macOS/other POSIX, and Win32_Process via
|
|
293
|
-
* PowerShell (wmic as a fallback) on Windows. When a backend cannot run, samples
|
|
294
|
-
* are null rather than wrong.
|
|
295
|
-
*/
|
|
296
|
-
var ProcessSampler = class {
|
|
297
|
-
reuseMs;
|
|
298
|
-
/** `reuseMs`: accept a process scan this recent from any sampler (0 = always scan fresh). */
|
|
299
|
-
constructor(reuseMs = 0) {
|
|
300
|
-
this.reuseMs = reuseMs;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Cumulative CPU seconds per pid, from the **whole process table** of the last scan.
|
|
304
|
-
*
|
|
305
|
-
* A tree is not a fixed set of processes: a wrapper spawns and reaps children continuously, so
|
|
306
|
-
* "the sum over whatever is in the tree now" is not comparable with the previous sum. Measuring
|
|
307
|
-
* that rule against a wrapper respawning a 1.5 s worker, **two samples in every three were
|
|
308
|
-
* discarded**: the child's exit made the sum drop, the delta went negative, and the reading was
|
|
309
|
-
* thrown away — the gaps a person sees on a live server.
|
|
310
|
-
*
|
|
311
|
-
* Baselining every pid the scan saw, rather than only the tree's, is what makes each delta a
|
|
312
|
-
* real interval. A process that was already running has a previous counter even if it only
|
|
313
|
-
* joined this tree afterwards, so it cannot be charged its whole lifetime; and a pid absent from
|
|
314
|
-
* the previous scan was born inside the window, so its counter really did accrue in it.
|
|
315
|
-
*/
|
|
316
|
-
previousTable = null;
|
|
317
|
-
/**
|
|
318
|
-
* Roots whose next sample must not be differenced, stamped with when they were forgotten.
|
|
319
|
-
*
|
|
320
|
-
* `forget` is called when an entry stops, exits or is restarted: the pid is gone, so the reading
|
|
321
|
-
* after it must be `null` rather than a delta against a previous life. The baseline is one table
|
|
322
|
-
* for the whole scan, so this is the per-root suppression. Pruned at each scan, which bounds it
|
|
323
|
-
* to the restarts that happened since the last one.
|
|
324
|
-
*/
|
|
325
|
-
forgotten = /* @__PURE__ */ new Map();
|
|
326
|
-
/** Each root's latest reading, answered again when the only scan available is one already used. */
|
|
327
|
-
lastReadings = /* @__PURE__ */ new Map();
|
|
328
|
-
async sample(rootPid, now = Date.now()) {
|
|
329
|
-
return (await this.sampleMany([rootPid], now)).get(rootPid) ?? null;
|
|
330
|
-
}
|
|
331
|
-
async sampleMany(rootPids, now = Date.now()) {
|
|
332
|
-
const results = /* @__PURE__ */ new Map();
|
|
333
|
-
if (rootPids.length === 0) return results;
|
|
334
|
-
let rows = [];
|
|
335
|
-
let scannedAt = now;
|
|
336
|
-
try {
|
|
337
|
-
const scan = await readProcesses(now, this.reuseMs);
|
|
338
|
-
rows = scan.rows;
|
|
339
|
-
scannedAt = scan.at;
|
|
340
|
-
} catch {
|
|
341
|
-
rows = [];
|
|
342
|
-
}
|
|
343
|
-
if (this.previousTable !== null && this.previousTable.at === scannedAt && rows.length > 0) {
|
|
344
|
-
for (const rootPid of rootPids) results.set(rootPid, this.lastReadings.get(rootPid) ?? null);
|
|
345
|
-
return results;
|
|
346
|
-
}
|
|
347
|
-
const byPid = new Map(rows.map((row) => [row.pid, row]));
|
|
348
|
-
const children = /* @__PURE__ */ new Map();
|
|
349
|
-
for (const row of rows) {
|
|
350
|
-
const siblings = children.get(row.ppid) ?? [];
|
|
351
|
-
siblings.push(row.pid);
|
|
352
|
-
children.set(row.ppid, siblings);
|
|
353
|
-
}
|
|
354
|
-
const before = this.previousTable;
|
|
355
|
-
const elapsedSeconds = before === null ? 0 : (scannedAt - before.at) / 1e3;
|
|
356
|
-
const ticks = process.platform === "linux" ? await getClockTicks() : 1;
|
|
357
|
-
const tableCpuSeconds = /* @__PURE__ */ new Map();
|
|
358
|
-
for (const row of rows) if (row.cpuSeconds !== void 0) tableCpuSeconds.set(row.pid, row.cpuSeconds / ticks);
|
|
359
|
-
for (const rootPid of rootPids) {
|
|
360
|
-
if (!byPid.has(rootPid)) {
|
|
361
|
-
results.set(rootPid, null);
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
const wasForgotten = this.forgotten.delete(rootPid);
|
|
365
|
-
const pids = collectTree(rootPid, children);
|
|
366
|
-
let rssKb = 0;
|
|
367
|
-
let percentAverage = null;
|
|
368
|
-
const treeSeconds = /* @__PURE__ */ new Map();
|
|
369
|
-
for (const pid of pids) {
|
|
370
|
-
const row = byPid.get(pid);
|
|
371
|
-
if (!row) continue;
|
|
372
|
-
rssKb += row.rssKb;
|
|
373
|
-
if (row.cpuPercent !== void 0) percentAverage = (percentAverage ?? 0) + row.cpuPercent;
|
|
374
|
-
if (row.cpuSeconds !== void 0) treeSeconds.set(pid, row.cpuSeconds / ticks);
|
|
375
|
-
}
|
|
376
|
-
const usedSeconds = before === null ? null : treeCpuUsedSeconds(before.cpuSeconds, treeSeconds, pids);
|
|
377
|
-
let cpuPercent = percentAverage;
|
|
378
|
-
if (cpuPercent === null && !wasForgotten && usedSeconds !== null && elapsedSeconds > 0) cpuPercent = usedSeconds / elapsedSeconds * 100;
|
|
379
|
-
results.set(rootPid, {
|
|
380
|
-
cpuPercent: cpuPercent === null ? null : Math.round(cpuPercent * 10) / 10,
|
|
381
|
-
rssBytes: Math.round(rssKb * 1024),
|
|
382
|
-
processes: pids.length,
|
|
383
|
-
sampledAt: scannedAt
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
this.previousTable = {
|
|
387
|
-
at: scannedAt,
|
|
388
|
-
cpuSeconds: tableCpuSeconds
|
|
389
|
-
};
|
|
390
|
-
for (const [pid, reading] of results) if (reading !== null) this.lastReadings.set(pid, reading);
|
|
391
|
-
else this.lastReadings.delete(pid);
|
|
392
|
-
return results;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Marks a root's next reading as the first of a new life.
|
|
396
|
-
*
|
|
397
|
-
* Called when an entry stops, exits or is restarted. Without it a recycled pid — or the very
|
|
398
|
-
* next sample of the same root — would be differenced against a counter from the previous run,
|
|
399
|
-
* which is not an interval. The scan-wide table cannot be cleared per root, so the suppression
|
|
400
|
-
* is remembered here and consumed by that root's next sample.
|
|
401
|
-
*/
|
|
402
|
-
forget(rootPid) {
|
|
403
|
-
this.lastReadings.delete(rootPid);
|
|
404
|
-
this.forgotten.set(rootPid, Date.now());
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* Does this process carry the environment the supervisor gave the entry?
|
|
409
|
-
*
|
|
410
|
-
* A program that restarts itself — especially a plugin doing it — leaves behind a
|
|
411
|
-
* detached process that still inherits `HHOSTED_SERVER_ID`, and that marker is what
|
|
412
|
-
* tells a legitimate successor apart from a stranger squatting on the port.
|
|
413
|
-
*
|
|
414
|
-
* Linux reads `/proc`; macOS asks `ps -E`; Windows has no per-process environment,
|
|
415
|
-
* so the answer is always "no" there and ownership falls back to the port policy.
|
|
416
|
-
*/
|
|
417
|
-
async function processCarriesServerId(pid, serverId) {
|
|
418
|
-
if (serverId.length === 0) return false;
|
|
419
|
-
const needle = `HHOSTED_SERVER_ID=${serverId}`;
|
|
420
|
-
if (process.platform === "linux") try {
|
|
421
|
-
return (await fs.promises.readFile(`/proc/${pid}/environ`, "utf8")).split("\0").includes(needle);
|
|
422
|
-
} catch {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
if (process.platform === "darwin") try {
|
|
426
|
-
const { stdout } = await execFileAsync$2("ps", [
|
|
427
|
-
"-p",
|
|
428
|
-
String(pid),
|
|
429
|
-
"-E",
|
|
430
|
-
"-ww",
|
|
431
|
-
"-o",
|
|
432
|
-
"command="
|
|
433
|
-
], { timeout: 3e3 });
|
|
434
|
-
return new RegExp(`(?:^|\\s)${needle}(?:\\s|$)`).test(stdout);
|
|
435
|
-
} catch {
|
|
436
|
-
return false;
|
|
437
|
-
}
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/providers/identity.ts
|
|
442
|
-
var execFileAsync$1 = promisify(execFile);
|
|
443
|
-
/**
|
|
444
|
-
* Splits a command line into words, undoing the quoting Windows put there. `CommandLine`
|
|
445
|
-
* is the raw string from the spawn call, so `"C:\a b\x.cmd" /c` is one argv entry plus
|
|
446
|
-
* two words, and a quoted argument that contains spaces has to come back as one word.
|
|
447
|
-
*
|
|
448
|
-
* Windows also *escapes* a quote inside an argument as `\"` (Node does this for any argv
|
|
449
|
-
* containing a quote), so the escape is undone here — otherwise every argument with a
|
|
450
|
-
* quote in it survives as a stray backslash and never matches what the panel spawned.
|
|
451
|
-
*/
|
|
452
|
-
function splitCommandLine(line) {
|
|
453
|
-
const words = [];
|
|
454
|
-
let current = "";
|
|
455
|
-
let quoted = false;
|
|
456
|
-
let started = false;
|
|
457
|
-
const chars = [...line.trim()];
|
|
458
|
-
for (let index = 0; index < chars.length; index += 1) {
|
|
459
|
-
const char = chars[index];
|
|
460
|
-
if (char === "\\") {
|
|
461
|
-
let run = 0;
|
|
462
|
-
while (chars[index + run] === "\\") run += 1;
|
|
463
|
-
if (chars[index + run] !== "\"") {
|
|
464
|
-
current += "\\".repeat(run);
|
|
465
|
-
started = true;
|
|
466
|
-
index += run - 1;
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
current += "\\".repeat(Math.floor(run / 2));
|
|
470
|
-
started = true;
|
|
471
|
-
if (run % 2 === 1) {
|
|
472
|
-
current += "\"";
|
|
473
|
-
index += run;
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
quoted = !quoted;
|
|
477
|
-
index += run;
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
if (char === "\"") {
|
|
481
|
-
quoted = !quoted;
|
|
482
|
-
started = true;
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (!quoted && /\s/.test(char)) {
|
|
486
|
-
if (started) words.push(current);
|
|
487
|
-
current = "";
|
|
488
|
-
started = false;
|
|
489
|
-
continue;
|
|
490
|
-
}
|
|
491
|
-
current += char;
|
|
492
|
-
started = true;
|
|
493
|
-
}
|
|
494
|
-
if (started) words.push(current);
|
|
495
|
-
return words;
|
|
496
|
-
}
|
|
497
|
-
function comparable(target) {
|
|
498
|
-
const value = target.replace(/^"(.*)"$/, "$1").replace(/\\(?=")/g, "");
|
|
499
|
-
return process.platform === "win32" ? value.toLowerCase() : value;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Literal comparison for an argument: the same text, modulo the case folding Windows needs
|
|
503
|
-
* and the quoting a command line shuffles around.
|
|
504
|
-
*
|
|
505
|
-
* Deliberately *not* `sameWord`: folding an argument to its basename would let this
|
|
506
|
-
* entry's `/srv/web/build/server.js` equal a stranger's `/tmp/evil/build/server.js`, and a
|
|
507
|
-
* match here is what `reclaim` kills. Nor is it a plain string equality: reading an argv
|
|
508
|
-
* back out of a Windows `CommandLine` cannot preserve quotes exactly — the OS escapes an
|
|
509
|
-
* argument's own quote as `\"` and strips the structural ones — so quotes and backslashes
|
|
510
|
-
* are dropped from both sides. That leaves the arguments' actual text, which is what the
|
|
511
|
-
* match is about.
|
|
512
|
-
*/
|
|
513
|
-
function sameArg(a, b) {
|
|
514
|
-
const normalize = (value) => comparable(value).replace(/["\\]/g, "");
|
|
515
|
-
return normalize(a) === normalize(b);
|
|
516
|
-
}
|
|
517
|
-
/** Whether a value names a file with no directory part, under either platform's separator. */
|
|
518
|
-
function isBare(value) {
|
|
519
|
-
return !value.includes("/") && !value.includes("\\");
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* The same file spelled differently compares equal — but only while one of the two spellings is a
|
|
523
|
-
* bare name, which is the case the fallback exists for: the config says `node` and the process table
|
|
524
|
-
* reports `/usr/bin/node`, or the reverse on Windows.
|
|
525
|
-
*
|
|
526
|
-
* When **both** spellings name a directory, they are two different files. Comparing basenames
|
|
527
|
-
* unconditionally made `/tmp/evil/server.js` match `/srv/web/server.js`, and a false match here is
|
|
528
|
-
* not cosmetic: the panel would treat a process it never spawned as its own entry, so `follow` adopts
|
|
529
|
-
* a stranger and `reclaim`/`kill` may remove one.
|
|
530
|
-
*/
|
|
531
|
-
function sameWord(a, b) {
|
|
532
|
-
const left = comparable(a);
|
|
533
|
-
const right = comparable(b);
|
|
534
|
-
if (left === right) return true;
|
|
535
|
-
if (!isBare(left) && !isBare(right)) return false;
|
|
536
|
-
return path.basename(left) === path.basename(right) || path.extname(b) === "" && path.basename(left, path.extname(left)) === right || path.extname(a) === "" && path.basename(right, path.extname(right)) === left;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* True when the argv a process is running is the entry's own: the image must match where
|
|
540
|
-
* `spawn` would have looked it up — the image Path, or the first word of the command line
|
|
541
|
-
* — and the words after it must open with the entry's args, compared literally. So
|
|
542
|
-
* `spawn --port 4000` also covers `spawn -p 4000 --extra`, which is what a self-restarting
|
|
543
|
-
* wrapper does, while `/tmp/evil/server.js` never covers `/srv/web/server.js` — two paths that name
|
|
544
|
-
* a directory are different files, and the basename fallback applies only while one spelling is bare
|
|
545
|
-
* (see `sameWord`).
|
|
546
|
-
*
|
|
547
|
-
* `words` must already be the process's own argv. A command-line *string* is only correct
|
|
548
|
-
* on Windows, where the OS hands one out; `/proc/<pid>/cmdline` quotes are literal bytes
|
|
549
|
-
* of an argument, so re-joining that argv into one string corrupts it.
|
|
550
|
-
*/
|
|
551
|
-
function matchesSpawn(info, spawn) {
|
|
552
|
-
const { words } = info;
|
|
553
|
-
const first = words[0] ?? "";
|
|
554
|
-
if (!(sameWord(first, spawn.command) || info.imagePath != null && info.imagePath !== "" && sameWord(info.imagePath, spawn.command))) return false;
|
|
555
|
-
const offset = sameWord(first, spawn.command) ? 1 : 0;
|
|
556
|
-
if (words.length < spawn.args.length + offset) return false;
|
|
557
|
-
return spawn.args.every((arg, index) => sameArg(words[index + offset], arg));
|
|
558
|
-
}
|
|
559
|
-
/** The argv of a pid on the platforms whose process table can answer it; null otherwise. */
|
|
560
|
-
async function processArgv(pid) {
|
|
561
|
-
if (process.platform === "win32") return null;
|
|
562
|
-
if (process.platform === "linux") try {
|
|
563
|
-
const words = (await fs.promises.readFile(`/proc/${pid}/cmdline`)).toString("utf8").split("\0");
|
|
564
|
-
if (words.at(-1) === "") words.pop();
|
|
565
|
-
return words.length > 0 ? words : null;
|
|
566
|
-
} catch {
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
569
|
-
try {
|
|
570
|
-
const { stdout } = await execFileAsync$1("ps", [
|
|
571
|
-
"-p",
|
|
572
|
-
String(pid),
|
|
573
|
-
"-ww",
|
|
574
|
-
"-o",
|
|
575
|
-
"command="
|
|
576
|
-
], { timeout: 3e3 });
|
|
577
|
-
const words = splitCommandLine(stdout.trim());
|
|
578
|
-
return words.length > 0 ? words : null;
|
|
579
|
-
} catch {
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
var windowsFilter = /^\d+$/;
|
|
584
|
-
/**
|
|
585
|
-
* The first two rows of `ConvertTo-Csv` output: the header and the first record. PowerShell
|
|
586
|
-
* quotes and doubles its way around CSV, so `a,"b""c"` is three fields with the second
|
|
587
|
-
* reading `b"c`.
|
|
588
|
-
*/
|
|
589
|
-
function parseCsvRows(output) {
|
|
590
|
-
const rows = [];
|
|
591
|
-
let row = [];
|
|
592
|
-
let field = "";
|
|
593
|
-
let quoted = false;
|
|
594
|
-
for (let index = 0; index < output.length; index++) {
|
|
595
|
-
const char = output[index];
|
|
596
|
-
if (quoted) {
|
|
597
|
-
if (char !== "\"") {
|
|
598
|
-
field += char;
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
if (output[index + 1] === "\"") {
|
|
602
|
-
field += "\"";
|
|
603
|
-
index++;
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
quoted = false;
|
|
607
|
-
continue;
|
|
608
|
-
}
|
|
609
|
-
if (char === "\"") {
|
|
610
|
-
quoted = true;
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
if (char === ",") {
|
|
614
|
-
row.push(field);
|
|
615
|
-
field = "";
|
|
616
|
-
continue;
|
|
617
|
-
}
|
|
618
|
-
if (char === "\n") {
|
|
619
|
-
row.push(field.replace(/\r$/, ""));
|
|
620
|
-
rows.push(row);
|
|
621
|
-
row = [];
|
|
622
|
-
field = "";
|
|
623
|
-
continue;
|
|
624
|
-
}
|
|
625
|
-
field += char;
|
|
626
|
-
}
|
|
627
|
-
if (field.length > 0 || row.length > 0) rows.push([...row, field.replace(/\r$/, "")]);
|
|
628
|
-
return [rows[0] ?? null, rows[1] ?? null];
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* `Win32_Process` for one pid, or null when it cannot be read.
|
|
632
|
-
*
|
|
633
|
-
* The whole round trip — launching PowerShell, loading the CIM provider, serializing —
|
|
634
|
-
* costs seconds on a cold runner, so the timeout is generous and the result is converted
|
|
635
|
-
* to CSV rather than JSON: CSV survives a value that contains a quote or a newline, which
|
|
636
|
-
* an argv legitimately can.
|
|
637
|
-
*/
|
|
638
|
-
async function windowsProcessInfo(pid) {
|
|
639
|
-
if (!windowsFilter.test(String(pid))) return null;
|
|
640
|
-
try {
|
|
641
|
-
const { stdout } = await execFileAsync$1("powershell", [
|
|
642
|
-
"-NoProfile",
|
|
643
|
-
"-NonInteractive",
|
|
644
|
-
"-Command",
|
|
645
|
-
`Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" | Select-Object CommandLine,ExecutablePath | ConvertTo-Csv -NoTypeInformation`
|
|
646
|
-
], {
|
|
647
|
-
timeout: 2e4,
|
|
648
|
-
windowsHide: true
|
|
649
|
-
});
|
|
650
|
-
const [headers, values] = parseCsvRows(stdout);
|
|
651
|
-
if (!headers || !values) return null;
|
|
652
|
-
const commandLineIndex = headers.indexOf("CommandLine");
|
|
653
|
-
const imageIndex = headers.indexOf("ExecutablePath");
|
|
654
|
-
const commandLine = commandLineIndex >= 0 ? values[commandLineIndex] : void 0;
|
|
655
|
-
if (commandLine === void 0 || commandLine.length === 0) return null;
|
|
656
|
-
const imagePath = imageIndex >= 0 ? values[imageIndex] : void 0;
|
|
657
|
-
return {
|
|
658
|
-
commandLine,
|
|
659
|
-
imagePath: imagePath && imagePath.length > 0 ? imagePath : null
|
|
660
|
-
};
|
|
661
|
-
} catch {
|
|
662
|
-
return null;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Which of these pids look like this entry's own detached successor. The environment
|
|
667
|
-
* marker is authoritative where the platform can read it; otherwise the answer rests on
|
|
668
|
-
* the entry's own argv, which is the only signal a detached successor is obliged to keep
|
|
669
|
-
* — and the only one Windows exposes at all.
|
|
670
|
-
*/
|
|
671
|
-
async function identifyHolders(serverId, spawn, pids) {
|
|
672
|
-
const found = [];
|
|
673
|
-
for (const pid of pids) {
|
|
674
|
-
if (await processCarriesServerId(pid, serverId)) {
|
|
675
|
-
found.push(pid);
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
if (spawn.args.length === 0) continue;
|
|
679
|
-
if (process.platform === "win32") {
|
|
680
|
-
const info = await windowsProcessInfo(pid);
|
|
681
|
-
if (info && matchesSpawn({
|
|
682
|
-
words: splitCommandLine(info.commandLine),
|
|
683
|
-
imagePath: info.imagePath
|
|
684
|
-
}, spawn)) found.push(pid);
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
const argv = await processArgv(pid);
|
|
688
|
-
if (argv !== null && matchesSpawn({ words: argv }, spawn)) found.push(pid);
|
|
689
|
-
}
|
|
690
|
-
return found;
|
|
691
|
-
}
|
|
692
|
-
//#endregion
|
|
693
|
-
//#region src/providers/process.ts
|
|
694
|
-
var execFileAsync = promisify(execFile);
|
|
695
|
-
/**
|
|
696
|
-
* The files `npm`/`pnpm` write into `node_modules/.bin` on Windows, in the order Node can
|
|
697
|
-
* actually start them.
|
|
698
|
-
*
|
|
699
|
-
* All of `foo`, `foo.cmd` and `foo.ps1` exist there — the extension-less one is a `#!/bin/sh`
|
|
700
|
-
* script, which is the POSIX shim, not a program Windows can spawn. Preferring it (the order
|
|
701
|
-
* `[command, ...shims]` gave) resolved to a file whose first line is `#!/bin/sh`: Node has no
|
|
702
|
-
* shell to hand it to, so the entry started nothing. `spawn` reports that as `ENOENT` and the
|
|
703
|
-
* panel used to blame the missing program.
|
|
704
|
-
*
|
|
705
|
-
* `.exe` leads because it needs no shell; `.cmd`/`.bat` follow and go through `needsShell()`.
|
|
706
|
-
* `.ps1` is last: it is a PowerShell script, which `cmd.exe` does not run on its own.
|
|
707
|
-
*/
|
|
708
|
-
var WINDOWS_SHIM_EXTENSIONS = [
|
|
709
|
-
".exe",
|
|
710
|
-
".cmd",
|
|
711
|
-
".bat",
|
|
712
|
-
".ps1"
|
|
713
|
-
];
|
|
714
|
-
/**
|
|
715
|
-
* Resolves a bare command through the entry's own directory and the project's
|
|
716
|
-
* `node_modules/.bin` first, so a server installed as a project dependency is
|
|
717
|
-
* found even when the launcher's PATH has no pnpm-injected bin dir.
|
|
718
|
-
*/
|
|
719
|
-
function resolveCommand(command, ...searchDirs) {
|
|
720
|
-
if (command.includes("/") || command.includes("\\")) return command;
|
|
721
|
-
const candidates = process.platform === "win32" && path.extname(command) === "" ? WINDOWS_SHIM_EXTENSIONS.map((extension) => `${command}${extension}`) : [command];
|
|
722
|
-
for (const dir of searchDirs) for (const candidate of candidates) {
|
|
723
|
-
const local = path.join(dir, "node_modules", ".bin", candidate);
|
|
724
|
-
if (fs.existsSync(local)) return local;
|
|
725
|
-
}
|
|
726
|
-
if (process.platform === "win32" && path.extname(command) === "") return windowsShimOnPath(command) ?? command;
|
|
727
|
-
return command;
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* A bare name that `PATH` resolves to a `.cmd`/`.bat` (`pnpm`, `npm`, `yarn`) comes back with that
|
|
731
|
-
* extension, so `needsShell` sees it: `spawn` without a shell only finds `.com`/`.exe` and answers
|
|
732
|
-
* `ENOENT`. The name stays bare (`npm.cmd`), so `cmd.exe` searches for it and a `Program Files`
|
|
733
|
-
* path is never split. `null` when the first match by `PATHEXT` order needs no shell, or none exists.
|
|
734
|
-
*/
|
|
735
|
-
function windowsShimOnPath(command) {
|
|
736
|
-
const runnable = /* @__PURE__ */ new Set([
|
|
737
|
-
".com",
|
|
738
|
-
".exe",
|
|
739
|
-
".bat",
|
|
740
|
-
".cmd"
|
|
741
|
-
]);
|
|
742
|
-
const extensions = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim().toLowerCase()).filter((extension) => runnable.has(extension));
|
|
743
|
-
for (const dir of pathDirs()) for (const extension of extensions) if (isExecutable(path.join(dir, `${command}${extension}`))) return extension === ".bat" || extension === ".cmd" ? `${command}${extension}` : null;
|
|
744
|
-
return null;
|
|
745
|
-
}
|
|
746
|
-
function pathDirs() {
|
|
747
|
-
return (process.env.PATH ?? "").split(path.delimiter).filter((dir) => dir.length > 0);
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Does this program exist where `spawn` would look it up, and where?
|
|
751
|
-
*
|
|
752
|
-
* Used only to tell a **pasted command line** apart from a missing program: `spawn` answers both
|
|
753
|
-
* with the same `ENOENT`, and the two have opposite fixes. `null` means it was not found anywhere
|
|
754
|
-
* this process would search.
|
|
755
|
-
*
|
|
756
|
-
* A bare name is searched on `PATH` (plus `.exe`/`.cmd`/`.bat` on Windows, because that is what
|
|
757
|
-
* the OS appends); anything with a separator is a path and is stat'd as written.
|
|
758
|
-
*/
|
|
759
|
-
function findProgram(command, cwd = projectDir) {
|
|
760
|
-
if (command.includes("/") || command.includes("\\")) {
|
|
761
|
-
const resolved = path.resolve(cwd, command);
|
|
762
|
-
return isExecutable(resolved) ? resolved : null;
|
|
763
|
-
}
|
|
764
|
-
const extensions = process.platform === "win32" ? ["", ...WINDOWS_SHIM_EXTENSIONS] : [""];
|
|
765
|
-
for (const dir of pathDirs()) for (const extension of extensions) {
|
|
766
|
-
const candidate = path.join(dir, `${command}${extension}`);
|
|
767
|
-
if (isExecutable(candidate)) return candidate;
|
|
768
|
-
}
|
|
769
|
-
return null;
|
|
770
|
-
}
|
|
771
|
-
/** A file this user may run. A directory named like a program is not one. */
|
|
772
|
-
function isExecutable(file) {
|
|
773
|
-
try {
|
|
774
|
-
if (!fs.statSync(file).isFile()) return false;
|
|
775
|
-
if (process.platform === "win32") return true;
|
|
776
|
-
fs.accessSync(file, fs.constants.X_OK);
|
|
777
|
-
return true;
|
|
778
|
-
} catch {
|
|
779
|
-
return false;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
/** Relative entry paths belong to the project that launched the panel. */
|
|
783
|
-
function resolveCwd(cwd, base = projectDir) {
|
|
784
|
-
return path.resolve(base, cwd);
|
|
785
|
-
}
|
|
786
|
-
/** Node cannot spawn a Windows `.cmd`/`.bat` shim without a shell (EINVAL). */
|
|
787
|
-
function needsShell(command) {
|
|
788
|
-
return process.platform === "win32" && /\.(?:cmd|bat)$/i.test(command);
|
|
789
|
-
}
|
|
790
|
-
function spawnManaged(spec, options = {}) {
|
|
791
|
-
return spawn(spec.command, spec.args, {
|
|
792
|
-
cwd: spec.cwd,
|
|
793
|
-
env: {
|
|
794
|
-
...process.env,
|
|
795
|
-
...spec.env
|
|
796
|
-
},
|
|
797
|
-
detached: options.detached ?? true,
|
|
798
|
-
stdio: options.output === void 0 ? [
|
|
799
|
-
"ignore",
|
|
800
|
-
"pipe",
|
|
801
|
-
"pipe"
|
|
802
|
-
] : [
|
|
803
|
-
"ignore",
|
|
804
|
-
options.output.stdout,
|
|
805
|
-
options.output.stderr
|
|
806
|
-
],
|
|
807
|
-
shell: needsShell(spec.command),
|
|
808
|
-
windowsHide: true
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
/** SIGTERM (default) to the child, escalating to SIGKILL after the grace period. */
|
|
812
|
-
async function terminate(child, options) {
|
|
813
|
-
if (child.exitCode !== null || child.signalCode !== null) return "exited";
|
|
814
|
-
const exited = waitForExit(child, options.graceMs);
|
|
815
|
-
signalChild(child, options.signal, options.killGroup);
|
|
816
|
-
if (await exited) return "exited";
|
|
817
|
-
signalChild(child, "SIGKILL", options.escalateGroup ?? options.killGroup);
|
|
818
|
-
await waitForExit(child, 2e3);
|
|
819
|
-
return "force-killed";
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Windows has no process groups and no SIGTERM: `taskkill /T` walks the tree and
|
|
823
|
-
* `/F` is the only reliable way to stop a console process.
|
|
824
|
-
*/
|
|
825
|
-
async function killTreeWindows(pid) {
|
|
826
|
-
try {
|
|
827
|
-
await execFileAsync("taskkill", [
|
|
828
|
-
"/pid",
|
|
829
|
-
String(pid),
|
|
830
|
-
"/T",
|
|
831
|
-
"/F"
|
|
832
|
-
], { timeout: 5e3 });
|
|
833
|
-
} catch {}
|
|
834
|
-
}
|
|
835
|
-
/** SIGKILL to a `spawnManaged` child and everything it started: its group, or its tree on Windows. */
|
|
836
|
-
function forceKillTree(child) {
|
|
837
|
-
if (child.exitCode === null && child.signalCode === null) signalChild(child, "SIGKILL", true);
|
|
838
|
-
}
|
|
839
|
-
function signalChild(child, signal, killGroup) {
|
|
840
|
-
const pid = child.pid;
|
|
841
|
-
if (pid === void 0) return;
|
|
842
|
-
signalPid(pid, signal, killGroup);
|
|
843
|
-
}
|
|
844
|
-
function signalPid(pid, signal, killGroup) {
|
|
845
|
-
if (process.platform === "win32") {
|
|
846
|
-
if (killGroup) killTreeWindows(pid);
|
|
847
|
-
else try {
|
|
848
|
-
process.kill(pid, signal);
|
|
849
|
-
} catch {}
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
if (killGroup) try {
|
|
853
|
-
process.kill(-pid, signal);
|
|
854
|
-
return;
|
|
855
|
-
} catch {}
|
|
856
|
-
try {
|
|
857
|
-
process.kill(pid, signal);
|
|
858
|
-
} catch {}
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* The same shutdown a supervised child gets, for a process we adopted instead of
|
|
862
|
-
* spawned: a detached successor is not our child, so it is signalled by pid (and
|
|
863
|
-
* by process group when asked) and its exit is polled rather than awaited.
|
|
864
|
-
*
|
|
865
|
-
* Liveness comes from `isProcessAlive`, never a local signal-0 copy: a second definition returned
|
|
866
|
-
* `false` for `EPERM`, so a process that was there but not ours to signal read as "exited" and
|
|
867
|
-
* `'force-killed'` was returned for one still running. One predicate, one answer.
|
|
868
|
-
*/
|
|
869
|
-
async function terminatePid(pid, options) {
|
|
870
|
-
if (!isProcessAlive(pid)) return "exited";
|
|
871
|
-
signalPid(pid, options.signal, options.killGroup);
|
|
872
|
-
const deadline = Date.now() + Math.max(0, options.graceMs);
|
|
873
|
-
while (Date.now() < deadline && isProcessAlive(pid)) await delay(50);
|
|
874
|
-
if (!isProcessAlive(pid)) return "exited";
|
|
875
|
-
signalPid(pid, "SIGKILL", options.escalateGroup ?? options.killGroup);
|
|
876
|
-
const hardDeadline = Date.now() + 2e3;
|
|
877
|
-
while (Date.now() < hardDeadline && isProcessAlive(pid)) await delay(50);
|
|
878
|
-
return "force-killed";
|
|
879
|
-
}
|
|
880
|
-
function delay(ms) {
|
|
881
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
882
|
-
}
|
|
883
|
-
function waitForExit(child, timeoutMs) {
|
|
884
|
-
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
|
|
885
|
-
if (timeoutMs <= 0) return Promise.resolve(false);
|
|
886
|
-
return new Promise((resolve) => {
|
|
887
|
-
const timer = setTimeout(() => {
|
|
888
|
-
child.removeListener("exit", onExit);
|
|
889
|
-
resolve(false);
|
|
890
|
-
}, timeoutMs);
|
|
891
|
-
function onExit() {
|
|
892
|
-
clearTimeout(timer);
|
|
893
|
-
resolve(true);
|
|
894
|
-
}
|
|
895
|
-
child.once("exit", onExit);
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
//#endregion
|
|
899
|
-
//#region src/providers/nanny.ts
|
|
900
|
-
var nanny_exports = /* @__PURE__ */ __exportAll({
|
|
901
|
-
HEARTBEAT_STALE_MS: () => HEARTBEAT_STALE_MS,
|
|
902
|
-
NANNY_HEARTBEAT_MS: () => NANNY_HEARTBEAT_MS,
|
|
903
|
-
NANNY_TRAPPED_SIGNALS: () => NANNY_TRAPPED_SIGNALS,
|
|
904
|
-
SPEC_SUFFIX: () => SPEC_SUFFIX,
|
|
905
|
-
clearNannySpec: () => clearNannySpec,
|
|
906
|
-
clearNannyState: () => clearNannyState,
|
|
907
|
-
describeNannyExit: () => describeNannyExit,
|
|
908
|
-
describeSpawnError: () => describeSpawnError,
|
|
909
|
-
nannyChildPid: () => nannyChildPid,
|
|
910
|
-
nannyEntryPoint: () => nannyEntryPoint,
|
|
911
|
-
nannyIsAlive: () => nannyIsAlive,
|
|
912
|
-
nannyLogFile: () => nannyLogFile,
|
|
913
|
-
nannySpecPath: () => nannySpecPath,
|
|
914
|
-
nannyStatePath: () => nannyStatePath,
|
|
915
|
-
nannyStopOptions: () => nannyStopOptions,
|
|
916
|
-
readNannyState: () => readNannyState,
|
|
917
|
-
sweepNannySpecs: () => sweepNannySpecs,
|
|
918
|
-
takeNannySpec: () => takeNannySpec,
|
|
919
|
-
writeNannySpec: () => writeNannySpec,
|
|
920
|
-
writeNannyState: () => writeNannyState
|
|
921
|
-
});
|
|
922
|
-
/**
|
|
923
|
-
* A persistent entry is not run by the panel: the panel spawns a *nanny* that owns
|
|
924
|
-
* the child's pipes, writes its output to the entry's JSONL log and keeps a small
|
|
925
|
-
* state file. That is what lets the entry survive a panel stop, restart or kill
|
|
926
|
-
* without losing its log or its identity — the pipes belong to a process that stays.
|
|
927
|
-
*
|
|
928
|
-
* These are the files and the liveness rules behind that arrangement; the nanny
|
|
929
|
-
* itself is `src/services/nanny.ts`.
|
|
930
|
-
*/
|
|
931
|
-
/** The spec carries expanded `env`, so it lives only from spawn to read. */
|
|
932
|
-
var SPEC_MODE = 384;
|
|
933
|
-
/** Suffix of a spawn spec, so a sweep and the state reader can tell them apart. */
|
|
934
|
-
var SPEC_SUFFIX = ".spec.json";
|
|
935
|
-
/**
|
|
936
|
-
* The signals a nanny traps and forwards to its child. Any other signal ends the nanny outright,
|
|
937
|
-
* so nothing was forwarded — see `stopPersistentEntries`, which then signals the child directly.
|
|
938
|
-
*/
|
|
939
|
-
var NANNY_TRAPPED_SIGNALS = /* @__PURE__ */ new Set(["SIGTERM", "SIGINT"]);
|
|
940
|
-
/**
|
|
941
|
-
* How a nanny is stopped. A trapped signal goes to the nanny's pid alone and the nanny signals its
|
|
942
|
-
* own group once (`killGroup` is honoured there): signalling the group from here as well delivered
|
|
943
|
-
* the stop to the child twice. The SIGKILL escalation still covers the whole group. Windows has no
|
|
944
|
-
* signal a nanny can trap, so its stop is unchanged.
|
|
945
|
-
*/
|
|
946
|
-
function nannyStopOptions(stop, platform = process.platform) {
|
|
947
|
-
if (platform === "win32" || !stop.killGroup || !NANNY_TRAPPED_SIGNALS.has(stop.signal)) return stop;
|
|
948
|
-
return {
|
|
949
|
-
...stop,
|
|
950
|
-
killGroup: false,
|
|
951
|
-
escalateGroup: true
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
/** How often a nanny rewrites its state file. */
|
|
955
|
-
var NANNY_HEARTBEAT_MS = 5e3;
|
|
956
|
-
/** A heartbeat older than this is not evidence of anything. */
|
|
957
|
-
var HEARTBEAT_STALE_MS = 3e4;
|
|
958
|
-
/**
|
|
959
|
-
* The state directory is passed in rather than read from a global: the panel injects
|
|
960
|
-
* `$HHOSTED_HOME/.state`, and a test injects its own temp directory.
|
|
961
|
-
*/
|
|
962
|
-
function nannySpecPath(dir, id) {
|
|
963
|
-
return path.join(dir, `${id}${SPEC_SUFFIX}`);
|
|
964
|
-
}
|
|
965
|
-
function nannyStatePath(dir, id) {
|
|
966
|
-
return path.join(dir, `${id}.json`);
|
|
967
|
-
}
|
|
968
|
-
/** The file a nanny writes and the panel tails; one derivation, so they cannot drift. */
|
|
969
|
-
function nannyLogFile(logDir, id) {
|
|
970
|
-
return path.join(logDir, `${id}.log`);
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* How to run this CLI again as a nanny. The panel was itself launched through this
|
|
974
|
-
* entry point (`up` re-spawns itself with it), so `process.argv[1]` is the one path
|
|
975
|
-
* that works under tsx, from `dist/cli.js` and through the published bin alike.
|
|
976
|
-
*/
|
|
977
|
-
function nannyEntryPoint() {
|
|
978
|
-
return process.argv[1] ?? "";
|
|
979
|
-
}
|
|
980
|
-
/** Written before the spawn, consumed by the nanny, never left behind. */
|
|
981
|
-
function writeNannySpec(file, spec) {
|
|
982
|
-
writeFileAtomic(file, JSON.stringify(spec), { mode: SPEC_MODE });
|
|
983
|
-
}
|
|
984
|
-
function clearNannySpec(file) {
|
|
985
|
-
fs.rmSync(file, { force: true });
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Reads and unlinks in one step: the spec holds expanded secrets, and a spec left
|
|
989
|
-
* behind — a nanny that died before reading it, a panel killed mid-spawn — is a
|
|
990
|
-
* secret file with no owner. It is consumed even when it cannot be parsed.
|
|
991
|
-
*/
|
|
992
|
-
function takeNannySpec(file) {
|
|
993
|
-
const raw = fs.readFileSync(file, "utf8");
|
|
994
|
-
fs.rmSync(file, { force: true });
|
|
995
|
-
const parsed = nannySpecSchema(JSON.parse(raw));
|
|
996
|
-
if (parsed instanceof type.errors) throw new Error(`invalid nanny spec: ${parsed.summary}`);
|
|
997
|
-
return parsed;
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Nothing can be waiting on a spec before this panel has spawned a nanny, so every
|
|
1001
|
-
* one still on disk at boot belongs to a nanny that never read it.
|
|
1002
|
-
*/
|
|
1003
|
-
function sweepNannySpecs(dir) {
|
|
1004
|
-
let swept = 0;
|
|
1005
|
-
for (const name of readSpecNames(dir)) {
|
|
1006
|
-
fs.rmSync(path.join(dir, name), { force: true });
|
|
1007
|
-
swept += 1;
|
|
1008
|
-
}
|
|
1009
|
-
return swept;
|
|
1010
|
-
}
|
|
1011
|
-
function readSpecNames(dir) {
|
|
1012
|
-
try {
|
|
1013
|
-
return fs.readdirSync(dir).filter((name) => name.endsWith(SPEC_SUFFIX));
|
|
1014
|
-
} catch {
|
|
1015
|
-
return [];
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
/** A stale or foreign file reads as "no state", never as a throw. */
|
|
1019
|
-
function readNannyState(file) {
|
|
1020
|
-
try {
|
|
1021
|
-
const parsed = nannyStateSchema(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
1022
|
-
return parsed instanceof type.errors ? null : parsed;
|
|
1023
|
-
} catch {
|
|
1024
|
-
return null;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
function writeNannyState(file, state) {
|
|
1028
|
-
writeFileAtomic(file, JSON.stringify(state));
|
|
1029
|
-
}
|
|
1030
|
-
function clearNannyState(file) {
|
|
1031
|
-
fs.rmSync(file, { force: true });
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* The same wording the supervisor uses for a child's exit, so history reads alike — plus a hint
|
|
1035
|
-
* when the code has a conventional meaning, because `code 137` alone tells an operator nothing and
|
|
1036
|
-
* that is the one they most want explained (a container limit or the kernel OOM killer).
|
|
1037
|
-
*
|
|
1038
|
-
* The hint is worded as a possibility, never a claim: 128+N is a shell convention, and a program
|
|
1039
|
-
* is free to exit 137 for its own reasons — a JVM reports OOM that way itself. 126 and 127 are
|
|
1040
|
-
* firmer, since the shell sets those when it cannot run the command at all.
|
|
1041
|
-
*/
|
|
1042
|
-
function describeNannyExit(exit) {
|
|
1043
|
-
if (exit.signal !== null) return `signal ${exit.signal}`;
|
|
1044
|
-
const hint = exitCodeHint(exit.code);
|
|
1045
|
-
return hint === null ? `code ${exit.code}` : `code ${exit.code} (${hint})`;
|
|
1046
|
-
}
|
|
1047
|
-
/** What a conventional exit code usually means, or null when there is nothing to add. */
|
|
1048
|
-
function exitCodeHint(code) {
|
|
1049
|
-
if (code === null || code === 0) return null;
|
|
1050
|
-
if (code === 126) return "the command is not executable";
|
|
1051
|
-
if (code === 127) return "the command was not found";
|
|
1052
|
-
if (code <= 128 || code > 192) return null;
|
|
1053
|
-
const signal = signalName(code - 128);
|
|
1054
|
-
if (signal === null) return null;
|
|
1055
|
-
return code === 137 ? `${signal} — which the kernel sends when memory runs out` : `${signal}, if the shell reported the kill`;
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* A spawn failure in words a person can act on.
|
|
1059
|
-
*
|
|
1060
|
-
* Node reports a missing program as `spawn <cmd> ENOENT` — the same errno as a missing *file*, and
|
|
1061
|
-
* the same wording whichever of the two it is. A user who pasted `java -jar server.jar` into
|
|
1062
|
-
* `command` saw exactly that and had nothing to go on: the message names the whole line, so it
|
|
1063
|
-
* reads as "the program is missing" even when the program is fine and only the argument is wrong.
|
|
1064
|
-
*
|
|
1065
|
-
* `command` is the configured program, so the two cases can be told apart: if a bare name has no
|
|
1066
|
-
* path separator, the shell would have searched `PATH` and this one did not.
|
|
1067
|
-
*
|
|
1068
|
-
* A **missing working directory** is the third cause of the same errno, and it is the one a
|
|
1069
|
-
* deployment hits: `spawn` resolves `cwd` before it looks for the program, so an entry whose `cwd`
|
|
1070
|
-
* does not exist *under this launch directory* fails exactly like an uninstalled program. That read
|
|
1071
|
-
* sent a person to `which node` while `node` was fine and only the relative path was wrong (a unit
|
|
1072
|
-
* file with no `WorkingDirectory=`, a container started from `/`). `cwd` is therefore checked first:
|
|
1073
|
-
* if it is not an existing directory, nothing else about the spawn could have worked.
|
|
1074
|
-
*/
|
|
1075
|
-
function describeSpawnError(error, command, cwd) {
|
|
1076
|
-
const missingDir = cwd === void 0 ? null : describeMissingDir(cwd);
|
|
1077
|
-
if (missingDir !== null && (error.code === "ENOENT" || error.code === "ENOTDIR")) return missingDir;
|
|
1078
|
-
if (error.code === "ENOENT") {
|
|
1079
|
-
const pasted = describePastedCommandLine(command, cwd);
|
|
1080
|
-
if (pasted !== null) return pasted;
|
|
1081
|
-
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?`;
|
|
1082
|
-
}
|
|
1083
|
-
if (error.code === "EACCES") return `\`${command}\` exists but is not executable — ${notExecutableHint()}`;
|
|
1084
|
-
return `${error.message} (while running \`${command}\`)`;
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* What to do about `EACCES`, in the shell of the platform the panel is running on.
|
|
1088
|
-
*
|
|
1089
|
-
* `chmod +x` is not a Windows program: `cmd.exe` answers `'chmod' is not recognized…`, so the one
|
|
1090
|
-
* line that exists to offer a way out sent the reader to a second dead end. The platform is the
|
|
1091
|
-
* only signal available, exactly as it is for `shellQuote` (`helpers/shell.ts`); one function so a
|
|
1092
|
-
* second `EACCES` message cannot be written with the POSIX half alone.
|
|
1093
|
-
*/
|
|
1094
|
-
function notExecutableHint() {
|
|
1095
|
-
return process.platform === "win32" ? "check its permissions (Windows has no executable bit — look at the file's Security tab for a denied account)" : "check its permissions (chmod +x)";
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* The first mistake the Add-server form invites: a whole command line typed into `Command`.
|
|
1099
|
-
*
|
|
1100
|
-
* `Command` is spawned **without a shell** and `Arguments` is a separate field, so `node server.js`
|
|
1101
|
-
* names a program called `node server.js`. The fix is to split it — and the sentence has to say so,
|
|
1102
|
-
* because the alternative reading ("node is not installed") is what sends someone to `which node`
|
|
1103
|
-
* while `node` is right there.
|
|
1104
|
-
*
|
|
1105
|
-
* Only claimed when the evidence is unambiguous: the field has whitespace, and the program it opens
|
|
1106
|
-
* with **does** resolve. So a genuinely missing program keeps the message about PATH, and a path with
|
|
1107
|
-
* a space in it is never split (it has no bare first word that resolves). See `findProgram`.
|
|
1108
|
-
*/
|
|
1109
|
-
function describePastedCommandLine(command, cwd) {
|
|
1110
|
-
const words = command.trim().split(/\s+/);
|
|
1111
|
-
if (words.length < 2) return null;
|
|
1112
|
-
const program = words[0];
|
|
1113
|
-
if (findProgram(program, cwd) === null) return null;
|
|
1114
|
-
return `\`${command}\` is a whole command line, but \`Command\` is spawned without a shell — this release looks for a program named \`${command}\`. Put \`${program}\` in \`Command\` and the rest in \`Arguments\`, one argument per line`;
|
|
1115
|
-
}
|
|
1116
|
-
/** Why a working directory cannot be used, in one sentence, or null when it can. */
|
|
1117
|
-
function describeMissingDir(cwd) {
|
|
1118
|
-
try {
|
|
1119
|
-
if (fs.statSync(cwd).isDirectory()) return null;
|
|
1120
|
-
return `the working directory \`${cwd}\` is not a directory — a relative \`cwd\` resolves against the directory the panel was started from`;
|
|
1121
|
-
} catch (error) {
|
|
1122
|
-
if (error.code === "ENOENT") return `the working directory \`${cwd}\` does not exist — a relative \`cwd\` resolves against the directory the panel was started from, so a service started from elsewhere (systemd, docker, a login shell) looks in a different place`;
|
|
1123
|
-
return `the working directory \`${cwd}\` cannot be read — check its permissions`;
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
/** `SIGKILL` for 9, or null when the number names nothing. */
|
|
1127
|
-
function signalName(number) {
|
|
1128
|
-
for (const [name, value] of Object.entries(os.constants.signals)) if (value === number) return name;
|
|
1129
|
-
return null;
|
|
1130
|
-
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Is the nanny this state describes still ours? A live pid proves nothing on its
|
|
1133
|
-
* own — pids are reused, and the heartbeat is written *into the file*, not by the
|
|
1134
|
-
* process the file names, so a recycled pid with a recent write reads as running.
|
|
1135
|
-
* `startedAt` settles that first (`processLiveness`), exactly as `run.json` uses it:
|
|
1136
|
-
* the nanny stamps its record during its own boot, so its process is always born
|
|
1137
|
-
* before the stamp. The environment marker (Linux, macOS) or the argv we spawned it
|
|
1138
|
-
* with answers the rest, Windows included.
|
|
1139
|
-
*/
|
|
1140
|
-
async function nannyIsAlive(state, id, options = {}) {
|
|
1141
|
-
if (state.nannyPid <= 0) return false;
|
|
1142
|
-
const liveness = await processLiveness(state.nannyPid, state.startedAt, options);
|
|
1143
|
-
if (liveness === "gone" || liveness === "recycled") return false;
|
|
1144
|
-
if (Date.now() - state.heartbeatAt <= 3e4) return true;
|
|
1145
|
-
if (await processCarriesServerId(state.nannyPid, id)) return true;
|
|
1146
|
-
const words = await processArgv(state.nannyPid);
|
|
1147
|
-
return words !== null && words.includes("__nanny") && words.some((word) => word.endsWith(`${id}.spec.json`));
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* The nanny's child, when that pid is still the process it spawned — `null` otherwise. Used to stop a
|
|
1151
|
-
* child the nanny could not pass a stop on to, which happens *after* the nanny is gone, so a pid alone
|
|
1152
|
-
* could be anybody's by then. The nanny stamps `startedAt` just before it spawns the child, so the
|
|
1153
|
-
* child is born within the stamp's tolerance and a pid born later is a recycled one. Where the
|
|
1154
|
-
* platform reports no birth, the environment marker decides.
|
|
1155
|
-
*/
|
|
1156
|
-
async function nannyChildPid(state, options = {}) {
|
|
1157
|
-
const pid = state.childPid;
|
|
1158
|
-
if (pid === null || pid <= 0) return null;
|
|
1159
|
-
const liveness = await processLiveness(pid, state.startedAt, options);
|
|
1160
|
-
if (liveness === "live") return pid;
|
|
1161
|
-
if (liveness === "unknown" && await processCarriesServerId(pid, state.serverId)) return pid;
|
|
1162
|
-
return null;
|
|
1163
|
-
}
|
|
1164
|
-
//#endregion
|
|
1165
|
-
export { processTreeOwners as A, resolveCwd as C, identifyHolders as D, terminatePid as E, ProcessSampler as O, resolveCommand as S, terminate as T, readNannyState as _, clearNannySpec as a, writeNannyState as b, describeSpawnError as c, nannyIsAlive as d, nannyLogFile as f, nanny_exports as g, nannyStopOptions as h, SPEC_SUFFIX as i, processCarriesServerId as k, nannyChildPid as l, nannyStatePath as m, NANNY_HEARTBEAT_MS as n, clearNannyState as o, nannySpecPath as p, NANNY_TRAPPED_SIGNALS as r, describeNannyExit as s, HEARTBEAT_STALE_MS as t, nannyEntryPoint as u, sweepNannySpecs as v, spawnManaged as w, forceKillTree as x, writeNannySpec as y };
|
|
1166
|
-
|
|
1167
|
-
//# sourceMappingURL=nanny-BtWfy0QH.js.map
|