MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / buildSystemdUnit

Function buildSystemdUnit

packages/server/src/svc/systemd-unit.ts:29–70  ·  view source on GitHub ↗
(input: BuildSystemdUnitInput)

Source from the content-addressed store, hash-verified

27
28
29export function buildSystemdUnit(input: BuildSystemdUnitInput): string {
30 const execStart = input.programArguments.map(systemdEscapeArg).join(' ');
31 const description = (input.description ?? 'Kimi Code local server').trim();
32 assertNoLineBreaks(description, 'Systemd Description');
33
34 const workingDirLine = input.workingDirectory
35 ? `WorkingDirectory=${systemdEscapeArg(input.workingDirectory)}`
36 : null;
37
38 const envLines = input.environment
39 ? Object.entries(input.environment).map(([k, v]) => {
40 assertNoLineBreaks(k, 'Systemd environment variable names');
41 assertNoLineBreaks(v, 'Systemd environment variable values');
42 return `Environment=${systemdEscapeArg(`${k}=${v}`)}`;
43 })
44 : [];
45
46 const lines = [
47 '[Unit]',
48 `Description=${description}`,
49 'After=network-online.target',
50 'Wants=network-online.target',
51 'StartLimitBurst=5',
52 'StartLimitIntervalSec=60',
53 '',
54 '[Service]',
55 'Type=simple',
56 `ExecStart=${execStart}`,
57 'Restart=always',
58 'RestartSec=5',
59 'TimeoutStopSec=30',
60 'TimeoutStartSec=30',
61 'KillMode=control-group',
62 workingDirLine,
63 ...envLines,
64 '',
65 '[Install]',
66 'WantedBy=default.target',
67 '',
68 ];
69 return lines.filter((line): line is string => line !== null).join('\n');
70}
71
72export function parseSystemctlShow(output: string): Record<string, string> {
73 const result: Record<string, string> = {};

Callers 2

systemd.test.tsFile · 0.90
writeUnitFunction · 0.90

Calls 2

assertNoLineBreaksFunction · 0.85
systemdEscapeArgFunction · 0.85

Tested by

no test coverage detected