@synopackageland/cli 0.48.2 → 0.48.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +6 -0
- package/dist/cli.js +1 -1
- package/dist/ctl/ai-tools.d.ts +1 -1
- package/dist/ctl/registry.d.ts +1 -1
- package/dist/ctl/registry.js +2 -2
- package/dist/error-registry.js +1 -0
- package/dist/nas/transport.js +3 -1
- package/dist/runtime/executor-policy.d.ts +6 -0
- package/dist/runtime/executor-policy.js +10 -6
- package/dist/runtime/operation-budget.d.ts +1 -0
- package/dist/runtime/operation-budget.js +1 -0
- package/dist/runtime/runtime-budgets.d.ts +1 -1
- package/dist/runtime/runtime-budgets.js +3 -2
- package/dist/standalone/api-description.js +58 -1
- package/dist/standalone/daemon-nofile.d.ts +13 -0
- package/dist/standalone/daemon-nofile.js +96 -0
- package/dist/standalone/daemon.d.ts +2 -0
- package/dist/standalone/daemon.js +8 -0
- package/dist/standalone/inspect-spk.js +35 -7
- package/dist/standalone/lifecycle.js +2 -1
- package/dist/standalone/manifest.d.ts +2 -0
- package/dist/standalone/manifest.js +13 -0
- package/dist/standalone/spk.js +8 -1
- package/dist/validate.js +7 -1
- package/package.json +5 -3
- package/schema/synopkgland-api-v2.schema.json +3 -3
- package/skills/SKILL.md +8 -0
- package/skills/reference/ctl.md +7 -2
- package/skills/reference/lifecycle.md +34 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.4
|
|
4
|
+
|
|
5
|
+
- Derive executor policy and runtime operation defaults from the SDK shared operation contract; preserve explicit App overrides without inheriting shorter implicit daemon lifecycle defaults
|
|
6
|
+
|
|
7
|
+
- Restore check and build support for legacy v1 ctl.commands Apps, with one nonblocking deprecation warning during check
|
|
8
|
+
- Remove byte-size caps from App-authored operation registry files and authenticated description reads; retain validation, route equality and ordinary request limits
|
|
9
|
+
|
|
10
|
+
## 0.48.3
|
|
11
|
+
|
|
12
|
+
- Make v2 job flow timeoutMs optional in commands and operations, matching v1: shared per-request budgets and no total polling deadline; retain explicit bounds and preserve omission through generation
|
|
13
|
+
|
|
14
|
+
- Add opt-in daemon.nofile (1024–1048576) through a fixed DSM-acquired package system unit with LimitNOFILE and package User/Group
|
|
15
|
+
- Preserve SDK-owned deadlines, non-root supervision, legacy omission and upgrade stop/uninstall routing; reject old or mismatched SDK sources
|
|
16
|
+
- Inspect the exact unit, metadata and controller config together; retain SDK 0.49.5 from 0.48.2
|
|
17
|
+
|
|
3
18
|
## 0.48.2
|
|
4
19
|
|
|
5
20
|
- Pin SDK 0.49.5 for CLI-owned controllers and planning so they inherit the shared operation policy
|
package/README.md
CHANGED
|
@@ -649,3 +649,9 @@ not a GPU blocker. Plan metadata describes SDK policy, not an attestation of the
|
|
|
649
649
|
provider's final container configuration; see the SDK Compose security boundary.
|
|
650
650
|
|
|
651
651
|
For same-origin App URLs, see [DSM path ingress](docs/path-ingress.md).
|
|
652
|
+
|
|
653
|
+
### CLI release checks
|
|
654
|
+
|
|
655
|
+
`npm run gates` runs basic checks and is the default for release packaging and CI.
|
|
656
|
+
Use `npm run gates:full` only when explicitly requested. See
|
|
657
|
+
[release entry points and checks](docs/release-checks.md) for the complete inventory.
|
package/dist/cli.js
CHANGED
|
@@ -391,7 +391,7 @@ async function runCliWithin(argv) {
|
|
|
391
391
|
: loadStandaloneManifest(standalone);
|
|
392
392
|
if (!loaded.ok)
|
|
393
393
|
throw failure(loaded.errors[0].code, loaded.errors.map((e) => `[${e.code}] ${e.message}`).join("\n"), "Update dsm-package.yaml to schema: 2, fix the declaration and retry.");
|
|
394
|
-
if ('ctl' in loaded.manifest &&
|
|
394
|
+
if ('ctl' in loaded.manifest && loaded.manifest.ctl?.registry) {
|
|
395
395
|
const { generateOperations } = await import('./standalone/operation-registry.js');
|
|
396
396
|
const { spawnSync } = await import('node:child_process');
|
|
397
397
|
await generateOperations(loaded.manifest, (command, args, options) => {
|
package/dist/ctl/ai-tools.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function listAiTools(client: CtlClient, appName: string, options?
|
|
|
18
18
|
destructiveHint: boolean;
|
|
19
19
|
openWorldHint: boolean;
|
|
20
20
|
};
|
|
21
|
-
ai: "read" | "preview" | "draft" | "human-only"
|
|
21
|
+
ai: "hidden" | "read" | "preview" | "draft" | "human-only";
|
|
22
22
|
flow: import("./descriptor.js").Flow;
|
|
23
23
|
}[];
|
|
24
24
|
}>;
|
package/dist/ctl/registry.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare function registryTools(registry: OperationRegistry): {
|
|
|
39
39
|
destructiveHint: boolean;
|
|
40
40
|
openWorldHint: boolean;
|
|
41
41
|
};
|
|
42
|
-
ai: "read" | "preview" | "draft" | "human-only"
|
|
42
|
+
ai: "hidden" | "read" | "preview" | "draft" | "human-only";
|
|
43
43
|
flow: import("./descriptor.js").Flow;
|
|
44
44
|
}[];
|
|
45
45
|
export declare function registryReference(registry: OperationRegistry): string;
|
package/dist/ctl/registry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
2
2
|
import { dirname, join, resolve, relative, isAbsolute } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { strictJson } from './json.js';
|
|
4
4
|
import { ajv, safeSchema, validateFlow } from './descriptor.js';
|
|
5
5
|
export const AI_CLASSES = ['read', 'preview', 'draft', 'human-only', 'hidden'];
|
|
6
6
|
export const INFRASTRUCTURE_METHODS = new Set(['synopkgland.describe', 'identity.status', 'identity.login', 'identity.session', 'identity.logout']);
|
|
@@ -12,7 +12,7 @@ export function registryFile(root, file) {
|
|
|
12
12
|
return path;
|
|
13
13
|
}
|
|
14
14
|
export function readRegistry(path) {
|
|
15
|
-
const raw =
|
|
15
|
+
const raw = readFileSync(path);
|
|
16
16
|
const value = strictJson(raw);
|
|
17
17
|
validateRegistry(value);
|
|
18
18
|
return value;
|
package/dist/error-registry.js
CHANGED
|
@@ -35,6 +35,7 @@ export const ERROR_REGISTRY = {
|
|
|
35
35
|
INIT_UPSTREAM_IMAGE_INVALID: { code: "INIT_UPSTREAM_IMAGE_INVALID", description: "The upstream image repository is invalid.", suggestion: "Supply the official repository without a tag or digest; upgrade.sh selects the matching release and resolves its digest." },
|
|
36
36
|
CTL_APP_NEEDS_APPROVAL: { "code": "CTL_APP_NEEDS_APPROVAL", "description": "The installed App needs approval or re-approval.", "suggestion": "Run synopkgland ctl list --app <package-id> --approve-installed --host <host>." },
|
|
37
37
|
COMPOSE_HEALTH_REQUIRED: { code: "COMPOSE_HEALTH_REQUIRED", description: "Compose web readiness was not selected.", suggestion: "Set compose.web.health.path and expected 2xx status for the actual App; redirects are not followed." },
|
|
38
|
+
CTL_LEGACY_COMMANDS_DEPRECATED: { code: 'CTL_LEGACY_COMMANDS_DEPRECATED', description: 'The App uses the supported legacy ctl.commands declaration.', suggestion: 'Plan migration to ctl.registry when ready; check and build continue to support v1.' },
|
|
38
39
|
CTL_REGISTRY_REQUIRED: { code: 'CTL_REGISTRY_REQUIRED', description: 'The App needs a single operation registry.', suggestion: 'Replace ctl.commands with ctl.registry and run synopkgland ctl generate.' },
|
|
39
40
|
CTL_REGISTRY_INVALID: { code: 'CTL_REGISTRY_INVALID', description: 'The operation registry is invalid.', suggestion: 'Declare every method with its required ai class, schemas, effect, permission and fixed flow.' },
|
|
40
41
|
CTL_ROUTE_MISMATCH: { code: 'CTL_ROUTE_MISMATCH', description: 'Operation specs and registered handlers differ.', suggestion: 'Match all method names and permissions in both directions, including hidden methods.' },
|
package/dist/nas/transport.js
CHANGED
|
@@ -34,6 +34,8 @@ export function createRequest(origin, timeoutMs = undefined, ca, trust) {
|
|
|
34
34
|
if (url.origin !== origin || (session && session.origin !== origin))
|
|
35
35
|
throw new CtlError('CTL_ORIGIN_MISMATCH', 'Credentials cannot cross NAS origins.', 'run: synopkgland host list', 4);
|
|
36
36
|
const form = body instanceof URLSearchParams;
|
|
37
|
+
// Discovery returns the trusted App-authored registry, rather than operation input.
|
|
38
|
+
const description = !(body instanceof URLSearchParams) && body.method === 'synopkgland.describe' && path.startsWith('/webman/3rdparty/') && path.endsWith('/cgi/api.cgi');
|
|
37
39
|
const payload = Buffer.from(form ? body.toString() : JSON.stringify(body));
|
|
38
40
|
if (payload.length > 1048576)
|
|
39
41
|
throw new CtlError('CTL_INPUT_TOO_LARGE', 'Request exceeds 1 MiB.', 'Reduce the input.');
|
|
@@ -56,7 +58,7 @@ export function createRequest(origin, timeoutMs = undefined, ca, trust) {
|
|
|
56
58
|
}
|
|
57
59
|
const chunks = [];
|
|
58
60
|
let length = 0;
|
|
59
|
-
res.on('data', (c) => { length += c.length; if (length > 1048576) {
|
|
61
|
+
res.on('data', (c) => { length += c.length; if (!description && length > 1048576) {
|
|
60
62
|
res.destroy();
|
|
61
63
|
reject(new CtlError('CTL_RESPONSE_TOO_LARGE', 'Response exceeds 1 MiB.', 'Use a smaller operation.', 5));
|
|
62
64
|
}
|
|
@@ -76,6 +76,12 @@ export declare function executorPolicy(m: {
|
|
|
76
76
|
status: number;
|
|
77
77
|
uninstall: number;
|
|
78
78
|
};
|
|
79
|
+
declaredLifecycleTimeouts?: Partial<{
|
|
80
|
+
start: number;
|
|
81
|
+
stop: number;
|
|
82
|
+
status: number;
|
|
83
|
+
uninstall: number;
|
|
84
|
+
}>;
|
|
79
85
|
backend?: {
|
|
80
86
|
kind: string;
|
|
81
87
|
timeoutSeconds?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_OPERATION_TIMEOUT_SECONDS } from './operation-budget.js';
|
|
1
2
|
import { operationBudgetSeconds } from "./runtime-budgets.js";
|
|
2
3
|
import { validWebAPIProfiles, sortedWebAPIProfiles } from './webapi-profile.js';
|
|
3
4
|
import { createHash } from 'node:crypto';
|
|
@@ -51,6 +52,9 @@ export function executorPolicy(m, arch) {
|
|
|
51
52
|
root[op.name] = rootEntry(op, settings?.programs?.[op.name], arch);
|
|
52
53
|
operations.push(...rootOperations(root));
|
|
53
54
|
}
|
|
55
|
+
// Loaded manifests retain only author-declared lifecycle overrides here.
|
|
56
|
+
// Direct callers can still supply normalized settings explicitly.
|
|
57
|
+
const lifecycle = m.declaredLifecycleTimeouts ?? m.lifecycleTimeouts ?? m.daemon?.timeouts;
|
|
54
58
|
const d = m.capabilities.delegate;
|
|
55
59
|
const purge = m.capabilities.rootOps ? m.uninstall?.purge.root : undefined;
|
|
56
60
|
return { v: 1, package: m.package, app: `SYNO.SDS.${m.package}.Instance`, ...(m.entry ? { entry: m.entry } : {}), ...(d ? { scope: d.scope } : {}),
|
|
@@ -58,12 +62,12 @@ export function executorPolicy(m, arch) {
|
|
|
58
62
|
operations: [...new Set(operations)].sort(), ...(portal ? { portal } : {}), ...(purge ? { purge } : {}), ...(settings?.stop ? { stop: settings.stop } : {}),
|
|
59
63
|
...(settings?.start ? { start: settings.start } : {}),
|
|
60
64
|
...(m.capabilities.webapi ? { webapi: sortedWebAPIProfiles(m.capabilities.webapi) } : {}),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
timeouts: {
|
|
66
|
+
start: lifecycle?.start ?? DEFAULT_OPERATION_TIMEOUT_SECONDS,
|
|
67
|
+
stop: lifecycle?.stop ?? DEFAULT_OPERATION_TIMEOUT_SECONDS,
|
|
68
|
+
purge: lifecycle?.uninstall ?? Math.min(3600, Math.max(DEFAULT_OPERATION_TIMEOUT_SECONDS, m.uninstall?.purge.timeout ?? 0)),
|
|
69
|
+
operation: operationBudgetSeconds(m),
|
|
70
|
+
},
|
|
67
71
|
root, ...(settings?.state ? { root_state: true } : {}) };
|
|
68
72
|
}
|
|
69
73
|
/** A script without settings keeps the bare digest; a binary pins the bytes built for this architecture. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
// Build-time snapshot of the SDK timeout contract, shipped in schema/.
|
|
3
3
|
const budget = JSON.parse(readFileSync(new URL('../../schema/sdk-timeouts.json', import.meta.url), 'utf8'));
|
|
4
|
+
export const DEFAULT_OPERATION_TIMEOUT_SECONDS = budget.executor.op_s;
|
|
4
5
|
export const DEFAULT_OPERATION_TIMEOUT_MS = budget.request.default_s * 1000;
|
|
5
6
|
export const RESPONSE_RESERVE_MS = budget.browser.margin_ms;
|
|
@@ -16,7 +16,7 @@ interface OperationBudgetSource {
|
|
|
16
16
|
/**
|
|
17
17
|
* A CGI's declared request budget owns operation work. Binary and Compose Apps
|
|
18
18
|
* have no compiled CGI deadline to configure, so their existing status allowance
|
|
19
|
-
* can enlarge the shared operation budget above
|
|
19
|
+
* can enlarge the shared operation budget above the SDK shared default.
|
|
20
20
|
*/
|
|
21
21
|
export declare function operationBudgetSeconds(source: OperationBudgetSource): number;
|
|
22
22
|
/** First released SDK that decodes operation/lifecycle budget config fields. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_OPERATION_TIMEOUT_SECONDS } from './operation-budget.js';
|
|
1
2
|
/**
|
|
2
3
|
* A CGI's declared request budget owns operation work. Binary and Compose Apps
|
|
3
4
|
* have no compiled CGI deadline to configure, so their existing status allowance
|
|
4
|
-
* can enlarge the shared operation budget above
|
|
5
|
+
* can enlarge the shared operation budget above the SDK shared default.
|
|
5
6
|
*/
|
|
6
7
|
export function operationBudgetSeconds(source) {
|
|
7
|
-
return source.backend?.timeoutSeconds ?? Math.max(
|
|
8
|
+
return source.backend?.timeoutSeconds ?? Math.max(DEFAULT_OPERATION_TIMEOUT_SECONDS, source.lifecycleTimeouts?.status ?? source.daemon?.timeouts?.status ?? 5);
|
|
8
9
|
}
|
|
9
10
|
/** First released SDK that decodes operation/lifecycle budget config fields. */
|
|
10
11
|
export function runtimeBudgetSdkSupported(sdk) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { portalByExecutor } from '../build-spk/dsm-version.js';
|
|
2
2
|
import { generateOperations } from './operation-registry.js';
|
|
3
3
|
import { readFileSync, mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { makeDescriptor, validateDescriptor, flowMethods } from '../ctl/descriptor.js';
|
|
4
5
|
import { tmpdir } from 'node:os';
|
|
5
6
|
import { requiredSdk } from '../runtime/sdk-source.js';
|
|
6
7
|
import { renderBridgeJson } from './bridge-json.js';
|
|
@@ -21,7 +22,7 @@ export async function buildApiDescription(m, bridgeMethods, run) {
|
|
|
21
22
|
return undefined;
|
|
22
23
|
if (m.backend.kind === 'binary' || m.compose)
|
|
23
24
|
throw new StandaloneBuildError('CTL_UNSUPPORTED_BACKEND', 'Automatic API descriptions require a standard SDK native App.');
|
|
24
|
-
|
|
25
|
+
return buildLegacyApiDescription(m, await describeApiRoutes(m, bridgeMethods, run));
|
|
25
26
|
}
|
|
26
27
|
export async function describeApiRoutes(m, bridgeMethods, run) {
|
|
27
28
|
if (m.backend.kind === 'binary')
|
|
@@ -63,3 +64,59 @@ export async function describeApiRoutes(m, bridgeMethods, run) {
|
|
|
63
64
|
throw new StandaloneBuildError('CTL_DESCRIBE_FAILED', 'Invalid registry snapshot.');
|
|
64
65
|
return methods.map(route => m.entry === 'admin-only' && !['identity.status', 'identity.login', 'identity.session', 'identity.logout'].includes(route.method) ? { ...route, permission: 'administrators' } : route);
|
|
65
66
|
}
|
|
67
|
+
/** Retain the v1 protocol for existing Apps; new registries use the v2 path above. */
|
|
68
|
+
function buildLegacyApiDescription(m, methods) {
|
|
69
|
+
const ctl = m.ctl;
|
|
70
|
+
const registry = new Map(methods.map(item => [item.method, item.permission]));
|
|
71
|
+
const rawHTTP = new Set(methods.filter(item => item.kind === 'http').map(item => item.method));
|
|
72
|
+
const nonRPC = new Set(methods.filter(item => item.kind && item.kind !== 'json').map(item => item.method));
|
|
73
|
+
// Identity transport routes are outside the business registry but have immutable SDK ownership.
|
|
74
|
+
if (m.capabilities.identity) {
|
|
75
|
+
registry.set('identity.session', 'public');
|
|
76
|
+
registry.set('identity.logout', 'public');
|
|
77
|
+
}
|
|
78
|
+
const bindings = {};
|
|
79
|
+
const commands = {};
|
|
80
|
+
if (ctl.external) {
|
|
81
|
+
if (m.capabilities.identity)
|
|
82
|
+
throw new StandaloneBuildError('CTL_EXTERNAL_TRANSPORT', 'External entries require the DSM session transport.');
|
|
83
|
+
for (const entry of Object.values(ctl.external)) {
|
|
84
|
+
if (!entry || typeof entry.method !== 'string' || !registry.has(entry.method) || nonRPC.has(entry.method) || m.entry !== 'admin-only' && registry.get(entry.method) !== 'administrators')
|
|
85
|
+
throw new StandaloneBuildError('CTL_EXTERNAL_ENTRY', 'External entries require registered administrator RPC methods.');
|
|
86
|
+
registry.set(entry.method, 'administrators');
|
|
87
|
+
bindings[entry.method] = { permission: 'administrators', effect: 'destructive' };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const weights = { read: 0, write: 1, destructive: 2 };
|
|
91
|
+
for (const [id, declared] of Object.entries(ctl.commands)) {
|
|
92
|
+
const command = structuredClone(declared);
|
|
93
|
+
const names = flowMethods(command.flow);
|
|
94
|
+
let permission = 'public';
|
|
95
|
+
for (const name of names) {
|
|
96
|
+
if (rawHTTP.has(name))
|
|
97
|
+
throw new StandaloneBuildError('CTL_COMMAND_UNREGISTERED', `Command ${id} references raw HTTP route ${name}; ctl commands require RPC methods.`);
|
|
98
|
+
if (!registry.has(name))
|
|
99
|
+
throw new StandaloneBuildError('CTL_COMMAND_UNREGISTERED', `Command ${id} references unregistered method ${name}.`);
|
|
100
|
+
const effective = m.entry === 'admin-only' ? 'administrators' : registry.get(name);
|
|
101
|
+
registry.set(name, effective);
|
|
102
|
+
const effect = command.flow.type === 'job' && name !== command.flow.start ? 'read' : command.effect;
|
|
103
|
+
const previous = bindings[name];
|
|
104
|
+
if (!previous || weights[effect] > weights[previous.effect])
|
|
105
|
+
bindings[name] = { permission: effective, effect };
|
|
106
|
+
if (effective === 'administrators' || effective === 'authenticated' && permission === 'public')
|
|
107
|
+
permission = effective;
|
|
108
|
+
}
|
|
109
|
+
commands[id] = { ...command, permission };
|
|
110
|
+
}
|
|
111
|
+
if (m.capabilities.identity) {
|
|
112
|
+
for (const method of ['identity.session', 'identity.logout'])
|
|
113
|
+
bindings[method] = { permission: 'public', effect: 'write' };
|
|
114
|
+
}
|
|
115
|
+
const description = makeDescriptor({ package: { id: m.package, version: m.spkVersion, displayName: m.displayname }, aliases: ctl.aliases ?? [m.package.toLowerCase()], provenance: { developedBy: ctl.developedBy ?? 'unknown', generator: 'synopkgland-cli' }, entry: m.entry ?? 'policy', transport: { path: `/webman/3rdparty/${m.package}/cgi/api.cgi`, auth: m.capabilities.identity ? 'dsm-app-session' : 'dsm-session' }, commands, bindings, ...(ctl.external ? { external: ctl.external } : {}) });
|
|
116
|
+
try {
|
|
117
|
+
return { description: validateDescriptor(description, m.package, m.spkVersion), registry: Object.fromEntries(registry) };
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new StandaloneBuildError('CTL_DESCRIPTOR_INVALID', error.message);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StandaloneError, StandaloneManifest } from './manifest.js';
|
|
2
|
+
export declare const DAEMON_NOFILE_MIN_SDK = "0.49.5";
|
|
3
|
+
export declare const DAEMON_NOFILE_MIN_DSM = "7.0-40761";
|
|
4
|
+
export declare function daemonNoFileSdkProblem(sdk: string): string | undefined;
|
|
5
|
+
export declare function daemonNoFileIdentityProblem(pkg: string): string | undefined;
|
|
6
|
+
export declare function readNoFile(value: unknown, fail: (e: StandaloneError) => void): number | undefined;
|
|
7
|
+
export declare function daemonSystemUnitName(pkg: string): string;
|
|
8
|
+
export declare function renderDaemonSystemUnit(pkg: string, nofile: number): string;
|
|
9
|
+
/** One fixed dispatch layer covers every native lifecycle composition, including
|
|
10
|
+
* delegated jobs and rootOps. The unit itself calls the SDK directly. */
|
|
11
|
+
export declare function renderNoFileLifecycle(manifest: StandaloneManifest, script: string): string;
|
|
12
|
+
/** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
|
|
13
|
+
export declare function requireDaemonNoFileSource(dir: string, sdk: string, nofile?: number): void;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { StandaloneBuildError } from './spk.js';
|
|
4
|
+
export const DAEMON_NOFILE_MIN_SDK = '0.49.5';
|
|
5
|
+
export const DAEMON_NOFILE_MIN_DSM = '7.0-40761';
|
|
6
|
+
export function daemonNoFileSdkProblem(sdk) {
|
|
7
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(sdk);
|
|
8
|
+
if (match) {
|
|
9
|
+
const [major, minor, patch] = match.slice(1).map(Number);
|
|
10
|
+
if (major > 0 || minor > 49 || minor === 49 && patch >= 5)
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return `daemon.nofile requires SDK ${DAEMON_NOFILE_MIN_SDK} or later; selected SDK ${sdk}`;
|
|
14
|
+
}
|
|
15
|
+
export function daemonNoFileIdentityProblem(pkg) {
|
|
16
|
+
if (!/^[A-Za-z][A-Za-z0-9]{1,63}$/.test(pkg) || pkg.toLowerCase() === 'root')
|
|
17
|
+
return 'daemon.nofile requires a valid non-root package account';
|
|
18
|
+
}
|
|
19
|
+
export function readNoFile(value, fail) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return;
|
|
22
|
+
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1024 && value <= 1048576)
|
|
23
|
+
return value;
|
|
24
|
+
fail({ code: 'STANDALONE_DAEMON_NOFILE_INVALID', message: 'daemon.nofile must be an integer from 1024 to 1048576; the daemon always runs as the package account' });
|
|
25
|
+
}
|
|
26
|
+
export function daemonSystemUnitName(pkg) { return `pkg-${pkg}-daemon.service`; }
|
|
27
|
+
export function renderDaemonSystemUnit(pkg, nofile) {
|
|
28
|
+
const problem = daemonNoFileIdentityProblem(pkg);
|
|
29
|
+
if (problem)
|
|
30
|
+
throw new StandaloneBuildError('STANDALONE_DAEMON_NOFILE_INVALID', problem);
|
|
31
|
+
return `[Unit]
|
|
32
|
+
Description=${pkg} daemon
|
|
33
|
+
|
|
34
|
+
[Service]
|
|
35
|
+
Type=oneshot
|
|
36
|
+
RemainAfterExit=yes
|
|
37
|
+
User=${pkg}
|
|
38
|
+
Group=${pkg}
|
|
39
|
+
Slice=${pkg}.slice
|
|
40
|
+
LimitNOFILE=${nofile}
|
|
41
|
+
NoNewPrivileges=yes
|
|
42
|
+
UMask=0077
|
|
43
|
+
ExecStart=/var/packages/${pkg}/target/daemon/control start /var/packages/${pkg}/target /var/packages/${pkg}/var
|
|
44
|
+
ExecStop=/var/packages/${pkg}/target/daemon/control stop /var/packages/${pkg}/target /var/packages/${pkg}/var
|
|
45
|
+
KillMode=control-group
|
|
46
|
+
# The SDK controller owns the validated operation deadlines
|
|
47
|
+
TimeoutStartSec=0
|
|
48
|
+
TimeoutStopSec=0
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
/** One fixed dispatch layer covers every native lifecycle composition, including
|
|
52
|
+
* delegated jobs and rootOps. The unit itself calls the SDK directly. */
|
|
53
|
+
export function renderNoFileLifecycle(manifest, script) {
|
|
54
|
+
if (manifest.daemon?.nofile === undefined)
|
|
55
|
+
return script;
|
|
56
|
+
const pkg = manifest.package, unit = daemonSystemUnitName(pkg);
|
|
57
|
+
const controls = [`"/var/packages/${pkg}/target/daemon/control"`, `"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control"`];
|
|
58
|
+
if (!controls.some(c => script.includes(c)))
|
|
59
|
+
return script;
|
|
60
|
+
for (const control of controls)
|
|
61
|
+
script = script.replaceAll(`exec ${control}`, 'synopkgland_daemon_control').replaceAll(control, 'synopkgland_daemon_control');
|
|
62
|
+
const dispatch = `synopkgland_daemon_control() {
|
|
63
|
+
synopkgland_daemon_action="$1"
|
|
64
|
+
shift
|
|
65
|
+
case "$synopkgland_daemon_action" in
|
|
66
|
+
start|restart) /usr/syno/bin/synosystemctl "$synopkgland_daemon_action" ${unit} ;;
|
|
67
|
+
stop)
|
|
68
|
+
if [ -f /usr/local/lib/systemd/system/${unit} ]; then
|
|
69
|
+
/usr/syno/bin/synosystemctl stop ${unit} || return $?
|
|
70
|
+
fi
|
|
71
|
+
"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" stop "$@" ;;
|
|
72
|
+
uninstall)
|
|
73
|
+
if [ -f /usr/local/lib/systemd/system/${unit} ]; then
|
|
74
|
+
/usr/syno/bin/synosystemctl stop ${unit} || return $?
|
|
75
|
+
fi
|
|
76
|
+
"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" uninstall "$@" ;;
|
|
77
|
+
*) "\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" "$synopkgland_daemon_action" "$@" ;;
|
|
78
|
+
esac
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
return script.replace('#!/bin/sh\n', () => `#!/bin/sh\n${dispatch}`);
|
|
82
|
+
}
|
|
83
|
+
/** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
|
|
84
|
+
export function requireDaemonNoFileSource(dir, sdk, nofile) {
|
|
85
|
+
if (nofile === undefined)
|
|
86
|
+
return;
|
|
87
|
+
let main = '', linux = '';
|
|
88
|
+
try {
|
|
89
|
+
main = readFileSync(join(dir, 'daemonctl/main.go'), 'utf8');
|
|
90
|
+
linux = readFileSync(join(dir, 'daemonctl/nofile_linux.go'), 'utf8');
|
|
91
|
+
}
|
|
92
|
+
catch { /* Fail closed below. */ }
|
|
93
|
+
const problem = daemonNoFileSdkProblem(sdk);
|
|
94
|
+
if (problem || !/\bNoFile\s+int\s+`json:"nofile,omitempty"`/.test(main) || !main.includes('validateNoFile(cfg.NoFile)') || !main.includes('applyNoFile(c.NoFile)') || !linux.includes('func applyNoFile('))
|
|
95
|
+
throw new StandaloneBuildError('STANDALONE_DAEMON_NOFILE_SDK_REQUIRED', problem ?? `daemon.nofile requires matching SDK ${DAEMON_NOFILE_MIN_SDK} source with validated non-root NOFILE inheritance; update the SDK pin or development override before building`);
|
|
96
|
+
}
|
|
@@ -5,6 +5,8 @@ import { type DaemonRestart } from "./daemon-restart.js";
|
|
|
5
5
|
import type { CommandRunner } from "./build.js";
|
|
6
6
|
import type { StandaloneError, StandaloneManifest } from "./manifest.js";
|
|
7
7
|
export interface Daemon {
|
|
8
|
+
/** Acquired system-unit file descriptor limit; all processes stay non-root. */
|
|
9
|
+
nofile?: number;
|
|
8
10
|
/** Optional bounded recovery; omission uses the SDK controller default. SDK 0.26.0 or later. */
|
|
9
11
|
restart?: DaemonRestart;
|
|
10
12
|
/** Fixed foreground executable relative to daemon/payload; empty for a backend daemon. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readNoFile, requireDaemonNoFileSource } from "./daemon-nofile.js";
|
|
1
2
|
import { portDefaults } from "./install-ports.js";
|
|
2
3
|
import { operationBudgetSeconds, runtimeBudgetSdkSupported } from "../runtime/runtime-budgets.js";
|
|
3
4
|
import { goChildEnv } from "../runtime/go-env.js";
|
|
@@ -45,6 +46,7 @@ const fields = new Set([
|
|
|
45
46
|
"node",
|
|
46
47
|
"ingress",
|
|
47
48
|
"restart",
|
|
49
|
+
"nofile",
|
|
48
50
|
]);
|
|
49
51
|
const record = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
50
52
|
/** A fixed argv or env value: only the package's own directories expand. */
|
|
@@ -120,6 +122,9 @@ export function readDaemon(value, root, arches, fail, packageId) {
|
|
|
120
122
|
const timeouts = readLifecycleTimeouts(value.timeouts, fail);
|
|
121
123
|
if (!timeouts)
|
|
122
124
|
return undefined;
|
|
125
|
+
const nofile = readNoFile(value.nofile, fail);
|
|
126
|
+
if (value.nofile !== undefined && nofile === undefined)
|
|
127
|
+
return undefined;
|
|
123
128
|
const restart = readDaemonRestart(value.restart, fail);
|
|
124
129
|
if (value.restart !== undefined && !restart)
|
|
125
130
|
return undefined;
|
|
@@ -146,6 +151,7 @@ export function readDaemon(value, root, arches, fail, packageId) {
|
|
|
146
151
|
...(node ? { node } : {}),
|
|
147
152
|
...(ingress ? { ingress } : {}),
|
|
148
153
|
...(restart ? { restart } : {}),
|
|
154
|
+
...(nofile !== undefined ? { nofile } : {}),
|
|
149
155
|
};
|
|
150
156
|
}
|
|
151
157
|
function readDaemonNode(value, fail) {
|
|
@@ -182,6 +188,7 @@ export function daemonConfig(manifest) {
|
|
|
182
188
|
: runnableDaemon(manifest.package, manifest.daemon);
|
|
183
189
|
return (JSON.stringify({
|
|
184
190
|
package: manifest.package,
|
|
191
|
+
...(manifest.daemon?.nofile !== undefined ? { nofile: manifest.daemon.nofile } : {}),
|
|
185
192
|
...(!manifest.compose && manifest.daemon?.backend ? { backend: true } : { exec }),
|
|
186
193
|
args,
|
|
187
194
|
...(uninstall_args ? { uninstall_args } : {}),
|
|
@@ -231,6 +238,7 @@ export async function buildDaemonControl(manifest, arch, work, run) {
|
|
|
231
238
|
const sdk = daemonSdkVersion(manifest);
|
|
232
239
|
const source = runtimeBudgetSource(sdkSource(sdk).goDir, manifest);
|
|
233
240
|
requireDaemonRestartSource(source, sdk, manifest.daemon?.restart);
|
|
241
|
+
requireDaemonNoFileSource(source, sdk, manifest.daemon?.nofile);
|
|
234
242
|
requireBackendDaemonSource(source, manifest.daemon);
|
|
235
243
|
const result = await run("go", [
|
|
236
244
|
"build",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readNoFile, daemonSystemUnitName, renderDaemonSystemUnit, daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from "./daemon-nofile.js";
|
|
1
2
|
import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
2
3
|
import { renderGatewayIngressCheck } from './native-gateway.js';
|
|
3
4
|
import { portDefaults, portInstallSteps } from "./install-ports.js";
|
|
@@ -153,7 +154,15 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
const dependencies = inspectPackageDependencies(metadata.dependencies, findings);
|
|
156
|
-
const
|
|
157
|
+
const daemonNoFile = readNoFile(metadata.daemon_nofile, e => findings.push(e.message));
|
|
158
|
+
if (daemonNoFile !== undefined) {
|
|
159
|
+
const problem = daemonNoFileSdkProblem(typeof metadata.daemon_sdk === 'string' ? metadata.daemon_sdk : 'unknown');
|
|
160
|
+
if (problem)
|
|
161
|
+
findings.push(problem);
|
|
162
|
+
}
|
|
163
|
+
if (metadata.daemon_nofile !== undefined && (!paths.has("daemon/control") || metadata.compose !== undefined))
|
|
164
|
+
findings.push("daemon.nofile requires a native daemon controller");
|
|
165
|
+
const daemonRestart = recoverDaemonRestart(metadata.daemon_restart, metadata.daemon_restart === undefined && daemonNoFile !== undefined ? undefined : metadata.daemon_sdk, findings);
|
|
157
166
|
await inspectModuleUi(dir, paths, metadata.ui_module, findings);
|
|
158
167
|
if (metadata.daemon_restart !== undefined && (metadata.compose !== undefined || !paths.has("daemon/control")))
|
|
159
168
|
findings.push("DAEMON_RESTART_INVALID daemon restart requires a native daemon controller, without Compose supervision");
|
|
@@ -228,7 +237,7 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
228
237
|
!isDsmAtLeast(info.os_min_ver, PORTAL_MIN_DSM)) {
|
|
229
238
|
findings.push(`INFO os_min_ver "${info.os_min_ver}" is below the DSM ${PORTAL_MIN_DSM} a portal needs; ${PORTAL_MIN_DSM_REASON}`);
|
|
230
239
|
}
|
|
231
|
-
checkConf(dir, findings, kind, background, sharedFolder, info.package, portal, combined?.compose, nativeGateway, info.os_min_ver, daemonIngress, Boolean(metadata.installPorts));
|
|
240
|
+
checkConf(dir, findings, kind, background, sharedFolder, info.package, portal, combined?.compose, nativeGateway, info.os_min_ver, daemonIngress, Boolean(metadata.installPorts), daemonNoFile);
|
|
232
241
|
checkScripts(dir, findings);
|
|
233
242
|
checkUninstall(dir, findings);
|
|
234
243
|
if (kind === "container")
|
|
@@ -258,7 +267,7 @@ export async function inspectSpk(spkPath, expectedKind) {
|
|
|
258
267
|
if (standalone && portal)
|
|
259
268
|
findings.push(...inspectPortalInfo(info, hasExecutor));
|
|
260
269
|
const daemon = standalone
|
|
261
|
-
? await checkDaemon(dir, info, paths, payload, findings, hasExecutor, background, combined, nativeGateway, uninstallHook?.uninstall, { ingress: daemonIngress, node: daemonNode, restart: daemonRestart, installPorts: Boolean(metadata.installPorts) })
|
|
270
|
+
? await checkDaemon(dir, info, paths, payload, findings, hasExecutor, background, combined, nativeGateway, uninstallHook?.uninstall, { ingress: daemonIngress, node: daemonNode, restart: daemonRestart, nofile: daemonNoFile, installPorts: Boolean(metadata.installPorts) })
|
|
262
271
|
: undefined;
|
|
263
272
|
if (background)
|
|
264
273
|
checkBackground(dir, info, payload, findings, hasExecutor, daemon, kind !== "native-go", metadata.lifecycleTimeouts, nativeGateway, Boolean(metadata.installPorts));
|
|
@@ -990,9 +999,12 @@ async function checkDaemon(dir, info, paths, payload, findings, executor, backgr
|
|
|
990
999
|
"operation_seconds",
|
|
991
1000
|
"uninstall_args",
|
|
992
1001
|
"restart",
|
|
1002
|
+
"nofile",
|
|
993
1003
|
...(combined ? ["network"] : []),
|
|
994
1004
|
].includes(key)))
|
|
995
1005
|
throw new Error("package/config mismatch");
|
|
1006
|
+
if (config.nofile !== extras.nofile)
|
|
1007
|
+
throw new Error("daemon nofile differs from its build declaration");
|
|
996
1008
|
if (!isDeepStrictEqual(config.restart, extras.restart))
|
|
997
1009
|
throw new Error("daemon restart differs from its build declaration");
|
|
998
1010
|
const backend = config.backend === true;
|
|
@@ -1005,6 +1017,7 @@ async function checkDaemon(dir, info, paths, payload, findings, executor, backgr
|
|
|
1005
1017
|
env: config.env,
|
|
1006
1018
|
timeouts: config.timeouts,
|
|
1007
1019
|
restart: config.restart,
|
|
1020
|
+
nofile: config.nofile,
|
|
1008
1021
|
targets: { x86_64: "payload" },
|
|
1009
1022
|
}, dir, ["x86_64"], () => { }, info.package);
|
|
1010
1023
|
if (!daemon)
|
|
@@ -1334,7 +1347,7 @@ async function recoverDaemonIngress(dir, value, info, paths, findings) {
|
|
|
1334
1347
|
return undefined;
|
|
1335
1348
|
}
|
|
1336
1349
|
}
|
|
1337
|
-
function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, compose, nativeGateway, osMinVer, daemonIngress, installPorts = false) {
|
|
1350
|
+
function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, compose, nativeGateway, osMinVer, daemonIngress, installPorts = false, nofile) {
|
|
1338
1351
|
const confDir = join(dir, "conf");
|
|
1339
1352
|
const entries = existsSync(confDir) ? readdirSync(confDir) : [];
|
|
1340
1353
|
const nativeResource = kind !== "container"
|
|
@@ -1359,10 +1372,26 @@ function checkConf(dir, findings, kind, background, sharedFolder, pkg, portal, c
|
|
|
1359
1372
|
if (name !== "privilege" &&
|
|
1360
1373
|
!(kind === "container" && name === "resource") &&
|
|
1361
1374
|
!(nativeResource !== undefined && name === "resource") &&
|
|
1362
|
-
!(background && name === "systemd")) {
|
|
1375
|
+
!((background || nofile !== undefined) && name === "systemd")) {
|
|
1363
1376
|
findings.push(`conf/${name} registers an extra resource with DSM; a Standalone Package does not produce it`);
|
|
1364
1377
|
}
|
|
1365
1378
|
}
|
|
1379
|
+
if (nofile !== undefined && pkg) {
|
|
1380
|
+
if (!osMinVer || !isDsmAtLeast(osMinVer, DAEMON_NOFILE_MIN_DSM))
|
|
1381
|
+
findings.push(`daemon.nofile requires DSM ${DAEMON_NOFILE_MIN_DSM} or later`);
|
|
1382
|
+
const unit = daemonSystemUnitName(pkg);
|
|
1383
|
+
const identityProblem = daemonNoFileIdentityProblem(pkg);
|
|
1384
|
+
if (identityProblem)
|
|
1385
|
+
findings.push(identityProblem);
|
|
1386
|
+
else if (readOptional(join(confDir, "systemd", unit)) !== renderDaemonSystemUnit(pkg, nofile))
|
|
1387
|
+
findings.push("daemon NOFILE system unit must match the fixed package account, limit and lifecycle");
|
|
1388
|
+
}
|
|
1389
|
+
if (background || nofile !== undefined) {
|
|
1390
|
+
const expected = [...(background && pkg ? [backgroundUnitName(pkg)] : []), ...(nofile !== undefined && pkg ? [daemonSystemUnitName(pkg)] : [])].sort();
|
|
1391
|
+
const actual = existsSync(join(confDir, "systemd")) ? readdirSync(join(confDir, "systemd")).sort() : [];
|
|
1392
|
+
if (!isDeepStrictEqual(actual, expected))
|
|
1393
|
+
findings.push("conf/systemd contains missing or extra package units");
|
|
1394
|
+
}
|
|
1366
1395
|
if (kind === "container") {
|
|
1367
1396
|
try {
|
|
1368
1397
|
const resource = JSON.parse(readFileSync(join(confDir, "resource"), "utf8"));
|
|
@@ -1423,8 +1452,7 @@ function checkBackground(dir, info, payload, findings, executor, daemon, bridge
|
|
|
1423
1452
|
? readdirSync(join(dir, BACKGROUND_UNIT_DIR))
|
|
1424
1453
|
: [];
|
|
1425
1454
|
const unit = backgroundUnitName(pkg);
|
|
1426
|
-
if (units.
|
|
1427
|
-
units[0] !== unit ||
|
|
1455
|
+
if (!isDeepStrictEqual(units.sort(), [unit, ...(daemon?.nofile !== undefined ? [daemonSystemUnitName(pkg)] : [])].sort()) ||
|
|
1428
1456
|
read(`${BACKGROUND_UNIT_DIR}/${unit}`) !==
|
|
1429
1457
|
renderBackgroundUnit(pkg, bridge ? BRIDGE_WORKER_ARGS : [], daemon?.timeouts.stop ?? lifecycleTimeouts?.stop ?? 30)) {
|
|
1430
1458
|
findings.push(`${BACKGROUND_UNIT_DIR} must contain only the fixed ${unit} (runs as the package account, no User=, no root)`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renderNoFileLifecycle } from "./daemon-nofile.js";
|
|
1
2
|
import { renderGatewayIngressCheck } from './native-gateway.js';
|
|
2
3
|
import { renderSettingsHook } from './install-settings.js';
|
|
3
4
|
import { renderComposeRetainedData } from "../build-spk/compose-retained-data.js";
|
|
@@ -15,7 +16,7 @@ import { composeAppScript } from "./app-scripts.js";
|
|
|
15
16
|
const UNINSTALL_ONLY = '[ "${SYNOPKG_PKG_STATUS:-}" = UPGRADE ] || synopkgland_uninstall_hook\n';
|
|
16
17
|
/** Package-account lifecycle hooks for CGI, daemon and background packages. */
|
|
17
18
|
export function renderStandaloneScript(name, manifest) {
|
|
18
|
-
const script = renderStandaloneScriptInternal(name, manifest);
|
|
19
|
+
const script = renderNoFileLifecycle(manifest, renderStandaloneScriptInternal(name, manifest));
|
|
19
20
|
const prefix = renderStandaloneScriptPrefix(name, manifest);
|
|
20
21
|
const sdk = prefix ? script.replace('#!/bin/sh\n', () => '#!/bin/sh\n' + prefix) : script;
|
|
21
22
|
return manifest.appScripts?.some((app) => app === name)
|
|
@@ -95,6 +95,8 @@ export interface StandaloneManifest {
|
|
|
95
95
|
};
|
|
96
96
|
daemon?: Daemon;
|
|
97
97
|
lifecycleTimeouts?: Daemon["timeouts"];
|
|
98
|
+
/** Author-supplied overrides, before daemon supervision defaults are filled. */
|
|
99
|
+
declaredLifecycleTimeouts?: Partial<Daemon["timeouts"]>;
|
|
98
100
|
/** `identity_gateway`: signs DSM users in to the daemon's own web UI. */
|
|
99
101
|
identityGateway?: IdentityGateway;
|
|
100
102
|
compose?: ComposeApp;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from './daemon-nofile.js';
|
|
1
2
|
import { readRegistry, registryFile } from '../ctl/registry.js';
|
|
2
3
|
import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
3
4
|
import { nativeGatewaySdk } from "./native-gateway.js";
|
|
@@ -347,6 +348,16 @@ function readManifest(raw, c) {
|
|
|
347
348
|
if (problem)
|
|
348
349
|
c.fail("STANDALONE_DAEMON_INGRESS_MIN_DSM", problem);
|
|
349
350
|
}
|
|
351
|
+
if (daemon?.nofile !== undefined && backend) {
|
|
352
|
+
if (osMinVer && !isDsmAtLeast(osMinVer, DAEMON_NOFILE_MIN_DSM))
|
|
353
|
+
c.fail('STANDALONE_DAEMON_NOFILE_DSM_REQUIRED', `daemon.nofile requires DSM ${DAEMON_NOFILE_MIN_DSM} or later; the target is never raised automatically`);
|
|
354
|
+
const problem = daemonNoFileSdkProblem(daemonSdkVersion({ backend, identityGateway }));
|
|
355
|
+
if (problem)
|
|
356
|
+
c.fail('STANDALONE_DAEMON_NOFILE_SDK_REQUIRED', problem);
|
|
357
|
+
const identityProblem = daemonNoFileIdentityProblem(packageId ?? '');
|
|
358
|
+
if (identityProblem)
|
|
359
|
+
c.fail('STANDALONE_DAEMON_NOFILE_INVALID', identityProblem);
|
|
360
|
+
}
|
|
350
361
|
if (daemon?.restart && backend) {
|
|
351
362
|
const problem = daemonRestartSdkProblem(daemonSdkVersion({ backend, identityGateway }));
|
|
352
363
|
if (problem)
|
|
@@ -596,6 +607,8 @@ function readManifest(raw, c) {
|
|
|
596
607
|
...(daemon ? { daemon } : {}),
|
|
597
608
|
...(dependencies ? { dependencies } : {}),
|
|
598
609
|
...(lifecycleTimeouts ? { lifecycleTimeouts } : {}),
|
|
610
|
+
declaredLifecycleTimeouts: isRecord(raw.daemon) && isRecord(raw.daemon.timeouts)
|
|
611
|
+
? { ...raw.daemon.timeouts } : {},
|
|
599
612
|
...(identityGateway ? { identityGateway } : {}),
|
|
600
613
|
...(compose ? { compose } : {}),
|
|
601
614
|
...(uninstall ? { uninstall } : {}),
|
package/dist/standalone/spk.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { daemonSystemUnitName, renderDaemonSystemUnit } from "./daemon-nofile.js";
|
|
1
2
|
import { gatewayIngressOwnershipSupported } from './gateway-ingress.js';
|
|
2
3
|
import { portDefaults, portInstallSteps, writePortPayload } from "./install-ports.js";
|
|
3
4
|
import { packageDependencies, dependencyInfo } from "./package-dependencies.js";
|
|
@@ -272,7 +273,9 @@ export async function assembleStandaloneSpk(options) {
|
|
|
272
273
|
...(nativeGatewaySupported(manifest) ? { native_gateway: { sdk: manifest.identityGateway.sdk, listen: manifest.identityGateway.listen, ...(manifest.identityGateway.ingress ? { ingress: manifest.identityGateway.ingress } : {}) } } : {}),
|
|
273
274
|
...(manifest.daemon?.ingress ? { daemon_ingress: manifest.daemon.ingress } : {}),
|
|
274
275
|
...(manifest.daemon?.node ? { daemon_node: manifest.daemon.node } : {}),
|
|
275
|
-
...(manifest.daemon?.
|
|
276
|
+
...(manifest.daemon?.nofile !== undefined ? { daemon_nofile: manifest.daemon.nofile } : {}),
|
|
277
|
+
...(manifest.daemon?.restart ? { daemon_restart: manifest.daemon.restart } : {}),
|
|
278
|
+
...(manifest.daemon?.restart || manifest.daemon?.nofile !== undefined ? { daemon_sdk: daemonSdkVersion(manifest) } : {}),
|
|
276
279
|
launch: resolvedSdkLaunch(manifest),
|
|
277
280
|
capabilities: Object.keys(manifest.capabilities).sort(),
|
|
278
281
|
...(manifest.compose
|
|
@@ -299,6 +302,10 @@ export async function assembleStandaloneSpk(options) {
|
|
|
299
302
|
const resource = renderStandaloneResource(manifest, portal);
|
|
300
303
|
if (resource)
|
|
301
304
|
writeFile(join(staging, "conf", "resource"), resource);
|
|
305
|
+
if (manifest.daemon?.nofile !== undefined) {
|
|
306
|
+
mkdirSync(join(staging, "conf/systemd"), { recursive: true });
|
|
307
|
+
writeFile(join(staging, "conf/systemd", daemonSystemUnitName(manifest.package)), renderDaemonSystemUnit(manifest.package, manifest.daemon.nofile));
|
|
308
|
+
}
|
|
302
309
|
if (manifest.capabilities.jobs) {
|
|
303
310
|
mkdirSync(join(staging, BACKGROUND_UNIT_DIR), { recursive: true });
|
|
304
311
|
writeFile(join(staging, BACKGROUND_UNIT_DIR, backgroundUnitName(manifest.package)), renderBackgroundUnit(manifest.package, isBridgeBackend(manifest.backend) ? BRIDGE_WORKER_ARGS : [], manifest.daemon?.timeouts.stop ?? manifest.lifecycleTimeouts?.stop ?? 30));
|
package/dist/validate.js
CHANGED
|
@@ -37,6 +37,12 @@ export function validateProject(project, _options = {}) {
|
|
|
37
37
|
"Correct the schema-2 declaration; see the SDK Compose support matrix.",
|
|
38
38
|
})),
|
|
39
39
|
}
|
|
40
|
-
: { ok: true, errors: [], warnings: upstreamAttributionWarnings(project.root)
|
|
40
|
+
: { ok: true, errors: [], warnings: [...upstreamAttributionWarnings(project.root),
|
|
41
|
+
...(loaded.ok && 'ctl' in loaded.manifest && loaded.manifest.ctl?.enabled && !loaded.manifest.ctl.registry ? [{
|
|
42
|
+
code: 'CTL_LEGACY_COMMANDS_DEPRECATED', severity: 'warning',
|
|
43
|
+
span: { file, line: 1, column: 1 },
|
|
44
|
+
message: 'Legacy ctl.commands is deprecated and remains supported for check and build.',
|
|
45
|
+
suggestion: 'Plan migration to ctl.registry when ready; this warning does not block existing Apps.',
|
|
46
|
+
}] : [])] };
|
|
41
47
|
}
|
|
42
48
|
export { findProjectRoot } from "./discovery.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synopackageland/cli",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.4",
|
|
4
4
|
"description": "Syno Package Land Developer Kit CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
"test:glossary": "node --test scripts/test/glossary-drift.test.mjs",
|
|
25
25
|
"test:scripts": "node --test scripts/test/gate.test.mjs scripts/test/release.test.mjs scripts/test/pack-docker.test.mjs scripts/test/npm-pack.test.mjs scripts/test/executor-bump.test.mjs scripts/test/smoke-exports.test.mjs scripts/test/parallel.test.mjs scripts/test/scaffold-matrix.test.mjs scripts/test/frontend-deps.test.mjs scripts/test/docker-gate.test.mjs scripts/test/gate-plan.test.mjs scripts/test/gates.test.mjs && python3 scripts/test/npm-publish.py",
|
|
26
26
|
"gates": "bash scripts/ci/gates.sh",
|
|
27
|
-
"gates:fast": "bash scripts/ci/gates.sh
|
|
28
|
-
"prepublishOnly": "npm run build"
|
|
27
|
+
"gates:fast": "bash scripts/ci/gates.sh",
|
|
28
|
+
"prepublishOnly": "npm run build",
|
|
29
|
+
"gates:full": "bash scripts/ci/gates.sh --full",
|
|
30
|
+
"test:basic": "node --import tsx --test test/schema.test.ts test/standalone-manifest.test.ts test/native-arch.test.ts test/archive-inventory.test.ts"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
33
|
"@napi-rs/keyring": "^2.1.1",
|
|
@@ -430,7 +430,8 @@
|
|
|
430
430
|
"timeoutMs": {
|
|
431
431
|
"type": "integer",
|
|
432
432
|
"minimum": 10,
|
|
433
|
-
"maximum": 3600000
|
|
433
|
+
"maximum": 3600000,
|
|
434
|
+
"description": "Optional per-request allowance; omission uses the shared operation budget, with polling until completion or cancellation and no total elapsed limit"
|
|
434
435
|
}
|
|
435
436
|
},
|
|
436
437
|
"required": [
|
|
@@ -442,8 +443,7 @@
|
|
|
442
443
|
"state",
|
|
443
444
|
"done",
|
|
444
445
|
"failed",
|
|
445
|
-
"intervalMs"
|
|
446
|
-
"timeoutMs"
|
|
446
|
+
"intervalMs"
|
|
447
447
|
]
|
|
448
448
|
}
|
|
449
449
|
]
|
package/skills/SKILL.md
CHANGED
|
@@ -356,3 +356,11 @@ Use opt-in `identity_gateway.ingress: {path: /my-app/}` for
|
|
|
356
356
|
upstreams with a hardcoded base path. Read [reference/identity-gateway.md](reference/identity-gateway.md)
|
|
357
357
|
for reserved paths, install-time ownership checks and unchanged auth policy.
|
|
358
358
|
Apps requiring `/` cannot use ingress.
|
|
359
|
+
|
|
360
|
+
## Maintaining this CLI
|
|
361
|
+
|
|
362
|
+
For CLI releases, `npm run gates` runs basic build/typecheck, core unit checks,
|
|
363
|
+
npm pack and tarball content checks. Run `npm run gates:full` only when the user
|
|
364
|
+
explicitly requests extended matrices and integration checks. Publishing does
|
|
365
|
+
not require a full-gate result. Application fixture acceptance remains scoped
|
|
366
|
+
to the application task's authorization.
|
package/skills/reference/ctl.md
CHANGED
|
@@ -121,10 +121,15 @@ actual upstream token/header/API-password mapping and shared-account semantics.
|
|
|
121
121
|
|
|
122
122
|
## Designing commands for AI
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
New Apps have one `synopkgland.api` v2 operation spec (`operations.json`; OSS
|
|
125
125
|
wrappers keep it under `synology/`). Set `ctl: {enabled: true, registry:
|
|
126
126
|
operations.json}` relative to the packaging manifest. Do not maintain a second
|
|
127
|
-
list of summaries or command schemas.
|
|
127
|
+
list of summaries or command schemas. Existing v1 `ctl.commands` Apps continue
|
|
128
|
+
passing check and build; check emits one nonblocking deprecation warning.
|
|
129
|
+
Migrate them deliberately, keeping their registered methods and permissions.
|
|
130
|
+
App-authored registry files and authenticated discovery responses have no byte-size
|
|
131
|
+
cap. Runtime description/registry loading also needs the matching SDK metadata fix;
|
|
132
|
+
ordinary operation input limits continue to apply.
|
|
128
133
|
Each real method has one English `summary`, `paramsSchema`, `resultSchema`,
|
|
129
134
|
`effect`, `permission`, fixed `flow`, `cli` path and required `ai` class:
|
|
130
135
|
|
|
@@ -121,7 +121,7 @@ allowance with `KillMode=control-group`.
|
|
|
121
121
|
|
|
122
122
|
`backend.timeout_seconds` owns request/operation work. Binary and Compose Apps
|
|
123
123
|
without a CGI request setting can enlarge the shared operation allowance through
|
|
124
|
-
`daemon.timeouts.status` above
|
|
124
|
+
`daemon.timeouts.status` above the SDK shared operation default. Generated gateway and
|
|
125
125
|
approved executor configurations inherit it; nested calls use remaining time and
|
|
126
126
|
leave response reserve. Budget changes in the protected policy require renewed
|
|
127
127
|
approval and do not change token/session/grant lifetimes.
|
|
@@ -133,3 +133,36 @@ continue. The executor helper's JSON state distinguishes `accepted`,
|
|
|
133
133
|
request and does not prove cleanup finished. Unconfirmed cleanup retains protected
|
|
134
134
|
state for a later retry. DSM's outer install/uninstall deadline is not established
|
|
135
135
|
by these settings.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Daemon file descriptor budget
|
|
139
|
+
|
|
140
|
+
Native daemon Apps may opt in with `daemon.nofile: 32768`. The value must be an
|
|
141
|
+
integer from 1024 to 1048576; omission keeps the legacy controller path. This
|
|
142
|
+
requires DSM 7.0-40761 or later and SDK 0.49.5 or later, including an explicit Go App SDK pin or gateway
|
|
143
|
+
pin. CLI 0.48.3 retains the SDK 0.49.5 default introduced in 0.48.2. Check and
|
|
144
|
+
build reject older pins; build also verifies matching controller sources.
|
|
145
|
+
|
|
146
|
+
The CLI generates only `conf/systemd/pkg-<package>-daemon.service`. DSM acquires
|
|
147
|
+
this fixed system unit directly; it needs no `systemd-user-unit` resource
|
|
148
|
+
(that worker is for `pkguser-*` user units). See the
|
|
149
|
+
[official acquired-unit contract](https://help.synology.com/developer-guide/resource_acquisition/systemd_user_unit.html). `LimitNOFILE` sets its inherited soft/hard budget;
|
|
150
|
+
`User` and `Group` stay the package account, with `NoNewPrivileges=yes` and
|
|
151
|
+
`KillMode=control-group`. A root package identity is refused. Apps cannot supply
|
|
152
|
+
arbitrary units, identities, commands or root lifecycle work through this field.
|
|
153
|
+
The SDK daemon controller verifies the inherited hard limit and raises only the
|
|
154
|
+
soft limit before launching its non-root worker; insufficient inheritance fails
|
|
155
|
+
with `DAEMON_NOFILE_INSUFFICIENT`.
|
|
156
|
+
|
|
157
|
+
Generated start/restart uses the acquired unit; status stays on the SDK
|
|
158
|
+
controller. Stop also calls the idempotent SDK stop to cover an upgrade from a
|
|
159
|
+
legacy controller, including when a new unit file is already present. Uninstall
|
|
160
|
+
stops the unit then invokes the existing SDK uninstall path. The unit leaves
|
|
161
|
+
outer systemd start/stop timeouts disabled so the SDK's existing validated
|
|
162
|
+
`daemon.timeouts` remain the single work deadline. Inspect rejects a missing,
|
|
163
|
+
extra or changed unit and mismatched metadata/controller configuration.
|
|
164
|
+
|
|
165
|
+
After publishing and deploying an opted-in package, read the actual worker UID
|
|
166
|
+
and soft/hard limits after upgrade/restart. Generated files and local SPK tests
|
|
167
|
+
alone do not establish DSM acquisition, inherited worker limits or full lifecycle
|
|
168
|
+
acceptance on a NAS.
|