@usine/server 0.2.1 → 0.4.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/LICENSE +661 -21
- package/README.md +54 -20
- package/dist/backend.d.ts +26 -5
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +41 -16
- package/dist/backend.js.map +1 -1
- package/dist/backup.d.ts +6 -3
- package/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +26 -8
- package/dist/backup.js.map +1 -1
- package/dist/cli.d.ts +77 -11
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +280 -31
- package/dist/cli.js.map +1 -1
- package/dist/command.d.ts +22 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +51 -0
- package/dist/command.js.map +1 -0
- package/dist/detach.d.ts +83 -0
- package/dist/detach.d.ts.map +1 -0
- package/dist/detach.js +320 -0
- package/dist/detach.js.map +1 -0
- package/dist/export-run.d.ts +1 -1
- package/dist/export-run.d.ts.map +1 -1
- package/dist/export-run.js +3 -3
- package/dist/export-run.js.map +1 -1
- package/dist/failure-message.d.ts +19 -0
- package/dist/failure-message.d.ts.map +1 -0
- package/dist/failure-message.js +127 -0
- package/dist/failure-message.js.map +1 -0
- package/dist/http.d.ts +14 -5
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +86 -33
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instance/environment.d.ts +17 -0
- package/dist/instance/environment.d.ts.map +1 -0
- package/dist/instance/environment.js +51 -0
- package/dist/instance/environment.js.map +1 -0
- package/dist/instance/id.d.ts +17 -0
- package/dist/instance/id.d.ts.map +1 -0
- package/dist/instance/id.js +35 -0
- package/dist/instance/id.js.map +1 -0
- package/dist/instance/lock.d.ts +27 -0
- package/dist/instance/lock.d.ts.map +1 -0
- package/dist/instance/lock.js +127 -0
- package/dist/instance/lock.js.map +1 -0
- package/dist/instance/manifest.d.ts +52 -0
- package/dist/instance/manifest.d.ts.map +1 -0
- package/dist/instance/manifest.js +131 -0
- package/dist/instance/manifest.js.map +1 -0
- package/dist/instance/operator-api.d.ts +30 -0
- package/dist/instance/operator-api.d.ts.map +1 -0
- package/dist/instance/operator-api.js +47 -0
- package/dist/instance/operator-api.js.map +1 -0
- package/dist/instance/ports.d.ts +23 -0
- package/dist/instance/ports.d.ts.map +1 -0
- package/dist/instance/ports.js +81 -0
- package/dist/instance/ports.js.map +1 -0
- package/dist/instance/record.d.ts +82 -0
- package/dist/instance/record.d.ts.map +1 -0
- package/dist/instance/record.js +116 -0
- package/dist/instance/record.js.map +1 -0
- package/dist/instance/state.d.ts +45 -0
- package/dist/instance/state.d.ts.map +1 -0
- package/dist/instance/state.js +79 -0
- package/dist/instance/state.js.map +1 -0
- package/dist/instance/systemd.d.ts +36 -0
- package/dist/instance/systemd.d.ts.map +1 -0
- package/dist/instance/systemd.js +61 -0
- package/dist/instance/systemd.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +27 -0
- package/dist/logger.js.map +1 -0
- package/dist/main.js +38 -18
- package/dist/main.js.map +1 -1
- package/dist/registry.d.ts +20 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +37 -0
- package/dist/registry.js.map +1 -0
- package/dist/reload-signal.d.ts +8 -0
- package/dist/reload-signal.d.ts.map +1 -0
- package/dist/reload-signal.js +21 -0
- package/dist/reload-signal.js.map +1 -0
- package/dist/restart.d.ts +19 -0
- package/dist/restart.d.ts.map +1 -0
- package/dist/restart.js +105 -0
- package/dist/restart.js.map +1 -0
- package/dist/shutdown.d.ts +5 -2
- package/dist/shutdown.d.ts.map +1 -1
- package/dist/shutdown.js +11 -5
- package/dist/shutdown.js.map +1 -1
- package/dist/status.d.ts +12 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +99 -0
- package/dist/status.js.map +1 -0
- package/dist/stop.d.ts +81 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/stop.js +195 -0
- package/dist/stop.js.map +1 -0
- package/dist/system-sleep.d.ts +9 -0
- package/dist/system-sleep.d.ts.map +1 -0
- package/dist/system-sleep.js +42 -0
- package/dist/system-sleep.js.map +1 -0
- package/dist/tracing.d.ts +22 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +61 -0
- package/dist/tracing.js.map +1 -0
- package/dist/up.d.ts +2 -2
- package/dist/up.d.ts.map +1 -1
- package/dist/up.js +62 -24
- package/dist/up.js.map +1 -1
- package/dist/upgrade.d.ts +58 -0
- package/dist/upgrade.d.ts.map +1 -0
- package/dist/upgrade.js +237 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/web/assets/CompositeItem-DU6IyNMY.js +1 -0
- package/dist/web/assets/ToolbarRootContext-Cytu6o2e.js +1 -0
- package/dist/web/assets/X.es-B7iqdxa_.js +1 -0
- package/dist/web/assets/_agent-BVKD5odk.js +1 -0
- package/dist/web/assets/_loop-BFLzamuo.js +1 -0
- package/dist/web/assets/_name-Bh4AQ9sR.js +6 -0
- package/dist/web/assets/_name-CMVsmWzq.js +1 -0
- package/dist/web/assets/_name-DCkgEma_.js +1 -0
- package/dist/web/assets/_name-Ds_pWi15.js +1 -0
- package/dist/web/assets/_number-B9aYwvcQ.js +1 -0
- package/dist/web/assets/_run-BZWt47QS.js +8 -0
- package/dist/web/assets/_worker-Dgfufm5p.js +1 -0
- package/dist/web/assets/action-rCd1FeAz.js +1 -0
- package/dist/web/assets/agents-Drbg6qpH.js +1 -0
- package/dist/web/assets/agents-_6-dEjrY.js +1 -0
- package/dist/web/assets/button-DVWXde__.js +1 -0
- package/dist/web/assets/collapsible-IOhZV1qg.js +1 -0
- package/dist/web/assets/core-wi-Hu_JV.js +12 -0
- package/dist/web/assets/drawer-BiqnR_8i.js +1 -0
- package/dist/web/assets/dropdown-menu-C9D1kRkO.js +1 -0
- package/dist/web/assets/edit-and-retry-BgOR6mvP.js +1 -0
- package/dist/web/assets/engine-javascript-D-6se_EF.js +141 -0
- package/dist/web/assets/error-alert-9tKpTE3v.js +1 -0
- package/dist/web/assets/file-error-SjG2jLJ9.js +1 -0
- package/dist/web/assets/fill-cell-ClM88KFD.js +1 -0
- package/dist/web/assets/heading-lX1a1LNN.js +1 -0
- package/dist/web/assets/index-BymNZU1Q.js +10 -0
- package/dist/web/assets/index-Dyjfp3ET.css +2 -0
- package/dist/web/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/web/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/web/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/web/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/web/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/web/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/web/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/web/assets/label-badge-aIGT1Bry.js +1 -0
- package/dist/web/assets/list-v8WJp2Eq.js +1 -0
- package/dist/web/assets/loops-BFoFf_og.js +1 -0
- package/dist/web/assets/mark-CC3RwMy_.js +1 -0
- package/dist/web/assets/markdown-BnyfnuCL.js +29 -0
- package/dist/web/assets/matchContext-BquevSJS.js +2 -0
- package/dist/web/assets/model-BerBT6R0.js +1 -0
- package/dist/web/assets/moves-Dg9sshX5.js +1 -0
- package/dist/web/assets/overview-C_tFKGZ8.js +1 -0
- package/dist/web/assets/page-DWnGi6wA.js +301 -0
- package/dist/web/assets/project-not-found-CodaBVdu.js +1 -0
- package/dist/web/assets/pull-request-marks-DE00nqGW.js +1 -0
- package/dist/web/assets/queries-B1SHA_r4.js +1 -0
- package/dist/web/assets/reload-Dsl0zjJ7.js +1 -0
- package/dist/web/assets/repositories-BdxmD192.js +1 -0
- package/dist/web/assets/repositories-D4wYJfa_.js +1 -0
- package/dist/web/assets/route-B_gphTYG.js +1 -0
- package/dist/web/assets/route-Cc7dKnn5.js +1 -0
- package/dist/web/assets/routes-BLy5TGH_.js +65 -0
- package/dist/web/assets/run-again-BTKagSXR.js +1 -0
- package/dist/web/assets/section-B3pWIIBa.js +1 -0
- package/dist/web/assets/section-CD-MB5r3.js +1 -0
- package/dist/web/assets/section-Id99HktI.js +1 -0
- package/dist/web/assets/settings-YrDysQXW.js +1 -0
- package/dist/web/assets/slots-BraHmbNr.js +1 -0
- package/dist/web/assets/status-badge-DnvNo1tG.js +1 -0
- package/dist/web/assets/strings-CW2XaR5f.js +1 -0
- package/dist/web/assets/table-BjyI4fVI.js +1 -0
- package/dist/web/assets/tasks-DCL8kLmD.js +1 -0
- package/dist/web/assets/transcript-sxRJzx6t.js +5 -0
- package/dist/web/assets/usage-CLQJdX9-.js +1 -0
- package/dist/web/assets/use-now-0P8TUXeg.js +1 -0
- package/dist/web/assets/useAnchoredPopupScrollLock-CQ83Wy-r.js +1 -0
- package/dist/web/assets/useNavigate-BW1WdocJ.js +1 -0
- package/dist/web/assets/usePositioner-rNCxnHO-.js +1 -0
- package/dist/web/assets/useTimeout-_TcdZXP6.js +1 -0
- package/dist/web/assets/with-selector-DoElmmtd.js +1 -0
- package/dist/web/assets/workers-BH5CBOR3.js +1 -0
- package/dist/web/index.html +16 -10
- package/package.json +17 -12
- package/dist/web/assets/_name-DdyMEUN6.js +0 -6
- package/dist/web/assets/_name-eoobiMh0.js +0 -1
- package/dist/web/assets/_name-pUxlKZt5.js +0 -1
- package/dist/web/assets/badge-t7m0Vk1K.js +0 -146
- package/dist/web/assets/button-BoOukj77.js +0 -1
- package/dist/web/assets/core-CLXRiB63.js +0 -12
- package/dist/web/assets/empty-DbVYU7bi.js +0 -1
- package/dist/web/assets/engine-javascript-h-x4hGa4.js +0 -141
- package/dist/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/web/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/web/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/web/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/web/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/dist/web/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/dist/web/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/dist/web/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/web/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/dist/web/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/dist/web/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/web/assets/index-CVBBoW6r.css +0 -2
- package/dist/web/assets/index-CsW8KcJW.js +0 -10
- package/dist/web/assets/loops-DghpuoiG.js +0 -1
- package/dist/web/assets/operator-copy-DIsVXn17.js +0 -1
- package/dist/web/assets/overview-DmCIVPwN.js +0 -1
- package/dist/web/assets/rolldown-runtime-hePW80VL.js +0 -1
- package/dist/web/assets/routes-BDyP7vCr.js +0 -1
- package/dist/web/assets/run-drawer-B-xhTXe4.js +0 -157
- package/dist/web/assets/status-badge-yblcElE0.js +0 -1
- package/dist/web/assets/table-B8cLYNvq.js +0 -1
- package/dist/web/assets/useCompositeItem-HmBmWxUW.js +0 -1
- package/dist/web/assets/with-selector-N6m4X0X_.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/instance/ports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAsB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,sEAAsE;AACtE,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,WAAW,CACzD,mCAAmC,CACpC,CAAC,qBAAqB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;CAAG;AAEtE,kFAAkF;AAClF,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,KAAc,EAAE,EAAE,CACtD,MAAM,CAAC,OAAO,CACZ,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CACpE,CACF,CAAC;AAEJ,4FAA4F;AAC5F,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,EAAE,CACzC,KAAK;KACF,KAAK,CAAC,IAAI,CAAC;KACX,KAAK,CAAC,CAAC,CAAC;KACR,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;IAChB,MAAM,CAAC,EAAE,KAAK,EAAE,AAAD,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BAAmB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Schema } from "effect";
|
|
2
|
+
import { type UpCommand } from "../cli.ts";
|
|
3
|
+
/** An operating system process ID. */
|
|
4
|
+
export declare const ProcessId: Schema.brand<Schema.Int, "ProcessId">;
|
|
5
|
+
export type ProcessId = typeof ProcessId.Type;
|
|
6
|
+
declare const InstanceLaunch_base: Schema.Class<InstanceLaunch, Schema.Struct<{
|
|
7
|
+
/** The Node.js binary, from `process.execPath`. */
|
|
8
|
+
readonly node: Schema.NonEmptyString;
|
|
9
|
+
/** The Node.js options, from `process.execArgv`. */
|
|
10
|
+
readonly nodeOptions: Schema.$Array<Schema.String>;
|
|
11
|
+
/** The CLI entry point, from `process.argv[1]`. */
|
|
12
|
+
readonly script: Schema.NonEmptyString;
|
|
13
|
+
readonly port: Schema.brand<Schema.Int, "ServerPort">;
|
|
14
|
+
/** The origin of `--origin`, which a record omits without one. */
|
|
15
|
+
readonly origin: Schema.withConstructorDefault<Schema.OptionFromOptionalKey<Schema.brand<Schema.String, "UiOrigin">>>;
|
|
16
|
+
/** Decodes as `Info` from a record that a `usine up` without `--log-level` wrote. */
|
|
17
|
+
readonly logLevel: Schema.withDecodingDefaultKey<Schema.Literals<readonly ["Trace", "Debug", "Info", "Warn", "Error"]>, never>;
|
|
18
|
+
readonly allowVolatileInstance: Schema.Boolean;
|
|
19
|
+
}>, {}>;
|
|
20
|
+
/** The command that started a `usine up`, which `usine restart` runs again. */
|
|
21
|
+
export declare class InstanceLaunch extends InstanceLaunch_base {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns how this process was started with the settings of `command`. Dies without
|
|
25
|
+
* `process.argv[1]`, which a CLI always has.
|
|
26
|
+
*/
|
|
27
|
+
export declare const currentLaunch: ({ port, origin, logLevel, allowVolatileInstance }: UpCommand) => Effect.Effect<InstanceLaunch, never, never>;
|
|
28
|
+
declare const InstanceRecord_base: Schema.Class<InstanceRecord, Schema.Struct<{
|
|
29
|
+
readonly pid: Schema.brand<Schema.Int, "ProcessId">;
|
|
30
|
+
/** The `@usine/server` version of the process. */
|
|
31
|
+
readonly version: Schema.NonEmptyString;
|
|
32
|
+
readonly startedAt: Schema.DateTimeUtcFromString;
|
|
33
|
+
readonly launch: typeof InstanceLaunch;
|
|
34
|
+
/**
|
|
35
|
+
* The systemd service whose cgroup the process is in, which a record omits outside one. The CLI
|
|
36
|
+
* stops and starts the service with `systemctl` if systemd reports the process as its main one.
|
|
37
|
+
*/
|
|
38
|
+
readonly systemdUnit: Schema.withConstructorDefault<Schema.OptionFromOptionalKey<Schema.brand<Schema.String, "SystemdUnit">>>;
|
|
39
|
+
/** When the process received its first `SIGINT` or `SIGTERM`. */
|
|
40
|
+
readonly stoppingSince: Schema.optionalKey<Schema.DateTimeUtcFromString>;
|
|
41
|
+
}>, {}>;
|
|
42
|
+
/**
|
|
43
|
+
* The running `usine up` of an instance folder, as written to `.usine/instance.json`. A newer CLI
|
|
44
|
+
* reads the record that an older engine wrote, so a field added after the first version decodes
|
|
45
|
+
* with a default.
|
|
46
|
+
*/
|
|
47
|
+
export declare class InstanceRecord extends InstanceRecord_base {
|
|
48
|
+
}
|
|
49
|
+
declare const InstanceRecordError_base: Schema.Class<InstanceRecordError, Schema.TaggedStruct<"InstanceRecordError", {
|
|
50
|
+
readonly path: Schema.String;
|
|
51
|
+
readonly reason: Schema.String;
|
|
52
|
+
}>, import("effect/Cause").YieldableError>;
|
|
53
|
+
/** `.usine/instance.json` exists but doesn't decode as an `InstanceRecord`. */
|
|
54
|
+
export declare class InstanceRecordError extends InstanceRecordError_base {
|
|
55
|
+
}
|
|
56
|
+
/** The files that a `usine up` keeps in the instance's `.usine` folder. */
|
|
57
|
+
export interface InstanceFiles {
|
|
58
|
+
readonly folder: string;
|
|
59
|
+
readonly lock: string;
|
|
60
|
+
/** The process ID alone, for shell use such as `kill -HUP "$(cat .usine/instance.pid)"`. */
|
|
61
|
+
readonly pid: string;
|
|
62
|
+
readonly record: string;
|
|
63
|
+
/** The output of an instance that `usine up --detach` or `usine restart` started. */
|
|
64
|
+
readonly log: string;
|
|
65
|
+
readonly backups: string;
|
|
66
|
+
/** The instance's ID, which every `usine up` of the folder reuses. */
|
|
67
|
+
readonly id: string;
|
|
68
|
+
}
|
|
69
|
+
export declare const instanceFiles: (directory: string) => InstanceFiles;
|
|
70
|
+
/**
|
|
71
|
+
* Writes the record through a temporary file and a rename, so that readers never see a partial
|
|
72
|
+
* file.
|
|
73
|
+
*/
|
|
74
|
+
export declare const writeRecord: (files: InstanceFiles, record: InstanceRecord) => Effect.Effect<void, import("effect/PlatformError").PlatformError, FileSystem.FileSystem>;
|
|
75
|
+
/** Records `stoppingSince` synchronously, for use in a signal listener. Throws on failure. */
|
|
76
|
+
export declare const markStoppingSync: (files: InstanceFiles, record: InstanceRecord) => void;
|
|
77
|
+
/** Reads `.usine/instance.json`, or returns `None` if it doesn't exist. */
|
|
78
|
+
export declare const readRecord: (files: InstanceFiles) => Effect.Effect<Option.Option<InstanceRecord>, InstanceRecordError, FileSystem.FileSystem>;
|
|
79
|
+
/** Reads the process ID in `.usine/instance.pid`, or returns `None` if it's absent or invalid. */
|
|
80
|
+
export declare const readPid: (files: InstanceFiles) => Effect.Effect<Option.Option<number & import("effect/Brand").Brand<"ProcessId">>, never, FileSystem.FileSystem>;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/instance/record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtE,OAAO,EAAqC,KAAK,SAAS,EAAc,MAAM,WAAW,CAA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
+
import { renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { DateTime, Effect, FileSystem, Option, Schema } from "effect";
|
|
4
|
+
import { DEFAULT_LOG_LEVEL, Port, UiOrigin, UpLogLevel } from "../cli.js";
|
|
5
|
+
import { SystemdUnit } from "./systemd.js";
|
|
6
|
+
/** An operating system process ID. */
|
|
7
|
+
export const ProcessId = Schema.Int.check(Schema.isGreaterThan(0)).pipe(Schema.brand("ProcessId"));
|
|
8
|
+
/** The command that started a `usine up`, which `usine restart` runs again. */
|
|
9
|
+
export class InstanceLaunch extends Schema.Class("@usine/server/InstanceLaunch")({
|
|
10
|
+
/** The Node.js binary, from `process.execPath`. */
|
|
11
|
+
node: Schema.NonEmptyString,
|
|
12
|
+
/** The Node.js options, from `process.execArgv`. */
|
|
13
|
+
nodeOptions: Schema.Array(Schema.String),
|
|
14
|
+
/** The CLI entry point, from `process.argv[1]`. */
|
|
15
|
+
script: Schema.NonEmptyString,
|
|
16
|
+
port: Port,
|
|
17
|
+
/** The origin of `--origin`, which a record omits without one. */
|
|
18
|
+
origin: Schema.OptionFromOptionalKey(UiOrigin).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
19
|
+
/** Decodes as `Info` from a record that a `usine up` without `--log-level` wrote. */
|
|
20
|
+
logLevel: UpLogLevel.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_LOG_LEVEL))),
|
|
21
|
+
allowVolatileInstance: Schema.Boolean,
|
|
22
|
+
}) {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns how this process was started with the settings of `command`. Dies without
|
|
26
|
+
* `process.argv[1]`, which a CLI always has.
|
|
27
|
+
*/
|
|
28
|
+
export const currentLaunch = ({ port, origin, logLevel, allowVolatileInstance }) => Schema.decodeUnknownEffect(Schema.NonEmptyString)(process.argv[1]).pipe(Effect.map((script) => new InstanceLaunch({
|
|
29
|
+
node: process.execPath,
|
|
30
|
+
nodeOptions: process.execArgv,
|
|
31
|
+
script,
|
|
32
|
+
port,
|
|
33
|
+
origin,
|
|
34
|
+
logLevel,
|
|
35
|
+
allowVolatileInstance,
|
|
36
|
+
})), Effect.orDie);
|
|
37
|
+
/**
|
|
38
|
+
* The running `usine up` of an instance folder, as written to `.usine/instance.json`. A newer CLI
|
|
39
|
+
* reads the record that an older engine wrote, so a field added after the first version decodes
|
|
40
|
+
* with a default.
|
|
41
|
+
*/
|
|
42
|
+
export class InstanceRecord extends Schema.Class("@usine/server/InstanceRecord")({
|
|
43
|
+
pid: ProcessId,
|
|
44
|
+
/** The `@usine/server` version of the process. */
|
|
45
|
+
version: Schema.NonEmptyString,
|
|
46
|
+
startedAt: Schema.DateTimeUtcFromString,
|
|
47
|
+
launch: InstanceLaunch,
|
|
48
|
+
/**
|
|
49
|
+
* The systemd service whose cgroup the process is in, which a record omits outside one. The CLI
|
|
50
|
+
* stops and starts the service with `systemctl` if systemd reports the process as its main one.
|
|
51
|
+
*/
|
|
52
|
+
systemdUnit: Schema.OptionFromOptionalKey(SystemdUnit).pipe(Schema.withConstructorDefault(Effect.succeed(Option.none()))),
|
|
53
|
+
/** When the process received its first `SIGINT` or `SIGTERM`. */
|
|
54
|
+
stoppingSince: Schema.optionalKey(Schema.DateTimeUtcFromString),
|
|
55
|
+
}) {
|
|
56
|
+
}
|
|
57
|
+
/** `.usine/instance.json` exists but doesn't decode as an `InstanceRecord`. */
|
|
58
|
+
export class InstanceRecordError extends Schema.TaggedError("@usine/server/InstanceRecordError")("InstanceRecordError", { path: Schema.String, reason: Schema.String }) {
|
|
59
|
+
}
|
|
60
|
+
export const instanceFiles = (directory) => {
|
|
61
|
+
const folder = join(directory, ".usine");
|
|
62
|
+
return {
|
|
63
|
+
folder,
|
|
64
|
+
lock: join(folder, "instance.lock"),
|
|
65
|
+
pid: join(folder, "instance.pid"),
|
|
66
|
+
record: join(folder, "instance.json"),
|
|
67
|
+
log: join(folder, "usine.log"),
|
|
68
|
+
backups: join(folder, "backups"),
|
|
69
|
+
id: join(folder, "instance-id"),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const encodeRecord = (record) => `${JSON.stringify(Schema.encodeSync(InstanceRecord)(record), null, 2)}\n`;
|
|
73
|
+
const RecordFromJson = Schema.fromJsonString(InstanceRecord);
|
|
74
|
+
/**
|
|
75
|
+
* Writes the record through a temporary file and a rename, so that readers never see a partial
|
|
76
|
+
* file.
|
|
77
|
+
*/
|
|
78
|
+
export const writeRecord = Effect.fn("Instance.writeRecord")(function* (files, record) {
|
|
79
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
80
|
+
const staging = `${files.record}.${record.pid}`;
|
|
81
|
+
yield* fileSystem.writeFileString(staging, encodeRecord(record), { mode: 0o600 });
|
|
82
|
+
yield* fileSystem.rename(staging, files.record);
|
|
83
|
+
});
|
|
84
|
+
/** Records `stoppingSince` synchronously, for use in a signal listener. Throws on failure. */
|
|
85
|
+
export const markStoppingSync = (files, record) => {
|
|
86
|
+
const staging = `${files.record}.${record.pid}`;
|
|
87
|
+
const stopping = new InstanceRecord({
|
|
88
|
+
pid: record.pid,
|
|
89
|
+
version: record.version,
|
|
90
|
+
startedAt: record.startedAt,
|
|
91
|
+
launch: record.launch,
|
|
92
|
+
systemdUnit: record.systemdUnit,
|
|
93
|
+
stoppingSince: DateTime.nowUnsafe(),
|
|
94
|
+
});
|
|
95
|
+
writeFileSync(staging, encodeRecord(stopping), { mode: 0o600 });
|
|
96
|
+
renameSync(staging, files.record);
|
|
97
|
+
};
|
|
98
|
+
/** Reads `.usine/instance.json`, or returns `None` if it doesn't exist. */
|
|
99
|
+
export const readRecord = Effect.fn("Instance.readRecord")(function* (files) {
|
|
100
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
101
|
+
const failure = (reason) => new InstanceRecordError({ path: files.record, reason });
|
|
102
|
+
if (!(yield* fileSystem.exists(files.record).pipe(Effect.mapError((e) => failure(e.message))))) {
|
|
103
|
+
return Option.none();
|
|
104
|
+
}
|
|
105
|
+
const text = yield* fileSystem
|
|
106
|
+
.readFileString(files.record)
|
|
107
|
+
.pipe(Effect.mapError((error) => failure(error.message)));
|
|
108
|
+
return Option.some(yield* Schema.decodeUnknownEffect(RecordFromJson)(text).pipe(Effect.mapError((error) => failure(error.message))));
|
|
109
|
+
});
|
|
110
|
+
const PidFromText = Schema.Trim.pipe(Schema.decodeTo(Schema.NumberFromString), Schema.decodeTo(ProcessId));
|
|
111
|
+
/** Reads the process ID in `.usine/instance.pid`, or returns `None` if it's absent or invalid. */
|
|
112
|
+
export const readPid = Effect.fn("Instance.readPid")(function* (files) {
|
|
113
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
114
|
+
return yield* fileSystem.readFileString(files.pid).pipe(Effect.map(Schema.decodeUnknownOption(PidFromText)), Effect.orElseSucceed(() => Option.none()));
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/instance/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,sCAAsC;AACtC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AAGnG,+EAA+E;AA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,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,EACxC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC3B,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAoB;IAClF,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CACrD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,EACnD,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAa,CAAC,CACrD,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { InstanceRecord, ProcessId } from "./record.ts";
|
|
3
|
+
declare const Stopped_base: Schema.Class<Stopped, Schema.TaggedStruct<"Stopped", {
|
|
4
|
+
/** The PID that a process left in `.usine/` when it didn't exit cleanly. */
|
|
5
|
+
readonly stale: Schema.Option<Schema.brand<Schema.Int, "ProcessId">>;
|
|
6
|
+
}>, {}>;
|
|
7
|
+
/** No process holds the instance lock. */
|
|
8
|
+
export declare class Stopped extends Stopped_base {
|
|
9
|
+
}
|
|
10
|
+
declare const Running_base: Schema.Class<Running, Schema.TaggedStruct<"Running", {
|
|
11
|
+
readonly record: typeof InstanceRecord;
|
|
12
|
+
}>, {}>;
|
|
13
|
+
/** A live process holds the instance lock, and its record names it. */
|
|
14
|
+
export declare class Running extends Running_base {
|
|
15
|
+
}
|
|
16
|
+
declare const Unrecorded_base: Schema.Class<Unrecorded, Schema.TaggedStruct<"Unrecorded", {
|
|
17
|
+
readonly pid: Schema.Option<Schema.brand<Schema.Int, "ProcessId">>;
|
|
18
|
+
}>, {}>;
|
|
19
|
+
/**
|
|
20
|
+
* A process holds the instance lock without a record of a live process: a usine version that
|
|
21
|
+
* writes only `.usine/instance.pid`, or a process that is still starting.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Unrecorded extends Unrecorded_base {
|
|
24
|
+
}
|
|
25
|
+
export declare const InstanceState: Schema.Union<readonly [typeof Stopped, typeof Running, typeof Unrecorded]>;
|
|
26
|
+
export type InstanceState = typeof InstanceState.Type;
|
|
27
|
+
declare const SignalError_base: Schema.Class<SignalError, Schema.TaggedStruct<"SignalError", {
|
|
28
|
+
readonly pid: Schema.brand<Schema.Int, "ProcessId">;
|
|
29
|
+
readonly signal: Schema.String;
|
|
30
|
+
readonly reason: Schema.String;
|
|
31
|
+
}>, import("effect/Cause").YieldableError>;
|
|
32
|
+
/** The process couldn't be signaled, for example because another user owns it. */
|
|
33
|
+
export declare class SignalError extends SignalError_base {
|
|
34
|
+
}
|
|
35
|
+
/** Returns whether a process with the PID exists, including one that another user owns. */
|
|
36
|
+
export declare const processAlive: (pid: ProcessId) => Effect.Effect<boolean, never, never>;
|
|
37
|
+
/** Sends `signal` to the process. Succeeds if the process has already exited. */
|
|
38
|
+
export declare const signalProcess: (pid: number & import("effect/Brand").Brand<"ProcessId">, signal: "SIGKILL" | "SIGTERM") => Effect.Effect<void, SignalError, never>;
|
|
39
|
+
/**
|
|
40
|
+
* Reads whether `usine up` runs in the instance folder. The instance lock decides whether a process
|
|
41
|
+
* runs, so a PID that the OS reused for another process never counts.
|
|
42
|
+
*/
|
|
43
|
+
export declare const probeInstance: (directory: string & import("effect/Brand").Brand<"InstanceDirectory">) => Effect.Effect<Running | Stopped | Unrecorded, import("./lock.ts").InstanceLockError, import("effect/FileSystem").FileSystem>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/instance/state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAsC,MAAM,aAAa,CAAC;;IAMxF,4EAA4E;;;AAJhF,0CAA0C;AAC1C,qBAAa,OAAQ,SAAQ,YAM5B;CAAG;;;;AAEJ,uEAAuE;AACvE,qBAAa,OAAQ,SAAQ,YAG5B;CAAG;;;;AAEJ;;;GAGG;AACH,qBAAa,UAAW,SAAQ,eAG/B;CAAG;AAEJ,eAAO,MAAM,aAAa,4EAA+C,CAAC;AAC1E,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;;;;;;AAEtD,kFAAkF;AAClF,qBAAa,WAAY,SAAQ,gBAGhC;CAAG;AAIJ,2FAA2F;AAC3F,eAAO,MAAM,YAAY,QAAS,SAAS,yCAQvC,CAAC;AAEL,iFAAiF;AACjF,eAAO,MAAM,aAAa,qIAwBxB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,yMAoBxB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { lockHeld } from "./lock.js";
|
|
3
|
+
import { InstanceRecord, ProcessId, instanceFiles, readPid, readRecord } from "./record.js";
|
|
4
|
+
/** No process holds the instance lock. */
|
|
5
|
+
export class Stopped extends Schema.TaggedClass("@usine/server/InstanceStopped")("Stopped", {
|
|
6
|
+
/** The PID that a process left in `.usine/` when it didn't exit cleanly. */
|
|
7
|
+
stale: Schema.Option(ProcessId),
|
|
8
|
+
}) {
|
|
9
|
+
}
|
|
10
|
+
/** A live process holds the instance lock, and its record names it. */
|
|
11
|
+
export class Running extends Schema.TaggedClass("@usine/server/InstanceRunning")("Running", { record: InstanceRecord }) {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A process holds the instance lock without a record of a live process: a usine version that
|
|
15
|
+
* writes only `.usine/instance.pid`, or a process that is still starting.
|
|
16
|
+
*/
|
|
17
|
+
export class Unrecorded extends Schema.TaggedClass("@usine/server/InstanceUnrecorded")("Unrecorded", { pid: Schema.Option(ProcessId) }) {
|
|
18
|
+
}
|
|
19
|
+
export const InstanceState = Schema.Union([Stopped, Running, Unrecorded]);
|
|
20
|
+
/** The process couldn't be signaled, for example because another user owns it. */
|
|
21
|
+
export class SignalError extends Schema.TaggedError("@usine/server/SignalError")("SignalError", { pid: ProcessId, signal: Schema.String, reason: Schema.String }) {
|
|
22
|
+
}
|
|
23
|
+
const NoSuchProcess = Schema.Struct({ code: Schema.Literal("ESRCH") });
|
|
24
|
+
/** Returns whether a process with the PID exists, including one that another user owns. */
|
|
25
|
+
export const processAlive = (pid) => Effect.sync(() => {
|
|
26
|
+
try {
|
|
27
|
+
process.kill(pid, 0);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch (cause) {
|
|
31
|
+
return !Schema.is(NoSuchProcess)(cause);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
/** Sends `signal` to the process. Succeeds if the process has already exited. */
|
|
35
|
+
export const signalProcess = Effect.fn("Instance.signal")(function* (pid, signal) {
|
|
36
|
+
yield* Effect.annotateCurrentSpan({ pid, signal });
|
|
37
|
+
const sent = yield* Effect.try({
|
|
38
|
+
try: () => {
|
|
39
|
+
try {
|
|
40
|
+
return process.kill(pid, signal);
|
|
41
|
+
}
|
|
42
|
+
catch (cause) {
|
|
43
|
+
if (Schema.is(NoSuchProcess)(cause))
|
|
44
|
+
return false;
|
|
45
|
+
throw cause;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
catch: (cause) => new SignalError({
|
|
49
|
+
pid,
|
|
50
|
+
signal,
|
|
51
|
+
reason: cause instanceof Error ? cause.message : String(cause),
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
yield* sent
|
|
55
|
+
? Effect.logInfo("Sent a signal to the instance process", { pid, signal })
|
|
56
|
+
: Effect.logInfo("The instance process exited before the signal", { pid, signal });
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Reads whether `usine up` runs in the instance folder. The instance lock decides whether a process
|
|
60
|
+
* runs, so a PID that the OS reused for another process never counts.
|
|
61
|
+
*/
|
|
62
|
+
export const probeInstance = Effect.fn("Instance.probe")(function* (directory) {
|
|
63
|
+
const files = instanceFiles(directory);
|
|
64
|
+
const record = yield* readRecord(files).pipe(Effect.catchTag("InstanceRecordError", (error) => Effect.logWarning("The instance record is unreadable; it is ignored", {
|
|
65
|
+
path: error.path,
|
|
66
|
+
reason: error.reason,
|
|
67
|
+
}).pipe(Effect.as(Option.none()))));
|
|
68
|
+
if (!(yield* lockHeld(files))) {
|
|
69
|
+
const stale = Option.isSome(record) ? Option.some(record.value.pid) : yield* readPid(files);
|
|
70
|
+
return new Stopped({ stale });
|
|
71
|
+
}
|
|
72
|
+
if (Option.isSome(record) && (yield* processAlive(record.value.pid))) {
|
|
73
|
+
return new Running({ record: record.value });
|
|
74
|
+
}
|
|
75
|
+
const pid = yield* readPid(files);
|
|
76
|
+
const live = Option.isSome(pid) && (yield* processAlive(pid.value)) ? pid : Option.none();
|
|
77
|
+
return new Unrecorded({ pid: live });
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/instance/state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE5F,0CAA0C;AAC1C,MAAM,OAAO,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AG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC1F,OAAO,IAAI,UAAU,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Schema } from "effect";
|
|
2
|
+
/** A service of the systemd system manager, such as `usine.service`. */
|
|
3
|
+
export declare const SystemdUnit: Schema.brand<Schema.String, "SystemdUnit">;
|
|
4
|
+
export type SystemdUnit = typeof SystemdUnit.Type;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the system service in the contents of `/proc/<pid>/cgroup`, or `None` for a process
|
|
7
|
+
* outside one, such as in a login session or under a user's service manager.
|
|
8
|
+
*/
|
|
9
|
+
export declare const systemServiceOf: (cgroup: string) => Option.Option<SystemdUnit>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the system service whose cgroup this process is in, or `None` outside one and on systems
|
|
12
|
+
* without `/proc`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const currentSystemService: () => Effect.Effect<Option.Option<string & import("effect/Brand").Brand<"SystemdUnit">>, never, FileSystem.FileSystem>;
|
|
15
|
+
declare const SystemctlError_base: Schema.Class<SystemctlError, Schema.TaggedStruct<"SystemctlError", {
|
|
16
|
+
readonly command: Schema.String;
|
|
17
|
+
readonly unit: Schema.brand<Schema.String, "SystemdUnit">;
|
|
18
|
+
readonly reason: Schema.String;
|
|
19
|
+
}>, import("effect/Cause").YieldableError>;
|
|
20
|
+
/** `systemctl` couldn't run, or exited with a non-zero status. */
|
|
21
|
+
export declare class SystemctlError extends SystemctlError_base {
|
|
22
|
+
}
|
|
23
|
+
/** Runs `systemctl <args> <unit>` and returns its standard output. */
|
|
24
|
+
export declare const systemctl: (unit: SystemdUnit, args: ReadonlyArray<string>) => Effect.Effect<string, SystemctlError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns `unit` if systemd reports `pid` as its main process, or `None` without a unit or if
|
|
27
|
+
* the unit's main process is another one, as for a `usine up` that a service's script started.
|
|
28
|
+
*/
|
|
29
|
+
export declare const supervisingUnit: (pid: number & import("effect/Brand").Brand<"ProcessId">, unit: Option.Option<string & import("effect/Brand").Brand<"SystemdUnit">>) => Effect.Effect<Option.Option<string & import("effect/Brand").Brand<"SystemdUnit">>, SystemctlError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
|
|
30
|
+
/** Returns the state of `unit` from `systemctl show`. */
|
|
31
|
+
export declare const unitState: (unit: string & import("effect/Brand").Brand<"SystemdUnit">) => Effect.Effect<{
|
|
32
|
+
active: string;
|
|
33
|
+
sub: string;
|
|
34
|
+
}, SystemctlError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=systemd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemd.d.ts","sourceRoot":"","sources":["../../src/instance/systemd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAM5D,wEAAwE;AACxE,eAAO,MAAM,WAAW,4CAEW,CAAC;AACpC,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAMlD;;;GAGG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAIvE,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,oBAAoB,wHAe/B,CAAC;;;;;;AAEH,kEAAkE;AAClE,qBAAa,cAAe,SAAQ,mBAEqD;CAAG;AAE5F,sEAAsE;AACtE,eAAO,MAAM,SAAS,SAAU,WAAW,QAAQ,aAAa,CAAC,MAAM,CAAC,4GAIrE,CAAC;AAOJ;;;GAGG;AACH,eAAO,MAAM,eAAe,8SAe1B,CAAC;AAQH,yDAAyD;AACzD,eAAO,MAAM,SAAS;;;oFAapB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Schema } from "effect";
|
|
2
|
+
import { runCommand } from "../command.js";
|
|
3
|
+
const SYSTEMCTL_TIMEOUT = "30 seconds";
|
|
4
|
+
/** A service of the systemd system manager, such as `usine.service`. */
|
|
5
|
+
export const SystemdUnit = Schema.String.check(Schema.isPattern(/^[\w:.@\\-]+\.service$/u, { message: "Expected a systemd service name" })).pipe(Schema.brand("SystemdUnit"));
|
|
6
|
+
/** Matches the cgroup v2 line of a process in a system service: `0::/system.slice/usine.service`. */
|
|
7
|
+
const SYSTEM_SERVICE_CGROUP = /^0::\/system\.slice\/(?:[^/\n]+\.slice\/)*([^/\n]+\.service)(?:\/[^\n]*)?$/mu;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the system service in the contents of `/proc/<pid>/cgroup`, or `None` for a process
|
|
10
|
+
* outside one, such as in a login session or under a user's service manager.
|
|
11
|
+
*/
|
|
12
|
+
export const systemServiceOf = (cgroup) => Option.flatMap(Option.fromNullishOr(SYSTEM_SERVICE_CGROUP.exec(cgroup)?.[1]), Schema.decodeUnknownOption(SystemdUnit));
|
|
13
|
+
/**
|
|
14
|
+
* Returns the system service whose cgroup this process is in, or `None` outside one and on systems
|
|
15
|
+
* without `/proc`.
|
|
16
|
+
*/
|
|
17
|
+
export const currentSystemService = Effect.fn("Instance.currentSystemService")(function* () {
|
|
18
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
19
|
+
const cgroup = yield* fileSystem.readFileString("/proc/self/cgroup").pipe(Effect.tapError((error) => Effect.logDebug("Could not read this process's cgroup; no systemd service runs it", {
|
|
20
|
+
reason: error.message,
|
|
21
|
+
})), Effect.option);
|
|
22
|
+
const unit = Option.flatMap(cgroup, systemServiceOf);
|
|
23
|
+
if (Option.isSome(unit)) {
|
|
24
|
+
yield* Effect.logInfo("usine up runs in a systemd service", { unit: unit.value });
|
|
25
|
+
}
|
|
26
|
+
return unit;
|
|
27
|
+
});
|
|
28
|
+
/** `systemctl` couldn't run, or exited with a non-zero status. */
|
|
29
|
+
export class SystemctlError extends Schema.TaggedError("@usine/server/SystemctlError")("SystemctlError", { command: Schema.String, unit: SystemdUnit, reason: Schema.String }) {
|
|
30
|
+
}
|
|
31
|
+
/** Runs `systemctl <args> <unit>` and returns its standard output. */
|
|
32
|
+
export const systemctl = (unit, args) => runCommand("systemctl", [...args, unit], "/", SYSTEMCTL_TIMEOUT).pipe(Effect.map(({ stdout }) => stdout), Effect.mapError(({ command, reason }) => new SystemctlError({ command, unit, reason })));
|
|
33
|
+
const MainPid = Schema.Trim.pipe(Schema.decodeTo(Schema.NumberFromString), Schema.decodeTo(Schema.Int));
|
|
34
|
+
/**
|
|
35
|
+
* Returns `unit` if systemd reports `pid` as its main process, or `None` without a unit or if
|
|
36
|
+
* the unit's main process is another one, as for a `usine up` that a service's script started.
|
|
37
|
+
*/
|
|
38
|
+
export const supervisingUnit = Effect.fn("Instance.supervisingUnit")(function* (pid, unit) {
|
|
39
|
+
if (Option.isNone(unit))
|
|
40
|
+
return Option.none();
|
|
41
|
+
yield* Effect.annotateCurrentSpan({ pid, unit: unit.value });
|
|
42
|
+
const mainPid = Schema.decodeUnknownOption(MainPid)(yield* systemctl(unit.value, ["show", "--property=MainPID", "--value"]));
|
|
43
|
+
if (Option.contains(mainPid, pid))
|
|
44
|
+
return unit;
|
|
45
|
+
yield* Effect.logInfo("The instance process isn't the main process of its systemd service; usine signals it directly", { pid, unit: unit.value, mainPid: Option.getOrUndefined(mainPid) });
|
|
46
|
+
return Option.none();
|
|
47
|
+
});
|
|
48
|
+
/** Returns the state of `unit` from `systemctl show`. */
|
|
49
|
+
export const unitState = Effect.fn("Instance.unitState")(function* (unit) {
|
|
50
|
+
const properties = new Map((yield* systemctl(unit, ["show", "--property=ActiveState", "--property=SubState"]))
|
|
51
|
+
.split("\n")
|
|
52
|
+
.map((line) => {
|
|
53
|
+
const separator = line.indexOf("=");
|
|
54
|
+
return [line.slice(0, separator), line.slice(separator + 1).trim()];
|
|
55
|
+
}));
|
|
56
|
+
return {
|
|
57
|
+
active: properties.get("ActiveState") ?? "unknown",
|
|
58
|
+
sub: properties.get("SubState") ?? "unknown",
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=systemd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemd.js","sourceRoot":"","sources":["../../src/instance/systemd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAEvC,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAC5C,MAAM,CAAC,SAAS,CAAC,yBAAyB,EAAE,EAAE,OAAO,EAAE,iCAAiC,EAAE,CAAC,CAC5F,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;AAGpC,qGAAqG;AACrG,MAAM,qBAAqB,GACzB,8EAA8E,CAAC;AAEjF;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAA8B,EAAE,CAC5E,MAAM,CAAC,OAAO,CACZ,MAAM,CAAC,aAAa,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAC7D,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CACxC,CAAC;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,+BAA+B,CAAC,CAAC,QAAQ,CAAC;I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AC,CAAC,QAAQ,CAAC,EAAE,IAAiB;IACnF,MAAM,UAAU,GAAG,IAAI,GAAG,CACxB,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,wBAAwB,EAAE,qBAAqB,CAAC,CAAC,CAAC;SAChF,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAU,CAAC;IAC/E,CAAC,CAAC,CACL,CAAC;IACF,OAAO;QACL,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,SAAS;QAClD,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,SAAS;KACzB,CAAC;AACxB,CAAC,CAAC,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAsBA,8FAA8F;AAC9F,eAAO,MAAM,WAAW,mDAAiD,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Cause, Console, Logger, References } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Effect's default logger with an ISO 8601 UTC timestamp, such as `[2026-10-27T02:25:13.123Z]`, in
|
|
4
|
+
* place of the local time of day, which has no date or offset and shifts with the process's time
|
|
5
|
+
* zone (#603).
|
|
6
|
+
*/
|
|
7
|
+
const utcLogger = Logger.make(({ cause, date, fiber, logLevel, message }) => {
|
|
8
|
+
const parts = Array.isArray(message) ? [...message] : [message];
|
|
9
|
+
if (cause.reasons.length > 0)
|
|
10
|
+
parts.push(Cause.pretty(cause));
|
|
11
|
+
const annotations = fiber.getRef(References.CurrentLogAnnotations);
|
|
12
|
+
if (Object.keys(annotations).length > 0)
|
|
13
|
+
parts.push(annotations);
|
|
14
|
+
const spans = fiber
|
|
15
|
+
.getRef(References.CurrentLogSpans)
|
|
16
|
+
.map(([label, start]) => ` ${label.replace(/[\s="]/gu, "_")}=${date.getTime() - start}ms`)
|
|
17
|
+
.join("");
|
|
18
|
+
const console = fiber.getRef(Console.Console);
|
|
19
|
+
const line = `[${date.toISOString()}] ${logLevel.toUpperCase()} (#${fiber.id})${spans}:`;
|
|
20
|
+
if (fiber.getRef(References.LogToStderr))
|
|
21
|
+
console.error(line, ...parts);
|
|
22
|
+
else
|
|
23
|
+
console.log(line, ...parts);
|
|
24
|
+
});
|
|
25
|
+
/** Replaces the default loggers of every usine command: log lines in UTC, and span events. */
|
|
26
|
+
export const loggerLayer = Logger.layer([utcLogger, Logger.tracerLogger]);
|
|
27
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE5D;;;;GAIG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAgB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;IACzF,MAAM,KAAK,GAAmB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAChF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK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"@usine/core/instance";
|
|
4
|
+
import { Config, ConfigProvider, Console, Effect, Layer, Match } from "effect";
|
|
5
|
+
import { FetchHttpClient } from "effect/http";
|
|
4
6
|
import { CLI_USAGE, packageVersion, parseCli } from "./cli.js";
|
|
7
|
+
import { failureMessage } from "./failure-message.js";
|
|
8
|
+
import { instanceEnvironment } from "./instance/environment.js";
|
|
9
|
+
import { loggerLayer } from "./logger.js";
|
|
10
|
+
/** The exit status of `usine status` when no `usine up` runs, as for LSB init scripts. */
|
|
11
|
+
const NOT_RUNNING_STATUS = 3;
|
|
5
12
|
const exitWith = (message) => Console.error(message).pipe(Effect.andThen(Effect.sync(() => {
|
|
6
13
|
process.exitCode = 1;
|
|
7
14
|
})));
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
const cliEnvironment = Config.all({
|
|
16
|
+
port: Config.option(Config.String("USINE_PORT")),
|
|
17
|
+
origin: Config.option(Config.String("USINE_ORIGIN")),
|
|
18
|
+
logLevel: Config.option(Config.String("USINE_LOG_LEVEL")),
|
|
19
|
+
allowVolatileInstance: Config.option(Config.String("USINE_ALLOW_VOLATILE_INSTANCE")),
|
|
20
|
+
});
|
|
21
|
+
// Untraced: a span around `usine up`, which never returns, would parent every span it exports.
|
|
22
|
+
const runCommand = Effect.fnUntraced(function* (directory) {
|
|
23
|
+
// An environment and a parsed .env don't fail to load, so a ConfigError here is a defect.
|
|
24
|
+
const environment = yield* Effect.orDie(cliEnvironment);
|
|
25
|
+
const command = yield* parseCli(process.argv.slice(2), environment);
|
|
13
26
|
return yield* Match.valueTags(command, {
|
|
14
27
|
HelpCommand: () => Console.log(CLI_USAGE),
|
|
15
28
|
VersionCommand: () => Effect.flatMap(packageVersion(), Console.log),
|
|
16
29
|
ExportRunCommand: ({ runId, output }) => Effect.flatMap(Effect.promise(() => import("./export-run.js")), ({ exportRun }) => exportRun(runId, output)),
|
|
17
|
-
BackupCommand: ({ output }) => Effect.flatMap(Effect.promise(() => import("./backup.js")), ({ backup }) => backup(output)),
|
|
18
|
-
UpCommand: (
|
|
30
|
+
BackupCommand: ({ output }) => Effect.flatMap(Effect.promise(() => import("./backup.js")), ({ backup }) => backup(directory, output)),
|
|
31
|
+
UpCommand: (command) => command.detach
|
|
32
|
+
? Effect.flatMap(Effect.promise(() => import("./detach.js")), ({ upDetached }) => upDetached(directory, command))
|
|
33
|
+
: Effect.flatMap(Effect.promise(() => import("./up.js")), ({ up }) => up(command)),
|
|
34
|
+
StatusCommand: () => Effect.flatMap(Effect.promise(() => import("./status.js")), ({ status }) => status(directory)).pipe(Effect.flatMap(({ running, lines }) => Effect.forEach(lines, (line) => Console.log(line), { discard: true }).pipe(Effect.andThen(Effect.sync(() => {
|
|
35
|
+
if (!running)
|
|
36
|
+
process.exitCode = NOT_RUNNING_STATUS;
|
|
37
|
+
}))))),
|
|
38
|
+
StopCommand: ({ options }) => Effect.flatMap(Effect.promise(() => import("./stop.js")), ({ stop }) => stop(directory, options)),
|
|
39
|
+
RestartCommand: ({ options }) => Effect.flatMap(Effect.promise(() => import("./restart.js")), ({ restart, fallbackLaunch }) => restart(directory, options, fallbackLaunch(environment))),
|
|
40
|
+
UpgradeCommand: (upgradeCommand) => Effect.flatMap(Effect.promise(() => import("./upgrade.js")), ({ upgrade }) => upgrade(directory, upgradeCommand)),
|
|
19
41
|
});
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
PortInUseError: ({ port }) => exitWith(`Port ${port} is already in use. Stop the process using it or run usine up --port <port>.`),
|
|
29
|
-
}));
|
|
42
|
+
});
|
|
43
|
+
const main = Effect.gen(function* () {
|
|
44
|
+
const directory = InstanceDirectory.make(process.cwd());
|
|
45
|
+
const environment = yield* instanceEnvironment(directory, yield* ConfigProvider.ConfigProvider);
|
|
46
|
+
return yield* runCommand(directory).pipe(Effect.provideService(ConfigProvider.ConfigProvider, environment));
|
|
47
|
+
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer, loggerLayer)),
|
|
48
|
+
// Only typed failures are caught: a defect still crashes with its full cause.
|
|
49
|
+
Effect.catch((failure) => exitWith(failureMessage(failure))));
|
|
30
50
|
NodeRuntime.runMain(main);
|
|
31
51
|
//# sourceMappingURL=main.js.map
|