stitchkit 0.127.0 → 0.128.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/CHANGELOG.md +137 -6
- package/dist/agent-executor/acp/v1-connect.d.ts +9 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +8 -2
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +8 -0
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +4 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/protocol.d.ts +20 -2
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
- package/dist/agent-executor/claude/session.d.ts +2 -1
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude/transcript.d.ts +7 -4
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +4 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +4 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/protocol.d.ts +26 -2
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/session.d.ts +3 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +71 -0
- package/dist/agent-executor/image-input.d.ts.map +1 -0
- package/dist/agent-executor/session-primitives.d.ts +0 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-runtime/agent-tool.d.ts +21 -7
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
- package/dist/agent-runtime/branch-contract.d.ts +1 -0
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +5 -2
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +9 -9
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +45 -32
- package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts +12 -6
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-source.d.ts +13 -1
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/child-tools.d.ts +64 -0
- package/dist/agent-runtime/child-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-tools.d.ts +82 -5
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-payload.d.ts +12 -0
- package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-read.d.ts +6 -3
- package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-schema.d.ts +50 -8
- package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
- package/dist/agent-runtime/invocations.d.ts +20 -9
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/postgres.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-tools.d.ts +30 -0
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-invocation-payload.d.ts +48 -0
- package/dist/agent-runtime/schemas-invocation-payload.d.ts.map +1 -0
- package/dist/agent-runtime/sql-events.d.ts.map +1 -1
- package/dist/agent-runtime/sql-session.d.ts +11 -0
- package/dist/agent-runtime/sql-session.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
- package/dist/agent-runtime/state-tools.d.ts +55 -0
- package/dist/agent-runtime/state-tools.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/store-create.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +12 -0
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-events.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +7 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/declaration/declaration.d.ts +6 -3
- package/dist/declaration/declaration.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +23 -12
- package/dist/entrypoints/agent-executor/claude-sdk.js +26 -10
- package/dist/entrypoints/agent-executor/claude.js +35 -16
- package/dist/entrypoints/agent-executor/codex.js +81 -21
- package/dist/entrypoints/agent-executor.js +1 -1
- package/dist/entrypoints/agent-runtime/harness.js +5 -6
- package/dist/entrypoints/agent-runtime/openrouter.js +2 -2
- package/dist/entrypoints/agent-runtime/postgres.js +8 -3
- package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +4 -4
- package/dist/entrypoints/agent-runtime/sqlite/node.js +4 -4
- package/dist/entrypoints/agent-runtime/testing.js +6 -6
- package/dist/entrypoints/agent-runtime.d.ts +9 -7
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +246 -199
- package/dist/entrypoints/application/diagnostic-journal.js +4 -4
- package/dist/entrypoints/application/directory-inbox.js +8 -8
- package/dist/entrypoints/cli/publish.js +8 -8
- package/dist/entrypoints/cli.js +10 -9
- package/dist/entrypoints/declaration.js +0 -1
- package/dist/entrypoints/files.js +40 -17
- package/dist/entrypoints/node.js +4 -4
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process.js +1 -1
- package/dist/entrypoints/server.js +7 -7
- package/dist/entrypoints/service-host/macos.js +4 -4
- package/dist/entrypoints/service-host.d.ts +4 -1
- package/dist/entrypoints/service-host.d.ts.map +1 -1
- package/dist/entrypoints/service-host.js +831 -220
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/telegram.js +4 -4
- package/dist/entrypoints/tools/agent.js +4 -3
- package/dist/entrypoints/tools/invoker.js +3 -2
- package/dist/entrypoints/tools/mcp.js +4 -3
- package/dist/entrypoints/tools/toolkit.js +6 -5
- package/dist/entrypoints/tools.d.ts +1 -1
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +10 -8
- package/dist/files/directory-appearance.d.ts +20 -9
- package/dist/files/directory-appearance.d.ts.map +1 -1
- package/dist/files/polled-json.d.ts.map +1 -1
- package/dist/files/regular-file.d.ts +15 -5
- package/dist/files/regular-file.d.ts.map +1 -1
- package/dist/{index-z4k0hqp9.js → index-0gqs8ght.js} +106 -24
- package/dist/{index-caywx1c0.js → index-13dnv6d0.js} +107 -10
- package/dist/{index-a725ayvz.js → index-1qwrczr1.js} +1 -1
- package/dist/{index-xtkw9866.js → index-2c5w2d1d.js} +1 -1
- package/dist/{index-g1q7fwn9.js → index-2nwvn7m2.js} +1 -1
- package/dist/{index-4s2w4g37.js → index-3tnwtz38.js} +80 -2
- package/dist/{index-5e0zsbf7.js → index-4j8efqr3.js} +1 -1
- package/dist/{index-p1m9djt6.js → index-5v5vg85s.js} +1 -1
- package/dist/{index-x90w78yz.js → index-673drwkn.js} +23 -8
- package/dist/{index-7xp05h20.js → index-6wp4dn9d.js} +6 -6
- package/dist/{index-0hdm5sx6.js → index-8x22nprv.js} +6 -2
- package/dist/{index-j13gzgdv.js → index-bz3gn6cs.js} +8 -4
- package/dist/{index-d96c1n1q.js → index-c5gp2gh6.js} +20 -19
- package/dist/{index-wbnpa8z6.js → index-d54npte7.js} +4 -4
- package/dist/{index-kmbpej2y.js → index-emgrmavr.js} +102 -61
- package/dist/{index-bbzvrq66.js → index-g3e57qj6.js} +455 -202
- package/dist/index-gf92hc87.js +100 -0
- package/dist/{index-3djgv3ch.js → index-gzny6zsw.js} +25 -10
- package/dist/{index-3b31z0pc.js → index-hj1zq7mh.js} +12 -6
- package/dist/{index-8xr2eq99.js → index-jfecdk1e.js} +3 -3
- package/dist/{index-dvd1qdwa.js → index-ke02kxsr.js} +3 -3
- package/dist/{index-83n766x4.js → index-m18xm96h.js} +15 -9
- package/dist/{index-qnzhmk2s.js → index-n7f89hjw.js} +90 -47
- package/dist/{index-3agqmmrg.js → index-pn5b11ce.js} +7 -9
- package/dist/{index-3gwp8ez6.js → index-pwskmywy.js} +12 -17
- package/dist/{index-9wh98cpa.js → index-rxnyygke.js} +130 -90
- package/dist/{index-0djnptn8.js → index-rzeezh79.js} +10 -3
- package/dist/{index-nbv44x0x.js → index-s2e3h616.js} +137 -36
- package/dist/{index-5zwac8ft.js → index-t7wa7k12.js} +2 -2
- package/dist/{index-xypxnzhp.js → index-v1mxss62.js} +2 -2
- package/dist/index-vgzhw2zk.js +304 -0
- package/dist/{index-jrka9029.js → index-vmbxj75t.js} +2 -2
- package/dist/{index-j516jaaz.js → index-waa6t4zx.js} +49 -2
- package/dist/{index-fcw255hd.js → index-xv9jb84s.js} +2 -2
- package/dist/{index-dwa6pskj.js → index-y065r8g5.js} +82 -43
- package/dist/internal/bounded-file-confirm.d.ts +32 -0
- package/dist/internal/bounded-file-confirm.d.ts.map +1 -0
- package/dist/internal/bounded-file-read.d.ts +10 -7
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/internal/file-observation.d.ts +5 -1
- package/dist/internal/file-observation.d.ts.map +1 -1
- package/dist/internal/process-instance.d.ts +8 -0
- package/dist/internal/process-instance.d.ts.map +1 -1
- package/dist/internal/unix-socket.d.ts +3 -1
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/server/unix-client.d.ts +7 -0
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/service-host/systemd-inspect.d.ts +3 -1
- package/dist/service-host/systemd-inspect.d.ts.map +1 -1
- package/dist/service-host/systemd-render-shared.d.ts +64 -0
- package/dist/service-host/systemd-render-shared.d.ts.map +1 -0
- package/dist/service-host/systemd-render.d.ts +31 -26
- package/dist/service-host/systemd-render.d.ts.map +1 -1
- package/dist/service-host/systemd-timer-render.d.ts +31 -0
- package/dist/service-host/systemd-timer-render.d.ts.map +1 -0
- package/dist/service-host/systemd-timer-rollback.d.ts +26 -0
- package/dist/service-host/systemd-timer-rollback.d.ts.map +1 -0
- package/dist/service-host/systemd-timer.d.ts +82 -0
- package/dist/service-host/systemd-timer.d.ts.map +1 -0
- package/dist/service-host/systemd-unit-ops.d.ts +26 -0
- package/dist/service-host/systemd-unit-ops.d.ts.map +1 -0
- package/dist/service-host/systemd.d.ts +1 -1
- package/dist/service-host/systemd.d.ts.map +1 -1
- package/dist/tools/access.d.ts +30 -1
- package/dist/tools/access.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -2
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-scan.d.ts +5 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts +11 -5
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +2 -1
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/notices.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -1
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +2 -3
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -3
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -5
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +10 -6
- package/llms/agent-executor-claude-sdk.txt +1 -1
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-runtime.4.txt +21 -9
- package/llms/cli.3.txt +4 -4
- package/llms/cli.txt +1 -0
- package/llms/declaration.txt +2 -2
- package/llms/files.txt +1 -1
- package/llms/node.txt +2 -2
- package/llms/server.5.txt +2 -2
- package/llms/service-host.txt +5 -5
- package/llms/stitchkit.txt +81 -77
- package/llms/tools.3.txt +3 -2
- package/llms/upgrading-0.128.0.txt +147 -0
- package/llms/upgrading.txt +1 -0
- package/llms-full.txt +272 -113
- package/llms.txt +14 -13
- package/package.json +1 -1
- package/dist/index-ajmtxsky.js +0 -193
- package/dist/index-ax3wns1a.js +0 -93
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
fileIdentity2,
|
|
5
5
|
readRegularFileSync2,
|
|
6
6
|
parseJsonBytes2
|
|
7
|
-
} from "../index-
|
|
7
|
+
} from "../index-pwskmywy.js";
|
|
8
8
|
import {
|
|
9
9
|
ARTIFACT_MANIFEST_FILENAME2,
|
|
10
10
|
DEFAULT_ARTIFACT_MAX_FILE_BYTES2,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
assertAbsolutePlistPath,
|
|
35
35
|
lintLaunchdPlist2,
|
|
36
36
|
readLaunchdPlist2
|
|
37
|
-
} from "../index-
|
|
37
|
+
} from "../index-xv9jb84s.js";
|
|
38
38
|
import"../index-6kec3b14.js";
|
|
39
39
|
import {
|
|
40
40
|
probeLiveness,
|
|
@@ -44,12 +44,12 @@ import {
|
|
|
44
44
|
observeProcessInstanceAt,
|
|
45
45
|
probeProcessOwner2,
|
|
46
46
|
probeProcessOwnerWith
|
|
47
|
-
} from "../index-
|
|
47
|
+
} from "../index-673drwkn.js";
|
|
48
48
|
import"../index-v59pxmf1.js";
|
|
49
49
|
import"../index-7kfcb576.js";
|
|
50
50
|
import {
|
|
51
51
|
PolledJsonFile2
|
|
52
|
-
} from "../index-
|
|
52
|
+
} from "../index-bz3gn6cs.js";
|
|
53
53
|
import {
|
|
54
54
|
runNativeCommand2
|
|
55
55
|
} from "../index-5ptwb6ka.js";
|
|
@@ -65,10 +65,10 @@ import {
|
|
|
65
65
|
} from "../index-5cc6r990.js";
|
|
66
66
|
import {
|
|
67
67
|
syncDirectory
|
|
68
|
-
} from "../index-
|
|
68
|
+
} from "../index-2c5w2d1d.js";
|
|
69
69
|
import {
|
|
70
70
|
closeAfterSync
|
|
71
|
-
} from "../index-
|
|
71
|
+
} from "../index-s2e3h616.js";
|
|
72
72
|
import {
|
|
73
73
|
stagingName
|
|
74
74
|
} from "../index-39n02e0q.js";
|
|
@@ -1727,7 +1727,7 @@ async function reloadLaunchdJob(options) {
|
|
|
1727
1727
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
1728
1728
|
import { dirname as dirname2, join as join3, posix } from "node:path";
|
|
1729
1729
|
|
|
1730
|
-
// src/service-host/systemd-render.ts
|
|
1730
|
+
// src/service-host/systemd-render-shared.ts
|
|
1731
1731
|
import { z as z2 } from "zod";
|
|
1732
1732
|
var SystemdScopeSchema = z2.enum(["system", "user"]);
|
|
1733
1733
|
|
|
@@ -1745,9 +1745,40 @@ class SystemdUnitError extends Error {
|
|
|
1745
1745
|
this.foreignDropIns = options?.foreignDropIns;
|
|
1746
1746
|
}
|
|
1747
1747
|
}
|
|
1748
|
+
var OCTAL_MODE_PATTERN = /^[0-7]{3,4}$/;
|
|
1748
1749
|
var ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1749
1750
|
var EXEC_PREFIX = /^[-@:+!]/;
|
|
1750
1751
|
var EXEC_PREFIX_MESSAGE = "the executable must not start with one of systemd's prefixes (-, @, :, +, !): quoting does not disarm them";
|
|
1752
|
+
var SYSTEMD_TIMESPAN_UNIT = "(?:usec|us|msec|ms|seconds|second|sec|s|minutes|minute|min|m|hours|hour|hr|h|days|day|d|weeks|week|w|months|month|M|years|year|y)";
|
|
1753
|
+
var SYSTEMD_TIMESPAN_PATTERN = new RegExp(`^\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?(?:\\s+\\d+(?:\\.\\d+)?${SYSTEMD_TIMESPAN_UNIT}?)*$`);
|
|
1754
|
+
var SYSTEMD_SIGNAL_PATTERN = /^(?:SIG)?(?:HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR1|SEGV|USR2|PIPE|ALRM|TERM|CHLD|CONT|STOP|TSTP|TTIN|TTOU|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS)$/;
|
|
1755
|
+
var MAX_SYSTEMD_INTERVAL_SECONDS = 18446744073708;
|
|
1756
|
+
var SystemdIntervalSecondsSchema = z2.number().finite().nonnegative().max(MAX_SYSTEMD_INTERVAL_SECONDS);
|
|
1757
|
+
var SystemdTimespanSchema = z2.union([
|
|
1758
|
+
SystemdIntervalSecondsSchema,
|
|
1759
|
+
z2.string().regex(SYSTEMD_TIMESPAN_PATTERN, "must be a valid systemd timespan")
|
|
1760
|
+
]);
|
|
1761
|
+
var SystemdTimeoutSchema = z2.union([
|
|
1762
|
+
SystemdIntervalSecondsSchema,
|
|
1763
|
+
z2.literal("infinity"),
|
|
1764
|
+
z2.string().regex(SYSTEMD_TIMESPAN_PATTERN, 'must be a valid systemd timespan or "infinity"')
|
|
1765
|
+
]);
|
|
1766
|
+
var SystemdBindReadOnlyPathSchema = z2.union([
|
|
1767
|
+
z2.string().min(1),
|
|
1768
|
+
z2.strictObject({
|
|
1769
|
+
source: z2.string().min(1),
|
|
1770
|
+
target: z2.string().min(1).optional(),
|
|
1771
|
+
ignoreMissing: z2.boolean().optional()
|
|
1772
|
+
})
|
|
1773
|
+
]);
|
|
1774
|
+
var SystemdSuccessExitStatusItemSchema = z2.union([
|
|
1775
|
+
z2.number().int().min(0).max(255),
|
|
1776
|
+
z2.string().regex(SYSTEMD_SIGNAL_PATTERN, "must be an exit code 0..255 or POSIX signal name")
|
|
1777
|
+
]);
|
|
1778
|
+
var SystemdAddressFamilySchema = z2.union([
|
|
1779
|
+
z2.literal("none"),
|
|
1780
|
+
z2.string().regex(/^AF_[A-Z0-9_]+$/, 'must be "none" or an AF_* address family')
|
|
1781
|
+
]);
|
|
1751
1782
|
function hasLineBreakOrNul(value) {
|
|
1752
1783
|
return value.includes(`
|
|
1753
1784
|
`) || value.includes("\r") || value.includes("\x00");
|
|
@@ -1816,193 +1847,53 @@ function formatSystemdScalar(field, value, allowHomeSpecifier, forbidWhitespace
|
|
|
1816
1847
|
assertNoWhitespace(field, value);
|
|
1817
1848
|
return escapeSystemdSpecifiers(value, allowHomeSpecifier);
|
|
1818
1849
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
workingDirectory: z2.string().min(1).optional(),
|
|
1825
|
-
environment: z2.record(z2.string(), z2.string()).optional(),
|
|
1826
|
-
environmentFile: z2.union([z2.string().min(1), z2.array(z2.string().min(1))]).optional(),
|
|
1827
|
-
user: z2.string().min(1).optional(),
|
|
1828
|
-
group: z2.string().min(1).optional(),
|
|
1829
|
-
type: z2.enum(["simple", "exec", "forking", "oneshot", "notify"]).optional(),
|
|
1830
|
-
restart: z2.enum([
|
|
1831
|
-
"no",
|
|
1832
|
-
"on-success",
|
|
1833
|
-
"on-failure",
|
|
1834
|
-
"on-abnormal",
|
|
1835
|
-
"on-watchdog",
|
|
1836
|
-
"on-abort",
|
|
1837
|
-
"always"
|
|
1838
|
-
]).default("on-failure"),
|
|
1839
|
-
restartSec: z2.union([z2.number().nonnegative(), z2.string().min(1)]).optional(),
|
|
1840
|
-
timeoutStopSec: z2.union([z2.number().positive(), z2.string().min(1)]).optional(),
|
|
1841
|
-
killMode: z2.enum(["control-group", "mixed", "process", "none"]).optional(),
|
|
1842
|
-
oomScoreAdjust: z2.number().int().min(-1000).max(1000).optional(),
|
|
1843
|
-
oomPolicy: z2.enum(["continue", "stop", "kill"]).optional(),
|
|
1844
|
-
ioAccounting: z2.boolean().optional(),
|
|
1845
|
-
umask: z2.string().regex(/^0?[0-7]{3,4}$/).optional(),
|
|
1846
|
-
noNewPrivileges: z2.boolean().optional(),
|
|
1847
|
-
runtimeDirectory: z2.union([z2.string().min(1), z2.array(z2.string().min(1))]).optional(),
|
|
1848
|
-
limitNOFILE: z2.union([z2.number().int().positive(), z2.literal("infinity")]).optional(),
|
|
1849
|
-
after: z2.array(z2.string().min(1)).optional(),
|
|
1850
|
-
wants: z2.array(z2.string().min(1)).optional(),
|
|
1851
|
-
wantedBy: z2.array(z2.string().min(1)).optional(),
|
|
1852
|
-
allowHomeSpecifier: z2.boolean().default(false)
|
|
1853
|
-
}).check((ctx) => {
|
|
1854
|
-
const value = ctx.value;
|
|
1855
|
-
if ((value.execStart[0] ?? "").length === 0) {
|
|
1856
|
-
ctx.issues.push({
|
|
1857
|
-
code: "custom",
|
|
1858
|
-
input: value.execStart,
|
|
1859
|
-
path: ["execStart", 0],
|
|
1860
|
-
message: "execStart[0] must be a non-empty executable path"
|
|
1861
|
-
});
|
|
1862
|
-
} else if (EXEC_PREFIX.test(value.execStart[0] ?? "")) {
|
|
1863
|
-
ctx.issues.push({
|
|
1864
|
-
code: "custom",
|
|
1865
|
-
input: value.execStart,
|
|
1866
|
-
path: ["execStart", 0],
|
|
1867
|
-
message: EXEC_PREFIX_MESSAGE
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
if (value.execStartPre !== undefined) {
|
|
1871
|
-
for (let index = 0;index < value.execStartPre.length; index += 1) {
|
|
1872
|
-
const cmd = value.execStartPre[index];
|
|
1873
|
-
if ((cmd?.[0] ?? "").length === 0) {
|
|
1874
|
-
ctx.issues.push({
|
|
1875
|
-
code: "custom",
|
|
1876
|
-
input: cmd,
|
|
1877
|
-
path: ["execStartPre", index, 0],
|
|
1878
|
-
message: `execStartPre[${index}][0] must be a non-empty executable path`
|
|
1879
|
-
});
|
|
1880
|
-
} else if (EXEC_PREFIX.test(cmd?.[0] ?? "")) {
|
|
1881
|
-
ctx.issues.push({
|
|
1882
|
-
code: "custom",
|
|
1883
|
-
input: cmd,
|
|
1884
|
-
path: ["execStartPre", index, 0],
|
|
1885
|
-
message: EXEC_PREFIX_MESSAGE
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
if (value.scope === "user" && (value.user !== undefined || value.group !== undefined)) {
|
|
1891
|
-
ctx.issues.push({
|
|
1892
|
-
code: "custom",
|
|
1893
|
-
input: value,
|
|
1894
|
-
path: ["scope"],
|
|
1895
|
-
message: "systemd user units cannot declare 'user' or 'group'"
|
|
1896
|
-
});
|
|
1850
|
+
function formatSystemdNumber(value) {
|
|
1851
|
+
if (Number.isInteger(value))
|
|
1852
|
+
return String(value);
|
|
1853
|
+
if (value > 0 && value < 0.000001) {
|
|
1854
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd numeric duration ${value} is below microsecond precision and would round to 0`);
|
|
1897
1855
|
}
|
|
1898
|
-
|
|
1856
|
+
return value.toFixed(6).replace(/\.?0+$/, "");
|
|
1857
|
+
}
|
|
1858
|
+
function formatSystemdDuration(field, value, forbidWhitespace = false) {
|
|
1859
|
+
if (typeof value === "number")
|
|
1860
|
+
return formatSystemdNumber(value);
|
|
1861
|
+
return formatSystemdScalar(field, value, false, forbidWhitespace);
|
|
1862
|
+
}
|
|
1899
1863
|
function toStringList(value) {
|
|
1900
1864
|
if (value === undefined)
|
|
1901
1865
|
return [];
|
|
1902
1866
|
return typeof value === "string" ? [value] : value;
|
|
1903
1867
|
}
|
|
1904
|
-
function
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
const parsed = parsedResult.data;
|
|
1910
|
-
const allowHome = parsed.allowHomeSpecifier;
|
|
1911
|
-
const unitLines = [
|
|
1912
|
-
"[Unit]",
|
|
1913
|
-
`Description=${formatSystemdScalar("description", parsed.description, allowHome)}`
|
|
1914
|
-
];
|
|
1915
|
-
if (parsed.after && parsed.after.length > 0) {
|
|
1916
|
-
const items = parsed.after.map((item, i) => formatSystemdScalar(`after[${i}]`, item, false, true));
|
|
1917
|
-
unitLines.push(`After=${items.join(" ")}`);
|
|
1918
|
-
}
|
|
1919
|
-
if (parsed.wants && parsed.wants.length > 0) {
|
|
1920
|
-
const items = parsed.wants.map((item, i) => formatSystemdScalar(`wants[${i}]`, item, false, true));
|
|
1921
|
-
unitLines.push(`Wants=${items.join(" ")}`);
|
|
1922
|
-
}
|
|
1923
|
-
const serviceLines = ["[Service]"];
|
|
1924
|
-
if (parsed.type !== undefined)
|
|
1925
|
-
serviceLines.push(`Type=${parsed.type}`);
|
|
1926
|
-
if (parsed.user !== undefined) {
|
|
1927
|
-
serviceLines.push(`User=${formatSystemdScalar("user", parsed.user, false, true)}`);
|
|
1928
|
-
}
|
|
1929
|
-
if (parsed.group !== undefined) {
|
|
1930
|
-
serviceLines.push(`Group=${formatSystemdScalar("group", parsed.group, false, true)}`);
|
|
1931
|
-
}
|
|
1932
|
-
if (parsed.workingDirectory !== undefined) {
|
|
1933
|
-
serviceLines.push(`WorkingDirectory=${formatSystemdScalar("workingDirectory", parsed.workingDirectory, allowHome)}`);
|
|
1934
|
-
}
|
|
1935
|
-
if (parsed.runtimeDirectory !== undefined) {
|
|
1936
|
-
const dirs = toStringList(parsed.runtimeDirectory).map((dir, i) => formatSystemdScalar(`runtimeDirectory[${i}]`, dir, false, true));
|
|
1937
|
-
if (dirs.length > 0)
|
|
1938
|
-
serviceLines.push(`RuntimeDirectory=${dirs.join(" ")}`);
|
|
1939
|
-
}
|
|
1940
|
-
for (const [index, envFile] of toStringList(parsed.environmentFile).entries()) {
|
|
1941
|
-
serviceLines.push(`EnvironmentFile=${formatSystemdScalar(`environmentFile[${index}]`, envFile, allowHome)}`);
|
|
1942
|
-
}
|
|
1943
|
-
if (parsed.environment !== undefined) {
|
|
1944
|
-
const sortedKeys = Object.keys(parsed.environment).sort();
|
|
1945
|
-
for (const key of sortedKeys) {
|
|
1946
|
-
const value = parsed.environment[key];
|
|
1947
|
-
if (value !== undefined) {
|
|
1948
|
-
serviceLines.push(formatSystemdEnvironmentLine(key, value, allowHome));
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
if (parsed.execStartPre !== undefined) {
|
|
1953
|
-
for (const [index, cmd] of parsed.execStartPre.entries()) {
|
|
1954
|
-
serviceLines.push(`ExecStartPre=${formatSystemdExecLine(`execStartPre[${index}]`, cmd, allowHome)}`);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
serviceLines.push(`ExecStart=${formatSystemdExecLine("execStart", parsed.execStart, allowHome)}`);
|
|
1958
|
-
serviceLines.push(`Restart=${parsed.restart}`);
|
|
1959
|
-
if (parsed.restartSec !== undefined) {
|
|
1960
|
-
const text = String(parsed.restartSec);
|
|
1961
|
-
serviceLines.push(`RestartSec=${formatSystemdScalar("restartSec", text, false, true)}`);
|
|
1962
|
-
}
|
|
1963
|
-
if (parsed.timeoutStopSec !== undefined) {
|
|
1964
|
-
const text = String(parsed.timeoutStopSec);
|
|
1965
|
-
serviceLines.push(`TimeoutStopSec=${formatSystemdScalar("timeoutStopSec", text, false, true)}`);
|
|
1966
|
-
}
|
|
1967
|
-
if (parsed.killMode !== undefined)
|
|
1968
|
-
serviceLines.push(`KillMode=${parsed.killMode}`);
|
|
1969
|
-
if (parsed.oomScoreAdjust !== undefined) {
|
|
1970
|
-
serviceLines.push(`OOMScoreAdjust=${parsed.oomScoreAdjust}`);
|
|
1971
|
-
}
|
|
1972
|
-
if (parsed.oomPolicy !== undefined)
|
|
1973
|
-
serviceLines.push(`OOMPolicy=${parsed.oomPolicy}`);
|
|
1974
|
-
if (parsed.ioAccounting !== undefined) {
|
|
1975
|
-
serviceLines.push(`IOAccounting=${parsed.ioAccounting ? "yes" : "no"}`);
|
|
1976
|
-
}
|
|
1977
|
-
if (parsed.umask !== undefined)
|
|
1978
|
-
serviceLines.push(`UMask=${parsed.umask}`);
|
|
1979
|
-
if (parsed.noNewPrivileges !== undefined) {
|
|
1980
|
-
serviceLines.push(`NoNewPrivileges=${parsed.noNewPrivileges ? "yes" : "no"}`);
|
|
1868
|
+
function formatRelativeManagedDirectory(field, value) {
|
|
1869
|
+
assertCleanValue(field, value);
|
|
1870
|
+
assertNoWhitespace(field, value);
|
|
1871
|
+
if (value.startsWith("/") || value.endsWith("\\") || value.includes(":") || value.includes("\\") || value.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) {
|
|
1872
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd field '${field}' must be a relative normal directory name without ':', whitespace, or '..': ${JSON.stringify(value)}`);
|
|
1981
1873
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1874
|
+
return escapeSystemdSpecifiers(value, false);
|
|
1875
|
+
}
|
|
1876
|
+
var BIND_FORBIDDEN_CHARS = /[\s:"'\\]/;
|
|
1877
|
+
function assertBindPathSegment(field, path) {
|
|
1878
|
+
assertCleanValue(field, path);
|
|
1879
|
+
if (!isAbsoluteNormalPath(path) || BIND_FORBIDDEN_CHARS.test(path)) {
|
|
1880
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Systemd field '${field}' must be an absolute normal path without whitespace, ':', quotes, or backslashes: ${JSON.stringify(path)}`);
|
|
1984
1881
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1882
|
+
return escapeSystemdSpecifiers(path, false);
|
|
1883
|
+
}
|
|
1884
|
+
function formatBindReadOnlyPath(field, entry) {
|
|
1885
|
+
if (typeof entry === "string") {
|
|
1886
|
+
return assertBindPathSegment(field, entry);
|
|
1990
1887
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
${serviceLines.join(`
|
|
1995
|
-
`)}
|
|
1996
|
-
|
|
1997
|
-
${installLines.join(`
|
|
1998
|
-
`)}
|
|
1999
|
-
`;
|
|
1888
|
+
const source = assertBindPathSegment(`${field}.source`, entry.source);
|
|
1889
|
+
const target = entry.target !== undefined ? `:${assertBindPathSegment(`${field}.target`, entry.target)}` : "";
|
|
1890
|
+
return `${entry.ignoreMissing ? "-" : ""}${source}${target}`;
|
|
2000
1891
|
}
|
|
2001
1892
|
|
|
2002
1893
|
// src/service-host/systemd-inspect.ts
|
|
2003
1894
|
var DEFAULT_SYSTEMD_UNIT_MODE = 420;
|
|
2004
1895
|
var SYSTEMCTL_PATH = "/usr/bin/systemctl";
|
|
2005
|
-
var SHOW_PROPERTIES = "LoadState,FragmentPath,DropInPaths,ActiveState,SubState,MainPID,UnitFileState";
|
|
1896
|
+
var SHOW_PROPERTIES = "LoadState,FragmentPath,DropInPaths,ActiveState,SubState,MainPID,UnitFileState,NeedDaemonReload";
|
|
2006
1897
|
var SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
2007
1898
|
function createDefaultSystemdHostAdapter() {
|
|
2008
1899
|
return {
|
|
@@ -2201,6 +2092,7 @@ async function checkSystemdUnit(options) {
|
|
|
2201
2092
|
const activeState = props.get("ActiveState") || null;
|
|
2202
2093
|
const mainPid = parseMainPid(props.get("MainPID"));
|
|
2203
2094
|
const unitFileState = props.get("UnitFileState") || null;
|
|
2095
|
+
const needsReload = props.get("NeedDaemonReload") === "yes";
|
|
2204
2096
|
const foreignDropIns = await collectForeignDropIns(options.unitName, options.unitPath, options.scope, props.get("DropInPaths"), options.unitSearchDirs, adapter);
|
|
2205
2097
|
let status;
|
|
2206
2098
|
if (foreignDropIns.length > 0)
|
|
@@ -2226,7 +2118,8 @@ async function checkSystemdUnit(options) {
|
|
|
2226
2118
|
foreignDropIns,
|
|
2227
2119
|
activeState,
|
|
2228
2120
|
mainPid,
|
|
2229
|
-
unitFileState
|
|
2121
|
+
unitFileState,
|
|
2122
|
+
needsReload
|
|
2230
2123
|
};
|
|
2231
2124
|
}
|
|
2232
2125
|
async function systemdUnitActive(options) {
|
|
@@ -2309,6 +2202,50 @@ function differentLinks(a, b) {
|
|
|
2309
2202
|
return [...paths].filter((path) => a.get(path) !== b.get(path)).sort();
|
|
2310
2203
|
}
|
|
2311
2204
|
|
|
2205
|
+
// src/service-host/systemd-unit-ops.ts
|
|
2206
|
+
async function runSystemctlChecked(adapter, scope, args) {
|
|
2207
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, args));
|
|
2208
|
+
if (result.exitCode !== 0) {
|
|
2209
|
+
throw new SystemdUnitError("COMMAND_FAILED", `systemctl ${args.join(" ")} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
function assertOwnedRegularPath(unitName, unitPath, standing) {
|
|
2213
|
+
if (standing.kind === "symlink" || standing.kind === "other") {
|
|
2214
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${unitName}: ${unitPath} is ${standing.kind === "symlink" ? `a symbolic link to ${standing.target}` : "not a regular file"}, not a unit file of ours to replace`, { rolledBack: false });
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
function assertNoForeignUnit(unitName, unitPath, check) {
|
|
2218
|
+
if (check.foreignDropIns.length > 0) {
|
|
2219
|
+
throw new SystemdUnitError("FOREIGN_DROP_IN", `Refusing to manage ${unitName}: foreign drop-ins present (${check.foreignDropIns.join(", ")})`, { rolledBack: false, foreignDropIns: check.foreignDropIns });
|
|
2220
|
+
}
|
|
2221
|
+
const foreign = foreignUnitSource(check, unitPath);
|
|
2222
|
+
if (foreign !== undefined) {
|
|
2223
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${unitName}: ${foreign}`, { rolledBack: false });
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
async function restoreUnitEnablement(adapter, point) {
|
|
2227
|
+
const { scope, unitName } = point;
|
|
2228
|
+
const read = () => readEnablementLinks(adapter, point.linkDirs, point.linkNames);
|
|
2229
|
+
if (await restoreEnablementLinks(adapter, unitName, point.linksBefore, await read())) {
|
|
2230
|
+
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2231
|
+
}
|
|
2232
|
+
const differ = differentLinks(point.linksBefore, await read());
|
|
2233
|
+
if (differ.length > 0) {
|
|
2234
|
+
throw new SystemdUnitError("COMMAND_FAILED", `the enable links of ${unitName} differ from before the apply: ${differ.join(", ")}`);
|
|
2235
|
+
}
|
|
2236
|
+
if (point.previousBytes === null)
|
|
2237
|
+
return;
|
|
2238
|
+
const expected = point.previousUnitFileState;
|
|
2239
|
+
if (expected === null) {
|
|
2240
|
+
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} was unknown before the apply: its enablement cannot be checked`);
|
|
2241
|
+
}
|
|
2242
|
+
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, ["is-enabled", "--", unitName]));
|
|
2243
|
+
const state = result.stdout.trim();
|
|
2244
|
+
if (state !== expected) {
|
|
2245
|
+
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} is ${state || "unknown"} after rollback, not ${expected}${result.stderr.trim() ? ` (${result.stderr.trim()})` : ""}`);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2312
2249
|
// src/service-host/systemd.ts
|
|
2313
2250
|
var DEFAULT_STABILITY_MS2 = 5000;
|
|
2314
2251
|
var DEFAULT_POLL_INTERVAL_MS2 = 250;
|
|
@@ -2320,12 +2257,6 @@ function assertSystemdWaitMs(name, value, allowZero) {
|
|
|
2320
2257
|
throw new SystemdUnitError("INVALID_CONFIG", `Invalid ${name}: expected integer in [${min}, ${MAX_WAIT_MS2}], got ${value}`);
|
|
2321
2258
|
}
|
|
2322
2259
|
}
|
|
2323
|
-
async function runSystemctlChecked(adapter, scope, args) {
|
|
2324
|
-
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, args));
|
|
2325
|
-
if (result.exitCode !== 0) {
|
|
2326
|
-
throw new SystemdUnitError("COMMAND_FAILED", `systemctl ${args.join(" ")} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
2260
|
async function waitForStableSystemdUnit(unitName, scope, adapter, startupTimeoutMs, stabilityMs, pollIntervalMs) {
|
|
2330
2261
|
const startDeadline = adapter.now() + startupTimeoutMs;
|
|
2331
2262
|
let candidatePid = null;
|
|
@@ -2354,34 +2285,22 @@ async function waitForStableSystemdUnit(unitName, scope, adapter, startupTimeout
|
|
|
2354
2285
|
return { mainPid: candidatePid, stableForMs: adapter.now() - stableSince };
|
|
2355
2286
|
}
|
|
2356
2287
|
var ONESHOT_TYPE = /^[ \t]*Type[ \t]*=[ \t]*oneshot[ \t]*$/m;
|
|
2357
|
-
async function restoreEnablement(adapter, options, point) {
|
|
2358
|
-
const { scope, unitName } = options;
|
|
2359
|
-
const read = () => readEnablementLinks(adapter, point.linkDirs, point.linkNames);
|
|
2360
|
-
if (await restoreEnablementLinks(adapter, unitName, point.linksBefore, await read()))
|
|
2361
|
-
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2362
|
-
const differ = differentLinks(point.linksBefore, await read());
|
|
2363
|
-
if (differ.length > 0) {
|
|
2364
|
-
throw new SystemdUnitError("COMMAND_FAILED", `the enable links of ${unitName} differ from before the apply: ${differ.join(", ")}`);
|
|
2365
|
-
}
|
|
2366
|
-
if (point.previousBytes === null)
|
|
2367
|
-
return;
|
|
2368
|
-
const expected = point.previousUnitFileState;
|
|
2369
|
-
if (expected === null) {
|
|
2370
|
-
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} was unknown before the apply: its enablement cannot be checked`);
|
|
2371
|
-
}
|
|
2372
|
-
const result = await adapter.runCommand(SYSTEMCTL_PATH, systemdScopeArgs(scope, ["is-enabled", "--", unitName]));
|
|
2373
|
-
const state = result.stdout.trim();
|
|
2374
|
-
if (state !== expected) {
|
|
2375
|
-
throw new SystemdUnitError("COMMAND_FAILED", `UnitFileState of ${unitName} is ${state || "unknown"} after rollback, not ${expected}${result.stderr.trim() ? ` (${result.stderr.trim()})` : ""}`);
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
2288
|
async function restorePreviousUnit(adapter, options, point) {
|
|
2379
2289
|
const { scope, unitName, unitPath } = options;
|
|
2290
|
+
const enablementPoint = {
|
|
2291
|
+
scope,
|
|
2292
|
+
unitName,
|
|
2293
|
+
previousBytes: point.previousBytes,
|
|
2294
|
+
previousUnitFileState: point.previousUnitFileState,
|
|
2295
|
+
linkDirs: point.linkDirs,
|
|
2296
|
+
linkNames: point.linkNames,
|
|
2297
|
+
linksBefore: point.linksBefore
|
|
2298
|
+
};
|
|
2380
2299
|
if (point.previousBytes === null) {
|
|
2381
2300
|
if (point.didRestart)
|
|
2382
2301
|
await runSystemctlChecked(adapter, scope, ["stop", "--", unitName]);
|
|
2383
2302
|
if (point.didEnable)
|
|
2384
|
-
await
|
|
2303
|
+
await restoreUnitEnablement(adapter, enablementPoint);
|
|
2385
2304
|
await adapter.removeFile(unitPath);
|
|
2386
2305
|
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2387
2306
|
return;
|
|
@@ -2396,7 +2315,7 @@ async function restorePreviousUnit(adapter, options, point) {
|
|
|
2396
2315
|
]);
|
|
2397
2316
|
}
|
|
2398
2317
|
if (point.didEnable)
|
|
2399
|
-
await
|
|
2318
|
+
await restoreUnitEnablement(adapter, enablementPoint);
|
|
2400
2319
|
}
|
|
2401
2320
|
async function applySystemdUnit(options, defaultEnable) {
|
|
2402
2321
|
assertValidSystemdUnitName(options.unitName);
|
|
@@ -2415,20 +2334,12 @@ async function applySystemdUnit(options, defaultEnable) {
|
|
|
2415
2334
|
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2416
2335
|
adapter
|
|
2417
2336
|
});
|
|
2418
|
-
|
|
2419
|
-
throw new SystemdUnitError("FOREIGN_DROP_IN", `Refusing to manage ${options.unitName}: foreign drop-ins present (${preCheck.foreignDropIns.join(", ")})`, { rolledBack: false, foreignDropIns: preCheck.foreignDropIns });
|
|
2420
|
-
}
|
|
2421
|
-
const foreign = foreignUnitSource(preCheck, options.unitPath);
|
|
2422
|
-
if (foreign !== undefined) {
|
|
2423
|
-
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${options.unitName}: ${foreign}`, { rolledBack: false });
|
|
2424
|
-
}
|
|
2337
|
+
assertNoForeignUnit(options.unitName, options.unitPath, preCheck);
|
|
2425
2338
|
if (ONESHOT_TYPE.test(options.content)) {
|
|
2426
2339
|
throw new SystemdUnitError("UNSUPPORTED_UNIT_TYPE", `Refusing to apply ${options.unitName}: Type=oneshot has no main process to hold stable`, { rolledBack: false });
|
|
2427
2340
|
}
|
|
2428
2341
|
const standing = await adapter.inspectPath(options.unitPath);
|
|
2429
|
-
|
|
2430
|
-
throw new SystemdUnitError("FOREIGN_FRAGMENT", `Refusing to manage ${options.unitName}: ${options.unitPath} is ${standing.kind === "symlink" ? `a symbolic link to ${standing.target}` : "not a regular file"}, not a unit file of ours to replace`, { rolledBack: false });
|
|
2431
|
-
}
|
|
2342
|
+
assertOwnedRegularPath(options.unitName, options.unitPath, standing);
|
|
2432
2343
|
const previousBytes = await adapter.readFile(options.unitPath);
|
|
2433
2344
|
const wasActive = preCheck.activeState === "active";
|
|
2434
2345
|
const mode = options.mode ?? DEFAULT_SYSTEMD_UNIT_MODE;
|
|
@@ -2499,6 +2410,702 @@ function installAndStartSystemdUnit(options) {
|
|
|
2499
2410
|
function reloadSystemdUnit(options) {
|
|
2500
2411
|
return applySystemdUnit(options, false);
|
|
2501
2412
|
}
|
|
2413
|
+
// src/service-host/systemd-render.ts
|
|
2414
|
+
import { z as z3 } from "zod";
|
|
2415
|
+
var SystemdServiceUnitConfigSchema = z3.strictObject({
|
|
2416
|
+
description: z3.string().min(1),
|
|
2417
|
+
scope: SystemdScopeSchema.default("system"),
|
|
2418
|
+
execStart: z3.array(z3.string()).min(1),
|
|
2419
|
+
execStartPre: z3.array(z3.array(z3.string()).min(1)).optional(),
|
|
2420
|
+
workingDirectory: z3.string().min(1).optional(),
|
|
2421
|
+
environment: z3.record(z3.string(), z3.string()).optional(),
|
|
2422
|
+
environmentFile: z3.union([z3.string().min(1), z3.array(z3.string().min(1))]).optional(),
|
|
2423
|
+
user: z3.string().min(1).optional(),
|
|
2424
|
+
group: z3.string().min(1).optional(),
|
|
2425
|
+
dynamicUser: z3.boolean().optional(),
|
|
2426
|
+
type: z3.enum(["simple", "exec", "forking", "oneshot", "notify"]).optional(),
|
|
2427
|
+
restart: z3.enum([
|
|
2428
|
+
"no",
|
|
2429
|
+
"on-success",
|
|
2430
|
+
"on-failure",
|
|
2431
|
+
"on-abnormal",
|
|
2432
|
+
"on-watchdog",
|
|
2433
|
+
"on-abort",
|
|
2434
|
+
"always"
|
|
2435
|
+
]).optional(),
|
|
2436
|
+
restartSec: z3.union([z3.number().nonnegative(), z3.string().min(1)]).optional(),
|
|
2437
|
+
startLimitIntervalSec: SystemdTimespanSchema.optional(),
|
|
2438
|
+
successExitStatus: z3.array(SystemdSuccessExitStatusItemSchema).min(1).optional(),
|
|
2439
|
+
timeoutStartSec: SystemdTimeoutSchema.optional(),
|
|
2440
|
+
timeoutStopSec: z3.union([z3.number().positive(), z3.string().min(1)]).optional(),
|
|
2441
|
+
killMode: z3.enum(["control-group", "mixed", "process", "none"]).optional(),
|
|
2442
|
+
oomScoreAdjust: z3.number().int().min(-1000).max(1000).optional(),
|
|
2443
|
+
oomPolicy: z3.enum(["continue", "stop", "kill"]).optional(),
|
|
2444
|
+
ioAccounting: z3.boolean().optional(),
|
|
2445
|
+
nice: z3.number().int().min(-20).max(19).optional(),
|
|
2446
|
+
ioSchedulingClass: z3.enum(["none", "realtime", "best-effort", "idle"]).optional(),
|
|
2447
|
+
umask: z3.string().regex(OCTAL_MODE_PATTERN).optional(),
|
|
2448
|
+
noNewPrivileges: z3.boolean().optional(),
|
|
2449
|
+
privateNetwork: z3.boolean().optional(),
|
|
2450
|
+
privateTmp: z3.boolean().optional(),
|
|
2451
|
+
protectSystem: z3.union([z3.boolean(), z3.enum(["full", "strict"])]).optional(),
|
|
2452
|
+
protectHome: z3.union([z3.boolean(), z3.enum(["read-only", "tmpfs"])]).optional(),
|
|
2453
|
+
restrictAddressFamilies: z3.array(SystemdAddressFamilySchema).min(1).optional(),
|
|
2454
|
+
bindReadOnlyPaths: z3.array(SystemdBindReadOnlyPathSchema).min(1).optional(),
|
|
2455
|
+
runtimeDirectory: z3.union([z3.string().min(1), z3.array(z3.string().min(1))]).optional(),
|
|
2456
|
+
runtimeDirectoryMode: z3.string().regex(OCTAL_MODE_PATTERN).optional(),
|
|
2457
|
+
stateDirectory: z3.union([z3.string().min(1), z3.array(z3.string().min(1)).min(1)]).optional(),
|
|
2458
|
+
stateDirectoryMode: z3.string().regex(OCTAL_MODE_PATTERN).optional(),
|
|
2459
|
+
limitNOFILE: z3.union([z3.number().int().positive(), z3.literal("infinity")]).optional(),
|
|
2460
|
+
after: z3.array(z3.string().min(1)).optional(),
|
|
2461
|
+
wants: z3.array(z3.string().min(1)).optional(),
|
|
2462
|
+
wantedBy: z3.array(z3.string().min(1)).optional(),
|
|
2463
|
+
allowHomeSpecifier: z3.boolean().default(false)
|
|
2464
|
+
}).check((ctx) => {
|
|
2465
|
+
const value = ctx.value;
|
|
2466
|
+
if ((value.execStart[0] ?? "").length === 0) {
|
|
2467
|
+
ctx.issues.push({
|
|
2468
|
+
code: "custom",
|
|
2469
|
+
input: value.execStart,
|
|
2470
|
+
path: ["execStart", 0],
|
|
2471
|
+
message: "execStart[0] must be a non-empty executable path"
|
|
2472
|
+
});
|
|
2473
|
+
} else if (EXEC_PREFIX.test(value.execStart[0] ?? "")) {
|
|
2474
|
+
ctx.issues.push({
|
|
2475
|
+
code: "custom",
|
|
2476
|
+
input: value.execStart,
|
|
2477
|
+
path: ["execStart", 0],
|
|
2478
|
+
message: EXEC_PREFIX_MESSAGE
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
if (value.execStartPre !== undefined) {
|
|
2482
|
+
for (let index = 0;index < value.execStartPre.length; index += 1) {
|
|
2483
|
+
const cmd = value.execStartPre[index];
|
|
2484
|
+
if ((cmd?.[0] ?? "").length === 0) {
|
|
2485
|
+
ctx.issues.push({
|
|
2486
|
+
code: "custom",
|
|
2487
|
+
input: cmd,
|
|
2488
|
+
path: ["execStartPre", index, 0],
|
|
2489
|
+
message: `execStartPre[${index}][0] must be a non-empty executable path`
|
|
2490
|
+
});
|
|
2491
|
+
} else if (EXEC_PREFIX.test(cmd?.[0] ?? "")) {
|
|
2492
|
+
ctx.issues.push({
|
|
2493
|
+
code: "custom",
|
|
2494
|
+
input: cmd,
|
|
2495
|
+
path: ["execStartPre", index, 0],
|
|
2496
|
+
message: EXEC_PREFIX_MESSAGE
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
if (value.scope === "user" && (value.user !== undefined || value.group !== undefined)) {
|
|
2502
|
+
ctx.issues.push({
|
|
2503
|
+
code: "custom",
|
|
2504
|
+
input: value,
|
|
2505
|
+
path: ["scope"],
|
|
2506
|
+
message: "systemd user units cannot declare 'user' or 'group'"
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
if (value.scope === "user" && value.dynamicUser !== undefined) {
|
|
2510
|
+
ctx.issues.push({
|
|
2511
|
+
code: "custom",
|
|
2512
|
+
input: value,
|
|
2513
|
+
path: ["dynamicUser"],
|
|
2514
|
+
message: "systemd user units cannot declare 'dynamicUser'"
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
if (value.type === "oneshot" && (value.restart === "always" || value.restart === "on-success")) {
|
|
2518
|
+
ctx.issues.push({
|
|
2519
|
+
code: "custom",
|
|
2520
|
+
input: value,
|
|
2521
|
+
path: ["restart"],
|
|
2522
|
+
message: `systemd refuses Type=oneshot with Restart=${value.restart}`
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2525
|
+
if (value.restrictAddressFamilies?.includes("none") && value.restrictAddressFamilies.length > 1) {
|
|
2526
|
+
ctx.issues.push({
|
|
2527
|
+
code: "custom",
|
|
2528
|
+
input: value.restrictAddressFamilies,
|
|
2529
|
+
path: ["restrictAddressFamilies"],
|
|
2530
|
+
message: "restrictAddressFamilies cannot combine 'none' with AF_* families"
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
function renderUnitSection(parsed, allowHome) {
|
|
2535
|
+
const unitLines = [
|
|
2536
|
+
"[Unit]",
|
|
2537
|
+
`Description=${formatSystemdScalar("description", parsed.description, allowHome)}`
|
|
2538
|
+
];
|
|
2539
|
+
if (parsed.after && parsed.after.length > 0) {
|
|
2540
|
+
const items = parsed.after.map((item, i) => formatSystemdScalar(`after[${i}]`, item, false, true));
|
|
2541
|
+
unitLines.push(`After=${items.join(" ")}`);
|
|
2542
|
+
}
|
|
2543
|
+
if (parsed.wants && parsed.wants.length > 0) {
|
|
2544
|
+
const items = parsed.wants.map((item, i) => formatSystemdScalar(`wants[${i}]`, item, false, true));
|
|
2545
|
+
unitLines.push(`Wants=${items.join(" ")}`);
|
|
2546
|
+
}
|
|
2547
|
+
if (parsed.startLimitIntervalSec !== undefined) {
|
|
2548
|
+
unitLines.push(`StartLimitIntervalSec=${formatSystemdDuration("startLimitIntervalSec", parsed.startLimitIntervalSec)}`);
|
|
2549
|
+
}
|
|
2550
|
+
return unitLines;
|
|
2551
|
+
}
|
|
2552
|
+
function formatTriStateBoolean(value) {
|
|
2553
|
+
return typeof value === "boolean" ? value ? "yes" : "no" : value;
|
|
2554
|
+
}
|
|
2555
|
+
function renderServiceSection(parsed, allowHome) {
|
|
2556
|
+
const serviceLines = ["[Service]"];
|
|
2557
|
+
if (parsed.type !== undefined)
|
|
2558
|
+
serviceLines.push(`Type=${parsed.type}`);
|
|
2559
|
+
if (parsed.dynamicUser !== undefined) {
|
|
2560
|
+
serviceLines.push(`DynamicUser=${parsed.dynamicUser ? "yes" : "no"}`);
|
|
2561
|
+
}
|
|
2562
|
+
if (parsed.user !== undefined) {
|
|
2563
|
+
serviceLines.push(`User=${formatSystemdScalar("user", parsed.user, false, true)}`);
|
|
2564
|
+
}
|
|
2565
|
+
if (parsed.group !== undefined) {
|
|
2566
|
+
serviceLines.push(`Group=${formatSystemdScalar("group", parsed.group, false, true)}`);
|
|
2567
|
+
}
|
|
2568
|
+
if (parsed.workingDirectory !== undefined) {
|
|
2569
|
+
serviceLines.push(`WorkingDirectory=${formatSystemdScalar("workingDirectory", parsed.workingDirectory, allowHome)}`);
|
|
2570
|
+
}
|
|
2571
|
+
if (parsed.runtimeDirectory !== undefined) {
|
|
2572
|
+
const dirs = toStringList(parsed.runtimeDirectory).map((dir, i) => formatSystemdScalar(`runtimeDirectory[${i}]`, dir, false, true));
|
|
2573
|
+
if (dirs.length > 0)
|
|
2574
|
+
serviceLines.push(`RuntimeDirectory=${dirs.join(" ")}`);
|
|
2575
|
+
}
|
|
2576
|
+
if (parsed.runtimeDirectoryMode !== undefined) {
|
|
2577
|
+
serviceLines.push(`RuntimeDirectoryMode=${parsed.runtimeDirectoryMode}`);
|
|
2578
|
+
}
|
|
2579
|
+
if (parsed.stateDirectory !== undefined) {
|
|
2580
|
+
const dirs = toStringList(parsed.stateDirectory).map((dir, i) => formatRelativeManagedDirectory(`stateDirectory[${i}]`, dir));
|
|
2581
|
+
if (dirs.length > 0)
|
|
2582
|
+
serviceLines.push(`StateDirectory=${dirs.join(" ")}`);
|
|
2583
|
+
}
|
|
2584
|
+
if (parsed.stateDirectoryMode !== undefined) {
|
|
2585
|
+
serviceLines.push(`StateDirectoryMode=${parsed.stateDirectoryMode}`);
|
|
2586
|
+
}
|
|
2587
|
+
for (const [index, envFile] of toStringList(parsed.environmentFile).entries()) {
|
|
2588
|
+
serviceLines.push(`EnvironmentFile=${formatSystemdScalar(`environmentFile[${index}]`, envFile, allowHome)}`);
|
|
2589
|
+
}
|
|
2590
|
+
if (parsed.environment !== undefined) {
|
|
2591
|
+
const sortedKeys = Object.keys(parsed.environment).sort();
|
|
2592
|
+
for (const key of sortedKeys) {
|
|
2593
|
+
const value = parsed.environment[key];
|
|
2594
|
+
if (value !== undefined) {
|
|
2595
|
+
serviceLines.push(formatSystemdEnvironmentLine(key, value, allowHome));
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
if (parsed.execStartPre !== undefined) {
|
|
2600
|
+
for (const [index, cmd] of parsed.execStartPre.entries()) {
|
|
2601
|
+
serviceLines.push(`ExecStartPre=${formatSystemdExecLine(`execStartPre[${index}]`, cmd, allowHome)}`);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
serviceLines.push(`ExecStart=${formatSystemdExecLine("execStart", parsed.execStart, allowHome)}`);
|
|
2605
|
+
const restart = parsed.restart ?? (parsed.type === "oneshot" ? undefined : "on-failure");
|
|
2606
|
+
if (restart !== undefined)
|
|
2607
|
+
serviceLines.push(`Restart=${restart}`);
|
|
2608
|
+
if (parsed.restartSec !== undefined) {
|
|
2609
|
+
serviceLines.push(`RestartSec=${formatSystemdScalar("restartSec", String(parsed.restartSec), false, true)}`);
|
|
2610
|
+
}
|
|
2611
|
+
if (parsed.successExitStatus !== undefined) {
|
|
2612
|
+
const items = parsed.successExitStatus.map((item, i) => {
|
|
2613
|
+
const text = String(item);
|
|
2614
|
+
assertCleanValue(`successExitStatus[${i}]`, text);
|
|
2615
|
+
return text;
|
|
2616
|
+
});
|
|
2617
|
+
serviceLines.push(`SuccessExitStatus=${items.join(" ")}`);
|
|
2618
|
+
}
|
|
2619
|
+
if (parsed.timeoutStartSec !== undefined) {
|
|
2620
|
+
serviceLines.push(`TimeoutStartSec=${formatSystemdDuration("timeoutStartSec", parsed.timeoutStartSec)}`);
|
|
2621
|
+
}
|
|
2622
|
+
if (parsed.timeoutStopSec !== undefined) {
|
|
2623
|
+
serviceLines.push(`TimeoutStopSec=${formatSystemdScalar("timeoutStopSec", String(parsed.timeoutStopSec), false, true)}`);
|
|
2624
|
+
}
|
|
2625
|
+
if (parsed.killMode !== undefined)
|
|
2626
|
+
serviceLines.push(`KillMode=${parsed.killMode}`);
|
|
2627
|
+
if (parsed.oomScoreAdjust !== undefined) {
|
|
2628
|
+
serviceLines.push(`OOMScoreAdjust=${parsed.oomScoreAdjust}`);
|
|
2629
|
+
}
|
|
2630
|
+
if (parsed.oomPolicy !== undefined)
|
|
2631
|
+
serviceLines.push(`OOMPolicy=${parsed.oomPolicy}`);
|
|
2632
|
+
if (parsed.ioAccounting !== undefined) {
|
|
2633
|
+
serviceLines.push(`IOAccounting=${parsed.ioAccounting ? "yes" : "no"}`);
|
|
2634
|
+
}
|
|
2635
|
+
if (parsed.nice !== undefined)
|
|
2636
|
+
serviceLines.push(`Nice=${parsed.nice}`);
|
|
2637
|
+
if (parsed.ioSchedulingClass !== undefined) {
|
|
2638
|
+
serviceLines.push(`IOSchedulingClass=${parsed.ioSchedulingClass}`);
|
|
2639
|
+
}
|
|
2640
|
+
if (parsed.umask !== undefined)
|
|
2641
|
+
serviceLines.push(`UMask=${parsed.umask}`);
|
|
2642
|
+
if (parsed.noNewPrivileges !== undefined) {
|
|
2643
|
+
serviceLines.push(`NoNewPrivileges=${parsed.noNewPrivileges ? "yes" : "no"}`);
|
|
2644
|
+
}
|
|
2645
|
+
if (parsed.privateNetwork !== undefined) {
|
|
2646
|
+
serviceLines.push(`PrivateNetwork=${parsed.privateNetwork ? "yes" : "no"}`);
|
|
2647
|
+
}
|
|
2648
|
+
if (parsed.privateTmp !== undefined) {
|
|
2649
|
+
serviceLines.push(`PrivateTmp=${parsed.privateTmp ? "yes" : "no"}`);
|
|
2650
|
+
}
|
|
2651
|
+
if (parsed.protectSystem !== undefined) {
|
|
2652
|
+
serviceLines.push(`ProtectSystem=${formatTriStateBoolean(parsed.protectSystem)}`);
|
|
2653
|
+
}
|
|
2654
|
+
if (parsed.protectHome !== undefined) {
|
|
2655
|
+
serviceLines.push(`ProtectHome=${formatTriStateBoolean(parsed.protectHome)}`);
|
|
2656
|
+
}
|
|
2657
|
+
if (parsed.restrictAddressFamilies !== undefined) {
|
|
2658
|
+
serviceLines.push(`RestrictAddressFamilies=${parsed.restrictAddressFamilies.join(" ")}`);
|
|
2659
|
+
}
|
|
2660
|
+
if (parsed.bindReadOnlyPaths !== undefined) {
|
|
2661
|
+
for (const [index, entry] of parsed.bindReadOnlyPaths.entries()) {
|
|
2662
|
+
serviceLines.push(`BindReadOnlyPaths=${formatBindReadOnlyPath(`bindReadOnlyPaths[${index}]`, entry)}`);
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
if (parsed.limitNOFILE !== undefined) {
|
|
2666
|
+
serviceLines.push(`LimitNOFILE=${parsed.limitNOFILE}`);
|
|
2667
|
+
}
|
|
2668
|
+
return serviceLines;
|
|
2669
|
+
}
|
|
2670
|
+
function renderInstallSection(parsed) {
|
|
2671
|
+
if (parsed.wantedBy !== undefined && parsed.wantedBy.length === 0)
|
|
2672
|
+
return;
|
|
2673
|
+
const wantedBy = parsed.wantedBy ?? (parsed.scope === "user" ? ["default.target"] : ["multi-user.target"]);
|
|
2674
|
+
const targets = wantedBy.map((item, i) => formatSystemdScalar(`wantedBy[${i}]`, item, false, true));
|
|
2675
|
+
return ["[Install]", `WantedBy=${targets.join(" ")}`];
|
|
2676
|
+
}
|
|
2677
|
+
function renderSystemdServiceUnit(config) {
|
|
2678
|
+
const parsedResult = SystemdServiceUnitConfigSchema.safeParse(config);
|
|
2679
|
+
if (!parsedResult.success) {
|
|
2680
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd unit configuration: ${parsedResult.error.message}`, { cause: parsedResult.error });
|
|
2681
|
+
}
|
|
2682
|
+
const parsed = parsedResult.data;
|
|
2683
|
+
const allowHome = parsed.allowHomeSpecifier;
|
|
2684
|
+
const sections = [
|
|
2685
|
+
renderUnitSection(parsed, allowHome).join(`
|
|
2686
|
+
`),
|
|
2687
|
+
renderServiceSection(parsed, allowHome).join(`
|
|
2688
|
+
`)
|
|
2689
|
+
];
|
|
2690
|
+
const install = renderInstallSection(parsed);
|
|
2691
|
+
if (install !== undefined)
|
|
2692
|
+
sections.push(install.join(`
|
|
2693
|
+
`));
|
|
2694
|
+
return `${sections.join(`
|
|
2695
|
+
|
|
2696
|
+
`)}
|
|
2697
|
+
`;
|
|
2698
|
+
}
|
|
2699
|
+
// src/service-host/systemd-timer-rollback.ts
|
|
2700
|
+
async function rollbackTimerPair(adapter, point) {
|
|
2701
|
+
const { scope, timerUnitName, timerUnitPath, serviceUnitPath } = point;
|
|
2702
|
+
const enablementPoint = {
|
|
2703
|
+
scope,
|
|
2704
|
+
unitName: timerUnitName,
|
|
2705
|
+
previousBytes: point.previousTimerBytes,
|
|
2706
|
+
previousUnitFileState: point.previousTimerUnitFileState,
|
|
2707
|
+
linkDirs: point.linkDirs,
|
|
2708
|
+
linkNames: point.linkNames,
|
|
2709
|
+
linksBefore: point.linksBefore
|
|
2710
|
+
};
|
|
2711
|
+
if (point.didActivate && point.previousTimerBytes === null) {
|
|
2712
|
+
await runSystemctlChecked(adapter, scope, ["stop", "--", timerUnitName]);
|
|
2713
|
+
}
|
|
2714
|
+
if (point.didEnable && point.previousTimerBytes === null) {
|
|
2715
|
+
await restoreUnitEnablement(adapter, enablementPoint);
|
|
2716
|
+
}
|
|
2717
|
+
if (point.wroteService) {
|
|
2718
|
+
if (point.previousServiceBytes === null)
|
|
2719
|
+
await adapter.removeFile(serviceUnitPath);
|
|
2720
|
+
else {
|
|
2721
|
+
await adapter.writeFileAtomic(serviceUnitPath, point.previousServiceBytes, {
|
|
2722
|
+
mode: point.previousServiceMode
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
if (point.wroteTimer) {
|
|
2727
|
+
if (point.previousTimerBytes === null)
|
|
2728
|
+
await adapter.removeFile(timerUnitPath);
|
|
2729
|
+
else {
|
|
2730
|
+
await adapter.writeFileAtomic(timerUnitPath, point.previousTimerBytes, {
|
|
2731
|
+
mode: point.previousTimerMode
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
await runSystemctlChecked(adapter, scope, ["daemon-reload"]);
|
|
2736
|
+
if (point.didActivate && point.previousTimerBytes !== null) {
|
|
2737
|
+
await runSystemctlChecked(adapter, scope, [
|
|
2738
|
+
point.timerWasActive ? "restart" : "stop",
|
|
2739
|
+
"--",
|
|
2740
|
+
timerUnitName
|
|
2741
|
+
]);
|
|
2742
|
+
}
|
|
2743
|
+
if (point.didEnable && point.previousTimerBytes !== null) {
|
|
2744
|
+
await restoreUnitEnablement(adapter, enablementPoint);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
// src/service-host/systemd-timer.ts
|
|
2749
|
+
function assertPairNames(serviceUnitName, timerUnitName) {
|
|
2750
|
+
assertValidSystemdUnitName(serviceUnitName);
|
|
2751
|
+
assertValidSystemdUnitName(timerUnitName);
|
|
2752
|
+
if (!serviceUnitName.endsWith(".service")) {
|
|
2753
|
+
throw new SystemdUnitError("INVALID_CONFIG", `serviceUnitName must end with '.service': ${JSON.stringify(serviceUnitName)}`);
|
|
2754
|
+
}
|
|
2755
|
+
if (!timerUnitName.endsWith(".timer")) {
|
|
2756
|
+
throw new SystemdUnitError("INVALID_CONFIG", `timerUnitName must end with '.timer': ${JSON.stringify(timerUnitName)}`);
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
function assertTimerTargetsService(timerContent, timerUnitName, serviceUnitName) {
|
|
2760
|
+
let inTimer = false;
|
|
2761
|
+
const declared = [];
|
|
2762
|
+
for (const rawLine of timerContent.split(`
|
|
2763
|
+
`)) {
|
|
2764
|
+
const line = rawLine.trim();
|
|
2765
|
+
if (line.length === 0 || line.startsWith("#") || line.startsWith(";"))
|
|
2766
|
+
continue;
|
|
2767
|
+
if (line.startsWith("[") && line.endsWith("]")) {
|
|
2768
|
+
inTimer = line === "[Timer]";
|
|
2769
|
+
continue;
|
|
2770
|
+
}
|
|
2771
|
+
if (!inTimer)
|
|
2772
|
+
continue;
|
|
2773
|
+
const match = /^Unit[ \t]*=(.*)$/.exec(line);
|
|
2774
|
+
if (match)
|
|
2775
|
+
declared.push((match[1] ?? "").trim());
|
|
2776
|
+
}
|
|
2777
|
+
if (declared.length > 1) {
|
|
2778
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Timer ${timerUnitName} declares multiple Unit= directives in [Timer]`);
|
|
2779
|
+
}
|
|
2780
|
+
const target = declared.length === 1 ? declared[0] : `${timerUnitName.slice(0, -".timer".length)}.service`;
|
|
2781
|
+
if (!target || target !== serviceUnitName) {
|
|
2782
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Timer ${timerUnitName} targets ${JSON.stringify(target)}, expected ${JSON.stringify(serviceUnitName)}`);
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
async function checkSystemdTimerPair(options) {
|
|
2786
|
+
assertPairNames(options.serviceUnitName, options.timerUnitName);
|
|
2787
|
+
assertSystemdUnitPath(options.serviceUnitPath);
|
|
2788
|
+
assertSystemdUnitPath(options.timerUnitPath);
|
|
2789
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2790
|
+
const service = await checkSystemdUnit({
|
|
2791
|
+
unitName: options.serviceUnitName,
|
|
2792
|
+
unitPath: options.serviceUnitPath,
|
|
2793
|
+
...options.expectedServiceContent !== undefined && {
|
|
2794
|
+
expectedContent: options.expectedServiceContent
|
|
2795
|
+
},
|
|
2796
|
+
...options.expectedServiceDigest !== undefined && {
|
|
2797
|
+
expectedDigest: options.expectedServiceDigest
|
|
2798
|
+
},
|
|
2799
|
+
scope: options.scope,
|
|
2800
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2801
|
+
adapter
|
|
2802
|
+
});
|
|
2803
|
+
const timer = await checkSystemdUnit({
|
|
2804
|
+
unitName: options.timerUnitName,
|
|
2805
|
+
unitPath: options.timerUnitPath,
|
|
2806
|
+
...options.expectedTimerContent !== undefined && {
|
|
2807
|
+
expectedContent: options.expectedTimerContent
|
|
2808
|
+
},
|
|
2809
|
+
...options.expectedTimerDigest !== undefined && {
|
|
2810
|
+
expectedDigest: options.expectedTimerDigest
|
|
2811
|
+
},
|
|
2812
|
+
scope: options.scope,
|
|
2813
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2814
|
+
adapter
|
|
2815
|
+
});
|
|
2816
|
+
return {
|
|
2817
|
+
ok: service.ok && timer.ok,
|
|
2818
|
+
service,
|
|
2819
|
+
timer,
|
|
2820
|
+
timerActive: timer.activeState === "active",
|
|
2821
|
+
timerEnabled: timer.unitFileState === "enabled"
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
async function activateTimerAfterReload(adapter, options, pre, loaded, wroteTimer, enable, start, mark) {
|
|
2825
|
+
if (enable && !loaded.timerEnabled) {
|
|
2826
|
+
mark.onEnable();
|
|
2827
|
+
await runSystemctlChecked(adapter, options.scope, ["enable", "--", options.timerUnitName]);
|
|
2828
|
+
}
|
|
2829
|
+
if (start) {
|
|
2830
|
+
if (pre.timerActive) {
|
|
2831
|
+
if (wroteTimer || pre.timer.needsReload) {
|
|
2832
|
+
mark.onActivate();
|
|
2833
|
+
await runSystemctlChecked(adapter, options.scope, [
|
|
2834
|
+
"restart",
|
|
2835
|
+
"--",
|
|
2836
|
+
options.timerUnitName
|
|
2837
|
+
]);
|
|
2838
|
+
}
|
|
2839
|
+
} else {
|
|
2840
|
+
mark.onActivate();
|
|
2841
|
+
await runSystemctlChecked(adapter, options.scope, [
|
|
2842
|
+
"start",
|
|
2843
|
+
"--",
|
|
2844
|
+
options.timerUnitName
|
|
2845
|
+
]);
|
|
2846
|
+
}
|
|
2847
|
+
const active = await systemdUnitActive({
|
|
2848
|
+
unitName: options.timerUnitName,
|
|
2849
|
+
scope: options.scope,
|
|
2850
|
+
adapter
|
|
2851
|
+
});
|
|
2852
|
+
if (!active) {
|
|
2853
|
+
throw new SystemdUnitError("START_TIMEOUT", `Systemd timer ${options.timerUnitName} is not active after activation`);
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
return {
|
|
2857
|
+
timerActive: start ? true : loaded.timerActive,
|
|
2858
|
+
timerEnabled: enable ? true : loaded.timerEnabled
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
async function installSystemdTimerPair(options) {
|
|
2862
|
+
assertPairNames(options.serviceUnitName, options.timerUnitName);
|
|
2863
|
+
assertSystemdUnitPath(options.serviceUnitPath);
|
|
2864
|
+
assertSystemdUnitPath(options.timerUnitPath);
|
|
2865
|
+
assertTimerTargetsService(options.timerContent, options.timerUnitName, options.serviceUnitName);
|
|
2866
|
+
const adapter = options.adapter ?? createDefaultSystemdHostAdapter();
|
|
2867
|
+
const mode = options.mode ?? DEFAULT_SYSTEMD_UNIT_MODE;
|
|
2868
|
+
const enable = options.enable ?? true;
|
|
2869
|
+
const start = options.start ?? true;
|
|
2870
|
+
const serviceDigest = computeSha256Hex(options.serviceContent);
|
|
2871
|
+
const timerDigest = computeSha256Hex(options.timerContent);
|
|
2872
|
+
const pre = await checkSystemdTimerPair({
|
|
2873
|
+
serviceUnitName: options.serviceUnitName,
|
|
2874
|
+
serviceUnitPath: options.serviceUnitPath,
|
|
2875
|
+
expectedServiceContent: options.serviceContent,
|
|
2876
|
+
timerUnitName: options.timerUnitName,
|
|
2877
|
+
timerUnitPath: options.timerUnitPath,
|
|
2878
|
+
expectedTimerContent: options.timerContent,
|
|
2879
|
+
scope: options.scope,
|
|
2880
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2881
|
+
adapter
|
|
2882
|
+
});
|
|
2883
|
+
assertNoForeignUnit(options.serviceUnitName, options.serviceUnitPath, pre.service);
|
|
2884
|
+
assertNoForeignUnit(options.timerUnitName, options.timerUnitPath, pre.timer);
|
|
2885
|
+
const serviceStanding = await adapter.inspectPath(options.serviceUnitPath);
|
|
2886
|
+
const timerStanding = await adapter.inspectPath(options.timerUnitPath);
|
|
2887
|
+
assertOwnedRegularPath(options.serviceUnitName, options.serviceUnitPath, serviceStanding);
|
|
2888
|
+
assertOwnedRegularPath(options.timerUnitName, options.timerUnitPath, timerStanding);
|
|
2889
|
+
const serviceModeMatches = serviceStanding.kind === "file" && serviceStanding.mode === mode;
|
|
2890
|
+
const timerModeMatches = timerStanding.kind === "file" && timerStanding.mode === mode;
|
|
2891
|
+
const serviceBytesMatch = pre.service.actualDigest === serviceDigest;
|
|
2892
|
+
const timerBytesMatch = pre.timer.actualDigest === timerDigest;
|
|
2893
|
+
const isNoop = pre.service.status === "matches" && pre.timer.status === "matches" && !pre.service.needsReload && !pre.timer.needsReload && serviceModeMatches && timerModeMatches && (!enable || pre.timerEnabled) && (!start || pre.timerActive);
|
|
2894
|
+
if (isNoop) {
|
|
2895
|
+
return {
|
|
2896
|
+
serviceUnitName: options.serviceUnitName,
|
|
2897
|
+
serviceDigest,
|
|
2898
|
+
timerUnitName: options.timerUnitName,
|
|
2899
|
+
timerDigest,
|
|
2900
|
+
changed: false,
|
|
2901
|
+
timerActive: pre.timerActive,
|
|
2902
|
+
timerEnabled: pre.timerEnabled
|
|
2903
|
+
};
|
|
2904
|
+
}
|
|
2905
|
+
const previousServiceBytes = await adapter.readFile(options.serviceUnitPath);
|
|
2906
|
+
const previousTimerBytes = await adapter.readFile(options.timerUnitPath);
|
|
2907
|
+
const linkNames = enablementNamesOf(options.timerUnitName, options.timerUnitPath, [
|
|
2908
|
+
options.timerContent,
|
|
2909
|
+
...previousTimerBytes === null ? [] : [new TextDecoder().decode(previousTimerBytes)]
|
|
2910
|
+
]);
|
|
2911
|
+
const linkDirs = enable ? await resolveUnitSearchDirs(options.timerUnitPath, options.scope, options.unitSearchDirs, adapter) : [];
|
|
2912
|
+
const linksBefore = enable ? await readEnablementLinks(adapter, linkDirs, linkNames) : new Map;
|
|
2913
|
+
let wroteService = false;
|
|
2914
|
+
let wroteTimer = false;
|
|
2915
|
+
let didEnable = false;
|
|
2916
|
+
let didActivate = false;
|
|
2917
|
+
try {
|
|
2918
|
+
if (!serviceBytesMatch || !serviceModeMatches) {
|
|
2919
|
+
wroteService = true;
|
|
2920
|
+
await adapter.writeFileAtomic(options.serviceUnitPath, options.serviceContent, { mode });
|
|
2921
|
+
}
|
|
2922
|
+
if (!timerBytesMatch || !timerModeMatches) {
|
|
2923
|
+
wroteTimer = true;
|
|
2924
|
+
await adapter.writeFileAtomic(options.timerUnitPath, options.timerContent, { mode });
|
|
2925
|
+
}
|
|
2926
|
+
if (wroteService || wroteTimer || pre.service.needsReload || pre.timer.needsReload || pre.service.status !== "matches" || pre.timer.status !== "matches") {
|
|
2927
|
+
await runSystemctlChecked(adapter, options.scope, ["daemon-reload"]);
|
|
2928
|
+
}
|
|
2929
|
+
const loaded = await checkSystemdTimerPair({
|
|
2930
|
+
serviceUnitName: options.serviceUnitName,
|
|
2931
|
+
serviceUnitPath: options.serviceUnitPath,
|
|
2932
|
+
expectedServiceContent: options.serviceContent,
|
|
2933
|
+
timerUnitName: options.timerUnitName,
|
|
2934
|
+
timerUnitPath: options.timerUnitPath,
|
|
2935
|
+
expectedTimerContent: options.timerContent,
|
|
2936
|
+
scope: options.scope,
|
|
2937
|
+
...options.unitSearchDirs ? { unitSearchDirs: options.unitSearchDirs } : {},
|
|
2938
|
+
adapter
|
|
2939
|
+
});
|
|
2940
|
+
if (!loaded.service.ok) {
|
|
2941
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `systemd did not load ${options.serviceUnitPath} for ${options.serviceUnitName} (${loaded.service.status})`);
|
|
2942
|
+
}
|
|
2943
|
+
if (!loaded.timer.ok) {
|
|
2944
|
+
throw new SystemdUnitError("FOREIGN_FRAGMENT", `systemd did not load ${options.timerUnitPath} for ${options.timerUnitName} (${loaded.timer.status})`);
|
|
2945
|
+
}
|
|
2946
|
+
const finalState = await activateTimerAfterReload(adapter, options, pre, loaded, wroteTimer, enable, start, {
|
|
2947
|
+
onEnable: () => {
|
|
2948
|
+
didEnable = true;
|
|
2949
|
+
},
|
|
2950
|
+
onActivate: () => {
|
|
2951
|
+
didActivate = true;
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
return {
|
|
2955
|
+
serviceUnitName: options.serviceUnitName,
|
|
2956
|
+
serviceDigest,
|
|
2957
|
+
timerUnitName: options.timerUnitName,
|
|
2958
|
+
timerDigest,
|
|
2959
|
+
changed: true,
|
|
2960
|
+
timerActive: finalState.timerActive,
|
|
2961
|
+
timerEnabled: finalState.timerEnabled
|
|
2962
|
+
};
|
|
2963
|
+
} catch (cause) {
|
|
2964
|
+
let rolledBack = false;
|
|
2965
|
+
let rollbackError;
|
|
2966
|
+
try {
|
|
2967
|
+
await rollbackTimerPair(adapter, {
|
|
2968
|
+
scope: options.scope,
|
|
2969
|
+
serviceUnitPath: options.serviceUnitPath,
|
|
2970
|
+
timerUnitName: options.timerUnitName,
|
|
2971
|
+
timerUnitPath: options.timerUnitPath,
|
|
2972
|
+
previousServiceBytes,
|
|
2973
|
+
previousServiceMode: serviceStanding.kind === "file" ? serviceStanding.mode : mode,
|
|
2974
|
+
previousTimerBytes,
|
|
2975
|
+
previousTimerMode: timerStanding.kind === "file" ? timerStanding.mode : mode,
|
|
2976
|
+
timerWasActive: pre.timerActive,
|
|
2977
|
+
previousTimerUnitFileState: pre.timer.unitFileState,
|
|
2978
|
+
linkDirs,
|
|
2979
|
+
linkNames,
|
|
2980
|
+
linksBefore,
|
|
2981
|
+
wroteService,
|
|
2982
|
+
wroteTimer,
|
|
2983
|
+
didEnable,
|
|
2984
|
+
didActivate
|
|
2985
|
+
});
|
|
2986
|
+
rolledBack = true;
|
|
2987
|
+
} catch (rbError) {
|
|
2988
|
+
rollbackError = rbError;
|
|
2989
|
+
}
|
|
2990
|
+
const code = cause instanceof SystemdUnitError ? cause.code : "COMMAND_FAILED";
|
|
2991
|
+
const baseMessage = messageOf(cause);
|
|
2992
|
+
const message = !rolledBack && rollbackError !== undefined ? `${baseMessage}; rollback also failed: ${messageOf(rollbackError)}` : baseMessage;
|
|
2993
|
+
throw new SystemdUnitError(code, message, { cause, rolledBack, rollbackError });
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
// src/service-host/systemd-timer-render.ts
|
|
2997
|
+
import { z as z4 } from "zod";
|
|
2998
|
+
var OnCalendarItemSchema = z4.string().refine((value) => value.trim().length > 0, "onCalendar expression must not be empty");
|
|
2999
|
+
var SystemdTimerUnitConfigSchema = z4.strictObject({
|
|
3000
|
+
description: z4.string().min(1),
|
|
3001
|
+
scope: SystemdScopeSchema.default("system"),
|
|
3002
|
+
after: z4.array(z4.string().min(1)).optional(),
|
|
3003
|
+
wants: z4.array(z4.string().min(1)).optional(),
|
|
3004
|
+
unit: z4.string().min(1).optional(),
|
|
3005
|
+
onCalendar: z4.union([OnCalendarItemSchema, z4.array(OnCalendarItemSchema).min(1)]).optional(),
|
|
3006
|
+
onBootSec: SystemdTimespanSchema.optional(),
|
|
3007
|
+
onStartupSec: SystemdTimespanSchema.optional(),
|
|
3008
|
+
onActiveSec: SystemdTimespanSchema.optional(),
|
|
3009
|
+
onUnitActiveSec: SystemdTimespanSchema.optional(),
|
|
3010
|
+
onUnitInactiveSec: SystemdTimespanSchema.optional(),
|
|
3011
|
+
accuracySec: SystemdTimespanSchema.optional(),
|
|
3012
|
+
randomizedDelaySec: SystemdTimespanSchema.optional(),
|
|
3013
|
+
persistent: z4.boolean().optional(),
|
|
3014
|
+
wantedBy: z4.array(z4.string().min(1)).optional(),
|
|
3015
|
+
allowHomeSpecifier: z4.boolean().default(false)
|
|
3016
|
+
}).check((ctx) => {
|
|
3017
|
+
const value = ctx.value;
|
|
3018
|
+
const hasTrigger = value.onCalendar !== undefined || value.onBootSec !== undefined || value.onStartupSec !== undefined || value.onActiveSec !== undefined || value.onUnitActiveSec !== undefined || value.onUnitInactiveSec !== undefined;
|
|
3019
|
+
if (!hasTrigger) {
|
|
3020
|
+
ctx.issues.push({
|
|
3021
|
+
code: "custom",
|
|
3022
|
+
input: value,
|
|
3023
|
+
path: ["onCalendar"],
|
|
3024
|
+
message: "systemd timer unit requires at least one trigger (onCalendar, onBootSec, onStartupSec, onActiveSec, onUnitActiveSec, or onUnitInactiveSec)"
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
if (value.persistent === true && value.onCalendar === undefined) {
|
|
3028
|
+
ctx.issues.push({
|
|
3029
|
+
code: "custom",
|
|
3030
|
+
input: value,
|
|
3031
|
+
path: ["persistent"],
|
|
3032
|
+
message: "systemd Persistent=yes requires onCalendar"
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
if (value.unit !== undefined && !value.unit.endsWith(".service")) {
|
|
3036
|
+
ctx.issues.push({
|
|
3037
|
+
code: "custom",
|
|
3038
|
+
input: value.unit,
|
|
3039
|
+
path: ["unit"],
|
|
3040
|
+
message: `systemd timer 'unit' must end with '.service': ${JSON.stringify(value.unit)}`
|
|
3041
|
+
});
|
|
3042
|
+
}
|
|
3043
|
+
});
|
|
3044
|
+
function renderSystemdTimerUnit(config) {
|
|
3045
|
+
const parsedResult = SystemdTimerUnitConfigSchema.safeParse(config);
|
|
3046
|
+
if (!parsedResult.success) {
|
|
3047
|
+
throw new SystemdUnitError("INVALID_CONFIG", `Invalid systemd timer configuration: ${parsedResult.error.message}`, { cause: parsedResult.error });
|
|
3048
|
+
}
|
|
3049
|
+
const parsed = parsedResult.data;
|
|
3050
|
+
const allowHome = parsed.allowHomeSpecifier;
|
|
3051
|
+
const unitLines = [
|
|
3052
|
+
"[Unit]",
|
|
3053
|
+
`Description=${formatSystemdScalar("description", parsed.description, allowHome)}`
|
|
3054
|
+
];
|
|
3055
|
+
if (parsed.after && parsed.after.length > 0) {
|
|
3056
|
+
const items = parsed.after.map((item, i) => formatSystemdScalar(`after[${i}]`, item, false, true));
|
|
3057
|
+
unitLines.push(`After=${items.join(" ")}`);
|
|
3058
|
+
}
|
|
3059
|
+
if (parsed.wants && parsed.wants.length > 0) {
|
|
3060
|
+
const items = parsed.wants.map((item, i) => formatSystemdScalar(`wants[${i}]`, item, false, true));
|
|
3061
|
+
unitLines.push(`Wants=${items.join(" ")}`);
|
|
3062
|
+
}
|
|
3063
|
+
const timerLines = ["[Timer]"];
|
|
3064
|
+
if (parsed.unit !== undefined) {
|
|
3065
|
+
assertValidSystemdUnitName(parsed.unit);
|
|
3066
|
+
timerLines.push(`Unit=${formatSystemdScalar("unit", parsed.unit, false, true)}`);
|
|
3067
|
+
}
|
|
3068
|
+
for (const [index, expr] of toStringList(parsed.onCalendar).entries()) {
|
|
3069
|
+
timerLines.push(`OnCalendar=${formatSystemdScalar(`onCalendar[${index}]`, expr, false, false)}`);
|
|
3070
|
+
}
|
|
3071
|
+
if (parsed.onBootSec !== undefined) {
|
|
3072
|
+
timerLines.push(`OnBootSec=${formatSystemdDuration("onBootSec", parsed.onBootSec)}`);
|
|
3073
|
+
}
|
|
3074
|
+
if (parsed.onStartupSec !== undefined) {
|
|
3075
|
+
timerLines.push(`OnStartupSec=${formatSystemdDuration("onStartupSec", parsed.onStartupSec)}`);
|
|
3076
|
+
}
|
|
3077
|
+
if (parsed.onActiveSec !== undefined) {
|
|
3078
|
+
timerLines.push(`OnActiveSec=${formatSystemdDuration("onActiveSec", parsed.onActiveSec)}`);
|
|
3079
|
+
}
|
|
3080
|
+
if (parsed.onUnitActiveSec !== undefined) {
|
|
3081
|
+
timerLines.push(`OnUnitActiveSec=${formatSystemdDuration("onUnitActiveSec", parsed.onUnitActiveSec)}`);
|
|
3082
|
+
}
|
|
3083
|
+
if (parsed.onUnitInactiveSec !== undefined) {
|
|
3084
|
+
timerLines.push(`OnUnitInactiveSec=${formatSystemdDuration("onUnitInactiveSec", parsed.onUnitInactiveSec)}`);
|
|
3085
|
+
}
|
|
3086
|
+
if (parsed.accuracySec !== undefined) {
|
|
3087
|
+
timerLines.push(`AccuracySec=${formatSystemdDuration("accuracySec", parsed.accuracySec)}`);
|
|
3088
|
+
}
|
|
3089
|
+
if (parsed.randomizedDelaySec !== undefined) {
|
|
3090
|
+
timerLines.push(`RandomizedDelaySec=${formatSystemdDuration("randomizedDelaySec", parsed.randomizedDelaySec)}`);
|
|
3091
|
+
}
|
|
3092
|
+
if (parsed.persistent !== undefined) {
|
|
3093
|
+
timerLines.push(`Persistent=${parsed.persistent ? "yes" : "no"}`);
|
|
3094
|
+
}
|
|
3095
|
+
const sections = [unitLines.join(`
|
|
3096
|
+
`), timerLines.join(`
|
|
3097
|
+
`)];
|
|
3098
|
+
if (parsed.wantedBy === undefined || parsed.wantedBy.length > 0) {
|
|
3099
|
+
const wantedBy = parsed.wantedBy ?? ["timers.target"];
|
|
3100
|
+
const targets = wantedBy.map((item, i) => formatSystemdScalar(`wantedBy[${i}]`, item, false, true));
|
|
3101
|
+
sections.push(["[Install]", `WantedBy=${targets.join(" ")}`].join(`
|
|
3102
|
+
`));
|
|
3103
|
+
}
|
|
3104
|
+
return `${sections.join(`
|
|
3105
|
+
|
|
3106
|
+
`)}
|
|
3107
|
+
`;
|
|
3108
|
+
}
|
|
2502
3109
|
export {
|
|
2503
3110
|
ARTIFACT_MANIFEST_FILENAME2 as ARTIFACT_MANIFEST_FILENAME,
|
|
2504
3111
|
ArtifactFileEntrySchema2 as ArtifactFileEntrySchema,
|
|
@@ -2516,9 +3123,11 @@ export {
|
|
|
2516
3123
|
PLUTIL_PATH2 as PLUTIL_PATH,
|
|
2517
3124
|
SystemdScopeSchema,
|
|
2518
3125
|
SystemdServiceUnitConfigSchema,
|
|
3126
|
+
SystemdTimerUnitConfigSchema,
|
|
2519
3127
|
SystemdUnitError,
|
|
2520
3128
|
activateVersionedArtifact,
|
|
2521
3129
|
bootoutLaunchdJob,
|
|
3130
|
+
checkSystemdTimerPair,
|
|
2522
3131
|
checkSystemdUnit,
|
|
2523
3132
|
computeArtifactManifestDigest2 as computeArtifactManifestDigest,
|
|
2524
3133
|
createDefaultLaunchdHostAdapter2 as createDefaultLaunchdHostAdapter,
|
|
@@ -2527,6 +3136,7 @@ export {
|
|
|
2527
3136
|
createPolledJsonConfigSource,
|
|
2528
3137
|
inspectLaunchdJob,
|
|
2529
3138
|
installAndStartSystemdUnit,
|
|
3139
|
+
installSystemdTimerPair,
|
|
2530
3140
|
lintLaunchdPlist2 as lintLaunchdPlist,
|
|
2531
3141
|
parseLaunchctlPrint2 as parseLaunchctlPrint,
|
|
2532
3142
|
parseProcNetUnixListeningSockets,
|
|
@@ -2535,6 +3145,7 @@ export {
|
|
|
2535
3145
|
reloadSystemdUnit,
|
|
2536
3146
|
renderLaunchdPlist2 as renderLaunchdPlist,
|
|
2537
3147
|
renderSystemdServiceUnit,
|
|
3148
|
+
renderSystemdTimerUnit,
|
|
2538
3149
|
rollbackVersionedArtifact,
|
|
2539
3150
|
startConfigReloader,
|
|
2540
3151
|
systemdMainPid,
|