@scrylog/cli 0.1.2 → 0.1.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/package.json +1 -1
- package/src/service/manager.ts +34 -1
package/package.json
CHANGED
package/src/service/manager.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
3
4
|
import { getResolvedConfigPath } from "../shared/config";
|
|
4
5
|
import {
|
|
5
6
|
ensureParentDir,
|
|
@@ -63,6 +64,7 @@ export function resolveDaemonExec(configPath?: string, daemonPath = whichCommand
|
|
|
63
64
|
export function renderLaunchAgentPlist(configPath?: string): string {
|
|
64
65
|
const args = resolveDaemonExec(configPath);
|
|
65
66
|
const programArguments = args.map((arg) => ` <string>${xmlEscape(arg)}</string>`).join("\n");
|
|
67
|
+
const path = resolveServicePath(args);
|
|
66
68
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
67
69
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
68
70
|
<plist version="1.0">
|
|
@@ -73,6 +75,11 @@ export function renderLaunchAgentPlist(configPath?: string): string {
|
|
|
73
75
|
<array>
|
|
74
76
|
${programArguments}
|
|
75
77
|
</array>
|
|
78
|
+
<key>EnvironmentVariables</key>
|
|
79
|
+
<dict>
|
|
80
|
+
<key>PATH</key>
|
|
81
|
+
<string>${xmlEscape(path)}</string>
|
|
82
|
+
</dict>
|
|
76
83
|
<key>RunAtLoad</key>
|
|
77
84
|
<true/>
|
|
78
85
|
<key>KeepAlive</key>
|
|
@@ -84,11 +91,13 @@ ${programArguments}
|
|
|
84
91
|
|
|
85
92
|
export function renderSystemdUserUnit(configPath?: string): string {
|
|
86
93
|
const args = resolveDaemonExec(configPath);
|
|
94
|
+
const path = resolveServicePath(args);
|
|
87
95
|
return `[Unit]
|
|
88
96
|
Description=scrylog daemon
|
|
89
97
|
After=default.target
|
|
90
98
|
|
|
91
99
|
[Service]
|
|
100
|
+
Environment="PATH=${path}"
|
|
92
101
|
ExecStart=${args.map(shellQuote).join(" ")}
|
|
93
102
|
Restart=on-failure
|
|
94
103
|
RestartSec=3
|
|
@@ -241,6 +250,30 @@ function shellQuote(value: string): string {
|
|
|
241
250
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
242
251
|
}
|
|
243
252
|
|
|
253
|
+
function resolveServicePath(args: string[]): string {
|
|
254
|
+
const commandPath = args[0];
|
|
255
|
+
const candidates = [
|
|
256
|
+
commandPath && isAbsolute(commandPath) ? dirname(commandPath) : undefined,
|
|
257
|
+
isAbsolute(process.execPath) ? dirname(process.execPath) : undefined,
|
|
258
|
+
process.env.PATH,
|
|
259
|
+
join(homedir(), ".bun", "bin"),
|
|
260
|
+
"/opt/homebrew/bin",
|
|
261
|
+
"/usr/local/bin",
|
|
262
|
+
"/usr/bin",
|
|
263
|
+
"/bin",
|
|
264
|
+
"/usr/sbin",
|
|
265
|
+
"/sbin",
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
const paths = new Set<string>();
|
|
269
|
+
for (const candidate of candidates) {
|
|
270
|
+
for (const part of candidate?.split(":") ?? []) {
|
|
271
|
+
if (part) paths.add(part);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return Array.from(paths).join(":");
|
|
275
|
+
}
|
|
276
|
+
|
|
244
277
|
function xmlEscape(value: string): string {
|
|
245
278
|
return value
|
|
246
279
|
.replace(/&/g, "&")
|