@scrylog/cli 0.1.1 → 0.1.2
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 +19 -10
package/package.json
CHANGED
package/src/service/manager.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getSystemdUnitPath,
|
|
10
10
|
getUserUid,
|
|
11
11
|
} from "../shared/paths";
|
|
12
|
-
import { IS_LINUX, IS_MAC, IS_WSL } from "../shared/platform";
|
|
12
|
+
import { IS_LINUX, IS_MAC, IS_WSL, whichCommand } from "../shared/platform";
|
|
13
13
|
import { maybeRunCommand } from "../shared/utils";
|
|
14
14
|
|
|
15
15
|
export interface ServiceStatus {
|
|
@@ -52,13 +52,17 @@ function daemonScriptPath(): string {
|
|
|
52
52
|
return join(import.meta.dir, "../daemon/index.ts");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function
|
|
55
|
+
export function resolveDaemonExec(configPath?: string, daemonPath = whichCommand("scrylogd")): string[] {
|
|
56
56
|
const resolvedConfigPath = getResolvedConfigPath(configPath);
|
|
57
|
+
if (daemonPath) {
|
|
58
|
+
return [daemonPath, "--config", resolvedConfigPath];
|
|
59
|
+
}
|
|
57
60
|
return [process.execPath, "run", daemonScriptPath(), "--config", resolvedConfigPath];
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export function renderLaunchAgentPlist(configPath?: string): string {
|
|
61
|
-
const
|
|
64
|
+
const args = resolveDaemonExec(configPath);
|
|
65
|
+
const programArguments = args.map((arg) => ` <string>${xmlEscape(arg)}</string>`).join("\n");
|
|
62
66
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
63
67
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
64
68
|
<plist version="1.0">
|
|
@@ -67,11 +71,7 @@ export function renderLaunchAgentPlist(configPath?: string): string {
|
|
|
67
71
|
<string>${getServiceLabel()}</string>
|
|
68
72
|
<key>ProgramArguments</key>
|
|
69
73
|
<array>
|
|
70
|
-
|
|
71
|
-
<string>${runArg}</string>
|
|
72
|
-
<string>${scriptPath}</string>
|
|
73
|
-
<string>${configFlag}</string>
|
|
74
|
-
<string>${resolvedConfigPath}</string>
|
|
74
|
+
${programArguments}
|
|
75
75
|
</array>
|
|
76
76
|
<key>RunAtLoad</key>
|
|
77
77
|
<true/>
|
|
@@ -83,13 +83,13 @@ export function renderLaunchAgentPlist(configPath?: string): string {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export function renderSystemdUserUnit(configPath?: string): string {
|
|
86
|
-
const
|
|
86
|
+
const args = resolveDaemonExec(configPath);
|
|
87
87
|
return `[Unit]
|
|
88
88
|
Description=scrylog daemon
|
|
89
89
|
After=default.target
|
|
90
90
|
|
|
91
91
|
[Service]
|
|
92
|
-
ExecStart=${
|
|
92
|
+
ExecStart=${args.map(shellQuote).join(" ")}
|
|
93
93
|
Restart=on-failure
|
|
94
94
|
RestartSec=3
|
|
95
95
|
|
|
@@ -240,3 +240,12 @@ class UnsupportedServiceManager implements ServiceManager {
|
|
|
240
240
|
function shellQuote(value: string): string {
|
|
241
241
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
242
242
|
}
|
|
243
|
+
|
|
244
|
+
function xmlEscape(value: string): string {
|
|
245
|
+
return value
|
|
246
|
+
.replace(/&/g, "&")
|
|
247
|
+
.replace(/</g, "<")
|
|
248
|
+
.replace(/>/g, ">")
|
|
249
|
+
.replace(/"/g, """)
|
|
250
|
+
.replace(/'/g, "'");
|
|
251
|
+
}
|