abtars 0.1.0-alpha.8 → 0.1.0-alpha.9
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/bundle/abtars-cli.js +1 -1
- package/bundle/daemon-PDOLHGWI.js +278 -0
- package/bundle/daemon-PDOLHGWI.js.map +7 -0
- package/bundle/meta.json +17 -7
- package/package.json +1 -1
package/bundle/abtars-cli.js
CHANGED
|
@@ -1398,7 +1398,7 @@ async function main(argv) {
|
|
|
1398
1398
|
return await startCmd();
|
|
1399
1399
|
}
|
|
1400
1400
|
case "daemon": {
|
|
1401
|
-
const { daemon: daemonCmd } = await import("./daemon-
|
|
1401
|
+
const { daemon: daemonCmd } = await import("./daemon-PDOLHGWI.js");
|
|
1402
1402
|
return await daemonCmd(argv.slice(1));
|
|
1403
1403
|
}
|
|
1404
1404
|
case "logs": {
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __bundleCreateRequire } from 'node:module'; import { fileURLToPath as __bundleFileURLToPath } from 'node:url'; import { dirname as __bundleDirname } from 'node:path'; const require = __bundleCreateRequire(import.meta.url); const __chunk_filename = __bundleFileURLToPath(import.meta.url); const __chunk_dirname = __bundleDirname(__chunk_filename);
|
|
3
|
+
import {
|
|
4
|
+
init_log_and_swallow,
|
|
5
|
+
logAndSwallow
|
|
6
|
+
} from "./chunk-EX2SRTUE.js";
|
|
7
|
+
import "./chunk-2BY6I4P5.js";
|
|
8
|
+
import "./chunk-MJ6PHMOK.js";
|
|
9
|
+
import "./chunk-7K2YZTLD.js";
|
|
10
|
+
|
|
11
|
+
// src/cli/commands/daemon.ts
|
|
12
|
+
init_log_and_swallow();
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join, dirname } from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
function abtarsHome() {
|
|
17
|
+
return process.env["ABTARS_HOME"] ?? join(process.env["HOME"] ?? "", ".abtars");
|
|
18
|
+
}
|
|
19
|
+
function isWSL() {
|
|
20
|
+
try {
|
|
21
|
+
return readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function detectScope() {
|
|
27
|
+
if (existsSync("/etc/systemd/system/abtars.service")) return "system";
|
|
28
|
+
const userUnit = join(process.env["HOME"] ?? "", ".config", "systemd", "user", "abtars-watchdog.service");
|
|
29
|
+
if (existsSync(userUnit)) return "user";
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function unitName(scope) {
|
|
33
|
+
return scope === "user" ? "abtars-watchdog" : "abtars";
|
|
34
|
+
}
|
|
35
|
+
async function daemonInstall() {
|
|
36
|
+
const platform = process.platform;
|
|
37
|
+
const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
38
|
+
if (platform === "linux" && isWSL()) {
|
|
39
|
+
process.stderr.write(`\u2139\uFE0F WSL detected \u2014 ensure systemd is enabled (wsl.conf: [boot] systemd=true)
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
const sudoUser = process.env["SUDO_USER"];
|
|
43
|
+
if (process.getuid?.() !== 0) {
|
|
44
|
+
process.stderr.write(
|
|
45
|
+
`Requires sudo for system-scope service registration.
|
|
46
|
+
Run: sudo -k $(which abtars) daemon install
|
|
47
|
+
`
|
|
48
|
+
);
|
|
49
|
+
return 2;
|
|
50
|
+
}
|
|
51
|
+
if (!sudoUser) {
|
|
52
|
+
process.stderr.write(`Cannot determine target user \u2014 $SUDO_USER is not set.
|
|
53
|
+
`);
|
|
54
|
+
return 2;
|
|
55
|
+
}
|
|
56
|
+
const { execSync: execSyncHome } = await import("node:child_process");
|
|
57
|
+
const userHome = execSyncHome(`eval echo ~${sudoUser}`, { encoding: "utf-8" }).trim();
|
|
58
|
+
const home = join(userHome, ".abtars");
|
|
59
|
+
const currentLink = join(home, "current");
|
|
60
|
+
if (!existsSync(currentLink)) {
|
|
61
|
+
process.stderr.write(`No release staged. Run 'abtars install' first.
|
|
62
|
+
`);
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
if (platform === "darwin") {
|
|
66
|
+
const { execSync, execFileSync } = await import("node:child_process");
|
|
67
|
+
let group = sudoUser;
|
|
68
|
+
try {
|
|
69
|
+
group = execSync(`id -gn ${sudoUser}`, { encoding: "utf-8" }).trim();
|
|
70
|
+
} catch (err) {
|
|
71
|
+
logAndSwallow("daemon", "op", err);
|
|
72
|
+
}
|
|
73
|
+
const plistSrc = join(pkgRoot, "scripts", "com.abtars.daemon.plist");
|
|
74
|
+
if (!existsSync(plistSrc)) {
|
|
75
|
+
process.stderr.write(`Template not found: ${plistSrc}
|
|
76
|
+
`);
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
let content = readFileSync(plistSrc, "utf-8");
|
|
80
|
+
content = content.replaceAll("{{USER}}", sudoUser).replaceAll("{{GROUP}}", group);
|
|
81
|
+
const dst = "/Library/LaunchDaemons/com.abtars.daemon.plist";
|
|
82
|
+
const { writeFileSync, chmodSync } = await import("node:fs");
|
|
83
|
+
writeFileSync(dst, content);
|
|
84
|
+
chmodSync(dst, 420);
|
|
85
|
+
try {
|
|
86
|
+
execFileSync("launchctl", ["bootstrap", "system", dst]);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
logAndSwallow("daemon", "op", err);
|
|
89
|
+
}
|
|
90
|
+
process.stdout.write(`\u2713 LaunchDaemon installed at ${dst}
|
|
91
|
+
`);
|
|
92
|
+
process.stdout.write(`\u2713 bridge runs as ${sudoUser}, survives logout + reboot
|
|
93
|
+
`);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
if (platform === "linux") {
|
|
97
|
+
const { execSync, execFileSync } = await import("node:child_process");
|
|
98
|
+
try {
|
|
99
|
+
execSync("systemctl --version", { stdio: "ignore" });
|
|
100
|
+
} catch {
|
|
101
|
+
process.stderr.write(`systemctl not found \u2014 requires systemd.
|
|
102
|
+
`);
|
|
103
|
+
return 2;
|
|
104
|
+
}
|
|
105
|
+
const unitSrc = join(pkgRoot, "scripts", "abtars-daemon.service");
|
|
106
|
+
if (!existsSync(unitSrc)) {
|
|
107
|
+
process.stderr.write(`Template not found: ${unitSrc}
|
|
108
|
+
`);
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
let content = readFileSync(unitSrc, "utf-8");
|
|
112
|
+
content = content.replaceAll("{{USER}}", sudoUser);
|
|
113
|
+
const dst = "/etc/systemd/system/abtars.service";
|
|
114
|
+
const { writeFileSync } = await import("node:fs");
|
|
115
|
+
writeFileSync(dst, content);
|
|
116
|
+
execFileSync("systemctl", ["daemon-reload"]);
|
|
117
|
+
execFileSync("systemctl", ["enable", "--now", "abtars"]);
|
|
118
|
+
process.stdout.write(`\u2713 systemd unit installed at ${dst}
|
|
119
|
+
`);
|
|
120
|
+
process.stdout.write(`\u2713 bridge runs as ${sudoUser}, survives logout + reboot
|
|
121
|
+
`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
process.stderr.write(`Unsupported platform: ${platform}
|
|
125
|
+
`);
|
|
126
|
+
return 2;
|
|
127
|
+
}
|
|
128
|
+
async function daemonUninstall() {
|
|
129
|
+
const scope = detectScope();
|
|
130
|
+
if (!scope) {
|
|
131
|
+
process.stderr.write("No daemon service found.\n");
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
if (scope === "system") {
|
|
135
|
+
if (process.getuid?.() !== 0) {
|
|
136
|
+
process.stderr.write(`Requires sudo: sudo -k $(which abtars) daemon uninstall
|
|
137
|
+
`);
|
|
138
|
+
return 2;
|
|
139
|
+
}
|
|
140
|
+
const { execFileSync } = await import("node:child_process");
|
|
141
|
+
const { unlinkSync } = await import("node:fs");
|
|
142
|
+
try {
|
|
143
|
+
execFileSync("systemctl", ["stop", "abtars"]);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
logAndSwallow("daemon", "op", err);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
execFileSync("systemctl", ["disable", "abtars"]);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
logAndSwallow("daemon", "op", err);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
unlinkSync("/etc/systemd/system/abtars.service");
|
|
154
|
+
} catch (err) {
|
|
155
|
+
logAndSwallow("daemon", "op", err);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
execFileSync("systemctl", ["daemon-reload"]);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
logAndSwallow("daemon", "op", err);
|
|
161
|
+
}
|
|
162
|
+
process.stdout.write("\u2713 system service removed\n");
|
|
163
|
+
} else {
|
|
164
|
+
const { execFileSync } = await import("node:child_process");
|
|
165
|
+
const { unlinkSync } = await import("node:fs");
|
|
166
|
+
const unit = join(process.env["HOME"] ?? "", ".config", "systemd", "user", "abtars-watchdog.service");
|
|
167
|
+
try {
|
|
168
|
+
execFileSync("systemctl", ["--user", "stop", "abtars-watchdog"]);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
logAndSwallow("daemon", "op", err);
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
execFileSync("systemctl", ["--user", "disable", "abtars-watchdog"]);
|
|
174
|
+
} catch (err) {
|
|
175
|
+
logAndSwallow("daemon", "op", err);
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
unlinkSync(unit);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
logAndSwallow("daemon", "op", err);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
execFileSync("systemctl", ["--user", "daemon-reload"]);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
logAndSwallow("daemon", "op", err);
|
|
186
|
+
}
|
|
187
|
+
process.stdout.write("\u2713 user service removed\n");
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
async function daemonControl(action) {
|
|
192
|
+
const scope = detectScope();
|
|
193
|
+
if (!scope) {
|
|
194
|
+
process.stderr.write("No daemon service found. Run: abtars daemon install\n");
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
const { execFileSync } = await import("node:child_process");
|
|
198
|
+
const unit = unitName(scope);
|
|
199
|
+
const args = scope === "user" ? ["--user", action, unit] : [action, unit];
|
|
200
|
+
try {
|
|
201
|
+
execFileSync("systemctl", args, { stdio: "inherit" });
|
|
202
|
+
process.stdout.write(`\u2713 ${action} ${unit}
|
|
203
|
+
`);
|
|
204
|
+
} catch {
|
|
205
|
+
process.stderr.write(`\u2717 ${action} failed
|
|
206
|
+
`);
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
async function daemonStatus() {
|
|
212
|
+
const scope = detectScope();
|
|
213
|
+
if (!scope) {
|
|
214
|
+
process.stdout.write("No daemon service installed.\n");
|
|
215
|
+
process.stdout.write(" Install: sudo $(which abtars) daemon install\n");
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
const { spawnSync } = await import("node:child_process");
|
|
219
|
+
const unit = unitName(scope);
|
|
220
|
+
const args = scope === "user" ? ["--user", "status", unit] : ["status", unit];
|
|
221
|
+
const r = spawnSync("systemctl", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
222
|
+
const output = r.stdout || r.stderr || "";
|
|
223
|
+
const activeMatch = output.match(/Active:\s+(.+)/);
|
|
224
|
+
const pidMatch = output.match(/Main PID:\s+(\d+)/);
|
|
225
|
+
process.stdout.write(`\u25CF ${unit} (${scope} scope)
|
|
226
|
+
`);
|
|
227
|
+
process.stdout.write(` ${activeMatch?.[1] ?? "unknown"}
|
|
228
|
+
`);
|
|
229
|
+
if (pidMatch) process.stdout.write(` PID: ${pidMatch[1]}
|
|
230
|
+
`);
|
|
231
|
+
const home = abtarsHome();
|
|
232
|
+
const lockPath = join(home, "bridge.lock");
|
|
233
|
+
if (existsSync(lockPath)) {
|
|
234
|
+
try {
|
|
235
|
+
const lock = JSON.parse(readFileSync(lockPath, "utf-8"));
|
|
236
|
+
if (lock.pid) process.stdout.write(` Bridge PID: ${lock.pid}
|
|
237
|
+
`);
|
|
238
|
+
if (lock.startedAt) {
|
|
239
|
+
const upMs = Date.now() - new Date(lock.startedAt).getTime();
|
|
240
|
+
const upMin = Math.round(upMs / 6e4);
|
|
241
|
+
process.stdout.write(` Uptime: ${upMin >= 60 ? `${Math.floor(upMin / 60)}h ${upMin % 60}m` : `${upMin}m`}
|
|
242
|
+
`);
|
|
243
|
+
}
|
|
244
|
+
if (lock.version) process.stdout.write(` Version: ${lock.version}
|
|
245
|
+
`);
|
|
246
|
+
if (lock.restartReason) process.stdout.write(` Last restart: ${lock.restartReason}
|
|
247
|
+
`);
|
|
248
|
+
} catch {
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
async function daemon(args) {
|
|
254
|
+
const sub = args[0] ?? "status";
|
|
255
|
+
switch (sub) {
|
|
256
|
+
case "install":
|
|
257
|
+
return daemonInstall();
|
|
258
|
+
case "uninstall":
|
|
259
|
+
return daemonUninstall();
|
|
260
|
+
case "start":
|
|
261
|
+
return daemonControl("start");
|
|
262
|
+
case "stop":
|
|
263
|
+
return daemonControl("stop");
|
|
264
|
+
case "restart":
|
|
265
|
+
return daemonControl("restart");
|
|
266
|
+
case "status":
|
|
267
|
+
return daemonStatus();
|
|
268
|
+
default:
|
|
269
|
+
process.stderr.write(`Unknown: abtars daemon ${sub}
|
|
270
|
+
Usage: abtars daemon [install|uninstall|start|stop|restart|status]
|
|
271
|
+
`);
|
|
272
|
+
return 1;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
export {
|
|
276
|
+
daemon
|
|
277
|
+
};
|
|
278
|
+
//# sourceMappingURL=daemon-PDOLHGWI.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cli/commands/daemon.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * `abtars daemon` \u2014 manage the system service (install/uninstall/start/stop/restart/status).\n */\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join, dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { logAndSwallow } from \"../../components/log-and-swallow.js\";\n\nfunction abtarsHome(): string {\n return process.env[\"ABTARS_HOME\"] ?? join(process.env[\"HOME\"] ?? \"\", \".abtars\");\n}\n\nfunction isWSL(): boolean {\n try { return readFileSync(\"/proc/version\", \"utf-8\").toLowerCase().includes(\"microsoft\"); } catch { return false; }\n}\n\ntype Scope = \"system\" | \"user\" | null;\n\nfunction detectScope(): Scope {\n if (existsSync(\"/etc/systemd/system/abtars.service\")) return \"system\";\n const userUnit = join(process.env[\"HOME\"] ?? \"\", \".config\", \"systemd\", \"user\", \"abtars-watchdog.service\");\n if (existsSync(userUnit)) return \"user\";\n return null;\n}\nfunction unitName(scope: Scope): string {\n return scope === \"user\" ? \"abtars-watchdog\" : \"abtars\";\n}\n\n// \u2500\u2500 install \u2500\u2500\n\nasync function daemonInstall(): Promise<number> {\n const platform = process.platform;\n const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), \"..\", \"..\");\n\n if (platform === \"linux\" && isWSL()) {\n process.stderr.write(`\u2139\uFE0F WSL detected \u2014 ensure systemd is enabled (wsl.conf: [boot] systemd=true)\\n`);\n }\n\n const sudoUser = process.env[\"SUDO_USER\"];\n if (process.getuid?.() !== 0) {\n process.stderr.write(\n `Requires sudo for system-scope service registration.\\n` +\n `Run: sudo -k $(which abtars) daemon install\\n`,\n );\n return 2;\n }\n if (!sudoUser) {\n process.stderr.write(`Cannot determine target user \u2014 $SUDO_USER is not set.\\n`);\n return 2;\n }\n\n // Resolve the SUDO_USER's home, not root's\n const { execSync: execSyncHome } = await import(\"node:child_process\");\n const userHome = execSyncHome(`eval echo ~${sudoUser}`, { encoding: \"utf-8\" }).trim();\n const home = join(userHome, \".abtars\");\n\n const currentLink = join(home, \"current\");\n if (!existsSync(currentLink)) {\n process.stderr.write(`No release staged. Run 'abtars install' first.\\n`);\n return 2;\n }\n\n if (platform === \"darwin\") {\n const { execSync, execFileSync } = await import(\"node:child_process\");\n let group = sudoUser;\n try { group = execSync(`id -gn ${sudoUser}`, { encoding: \"utf-8\" }).trim(); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n\n const plistSrc = join(pkgRoot, \"scripts\", \"com.abtars.daemon.plist\");\n if (!existsSync(plistSrc)) { process.stderr.write(`Template not found: ${plistSrc}\\n`); return 1; }\n let content = readFileSync(plistSrc, \"utf-8\");\n content = content.replaceAll(\"{{USER}}\", sudoUser).replaceAll(\"{{GROUP}}\", group);\n const dst = \"/Library/LaunchDaemons/com.abtars.daemon.plist\";\n\n const { writeFileSync, chmodSync } = await import(\"node:fs\");\n writeFileSync(dst, content);\n chmodSync(dst, 0o644);\n try { execFileSync(\"launchctl\", [\"bootstrap\", \"system\", dst]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n process.stdout.write(`\u2713 LaunchDaemon installed at ${dst}\\n`);\n process.stdout.write(`\u2713 bridge runs as ${sudoUser}, survives logout + reboot\\n`);\n return 0;\n }\n\n if (platform === \"linux\") {\n const { execSync, execFileSync } = await import(\"node:child_process\");\n try { execSync(\"systemctl --version\", { stdio: \"ignore\" }); } catch {\n process.stderr.write(`systemctl not found \u2014 requires systemd.\\n`);\n return 2;\n }\n\n const unitSrc = join(pkgRoot, \"scripts\", \"abtars-daemon.service\");\n if (!existsSync(unitSrc)) { process.stderr.write(`Template not found: ${unitSrc}\\n`); return 1; }\n let content = readFileSync(unitSrc, \"utf-8\");\n content = content.replaceAll(\"{{USER}}\", sudoUser);\n const dst = \"/etc/systemd/system/abtars.service\";\n\n const { writeFileSync } = await import(\"node:fs\");\n writeFileSync(dst, content);\n execFileSync(\"systemctl\", [\"daemon-reload\"]);\n execFileSync(\"systemctl\", [\"enable\", \"--now\", \"abtars\"]);\n process.stdout.write(`\u2713 systemd unit installed at ${dst}\\n`);\n process.stdout.write(`\u2713 bridge runs as ${sudoUser}, survives logout + reboot\\n`);\n return 0;\n }\n\n process.stderr.write(`Unsupported platform: ${platform}\\n`);\n return 2;\n}\n\n// \u2500\u2500 uninstall \u2500\u2500\n\nasync function daemonUninstall(): Promise<number> {\n const scope = detectScope();\n if (!scope) { process.stderr.write(\"No daemon service found.\\n\"); return 1; }\n\n if (scope === \"system\") {\n if (process.getuid?.() !== 0) {\n process.stderr.write(`Requires sudo: sudo -k $(which abtars) daemon uninstall\\n`);\n return 2;\n }\n const { execFileSync } = await import(\"node:child_process\");\n const { unlinkSync } = await import(\"node:fs\");\n try { execFileSync(\"systemctl\", [\"stop\", \"abtars\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { execFileSync(\"systemctl\", [\"disable\", \"abtars\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { unlinkSync(\"/etc/systemd/system/abtars.service\"); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { execFileSync(\"systemctl\", [\"daemon-reload\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n process.stdout.write(\"\u2713 system service removed\\n\");\n } else {\n const { execFileSync } = await import(\"node:child_process\");\n const { unlinkSync } = await import(\"node:fs\");\n const unit = join(process.env[\"HOME\"] ?? \"\", \".config\", \"systemd\", \"user\", \"abtars-watchdog.service\");\n try { execFileSync(\"systemctl\", [\"--user\", \"stop\", \"abtars-watchdog\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { execFileSync(\"systemctl\", [\"--user\", \"disable\", \"abtars-watchdog\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { unlinkSync(unit); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n try { execFileSync(\"systemctl\", [\"--user\", \"daemon-reload\"]); } catch (err) { logAndSwallow(\"daemon\", \"op\", err); }\n process.stdout.write(\"\u2713 user service removed\\n\");\n }\n return 0;\n}\n\n// \u2500\u2500 start/stop/restart \u2500\u2500\n\nasync function daemonControl(action: \"start\" | \"stop\" | \"restart\"): Promise<number> {\n const scope = detectScope();\n if (!scope) { process.stderr.write(\"No daemon service found. Run: abtars daemon install\\n\"); return 1; }\n const { execFileSync } = await import(\"node:child_process\");\n const unit = unitName(scope);\n const args = scope === \"user\" ? [\"--user\", action, unit] : [action, unit];\n try {\n execFileSync(\"systemctl\", args, { stdio: \"inherit\" });\n process.stdout.write(`\u2713 ${action} ${unit}\\n`);\n } catch {\n process.stderr.write(`\u2717 ${action} failed\\n`);\n return 1;\n }\n return 0;\n}\n\n// \u2500\u2500 status \u2500\u2500\n\nasync function daemonStatus(): Promise<number> {\n const scope = detectScope();\n if (!scope) {\n process.stdout.write(\"No daemon service installed.\\n\");\n process.stdout.write(\" Install: sudo $(which abtars) daemon install\\n\");\n return 0;\n }\n\n const { spawnSync } = await import(\"node:child_process\");\n const unit = unitName(scope);\n const args = scope === \"user\" ? [\"--user\", \"status\", unit] : [\"status\", unit];\n const r = spawnSync(\"systemctl\", args, { encoding: \"utf-8\", stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n const output = r.stdout || r.stderr || \"\";\n\n // Parse active state\n const activeMatch = output.match(/Active:\\s+(.+)/);\n const pidMatch = output.match(/Main PID:\\s+(\\d+)/);\n\n process.stdout.write(`\u25CF ${unit} (${scope} scope)\\n`);\n process.stdout.write(` ${activeMatch?.[1] ?? \"unknown\"}\\n`);\n if (pidMatch) process.stdout.write(` PID: ${pidMatch[1]}\\n`);\n\n // Bridge info from bridge.lock\n const home = abtarsHome();\n const lockPath = join(home, \"bridge.lock\");\n if (existsSync(lockPath)) {\n try {\n const lock = JSON.parse(readFileSync(lockPath, \"utf-8\"));\n if (lock.pid) process.stdout.write(` Bridge PID: ${lock.pid}\\n`);\n if (lock.startedAt) {\n const upMs = Date.now() - new Date(lock.startedAt).getTime();\n const upMin = Math.round(upMs / 60000);\n process.stdout.write(` Uptime: ${upMin >= 60 ? `${Math.floor(upMin / 60)}h ${upMin % 60}m` : `${upMin}m`}\\n`);\n }\n if (lock.version) process.stdout.write(` Version: ${lock.version}\\n`);\n if (lock.restartReason) process.stdout.write(` Last restart: ${lock.restartReason}\\n`);\n } catch { /* ignore */ }\n }\n return 0;\n}\n\n// \u2500\u2500 router \u2500\u2500\n\nexport async function daemon(args: string[]): Promise<number> {\n const sub = args[0] ?? \"status\";\n switch (sub) {\n case \"install\": return daemonInstall();\n case \"uninstall\": return daemonUninstall();\n case \"start\": return daemonControl(\"start\");\n case \"stop\": return daemonControl(\"stop\");\n case \"restart\": return daemonControl(\"restart\");\n case \"status\": return daemonStatus();\n default:\n process.stderr.write(`Unknown: abtars daemon ${sub}\\nUsage: abtars daemon [install|uninstall|start|stop|restart|status]\\n`);\n return 1;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAMA;AAHA,SAAS,YAAY,oBAAoB;AACzC,SAAS,MAAM,eAAe;AAC9B,SAAS,qBAAqB;AAG9B,SAAS,aAAqB;AAC5B,SAAO,QAAQ,IAAI,aAAa,KAAK,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,SAAS;AAChF;AAEA,SAAS,QAAiB;AACxB,MAAI;AAAE,WAAO,aAAa,iBAAiB,OAAO,EAAE,YAAY,EAAE,SAAS,WAAW;AAAA,EAAG,QAAQ;AAAE,WAAO;AAAA,EAAO;AACnH;AAIA,SAAS,cAAqB;AAC5B,MAAI,WAAW,oCAAoC,EAAG,QAAO;AAC7D,QAAM,WAAW,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,WAAW,WAAW,QAAQ,yBAAyB;AACxG,MAAI,WAAW,QAAQ,EAAG,QAAO;AACjC,SAAO;AACT;AACA,SAAS,SAAS,OAAsB;AACtC,SAAO,UAAU,SAAS,oBAAoB;AAChD;AAIA,eAAe,gBAAiC;AAC9C,QAAM,WAA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AAAW,aAAO,cAAc;AAAA,IACrC,KAAK;AAAa,aAAO,gBAAgB;AAAA,IACzC,KAAK;AAAS,aAAO,cAAc,OAAO;AAAA,IAC1C,KAAK;AAAQ,aAAO,cAAc,MAAM;AAAA,IACxC,KAAK;AAAW,aAAO,cAAc,SAAS;AAAA,IAC9C,KAAK;AAAU,aAAO,aAAa;AAAA,IACnC;AACE,cAAQ,OAAO,MAAM,0BAA0B,GAAG;AAAA;AAAA,CAAwE;AAC1H,aAAO;AAAA,EACX;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/bundle/meta.json
CHANGED
|
@@ -28829,7 +28829,7 @@
|
|
|
28829
28829
|
"format": "esm"
|
|
28830
28830
|
},
|
|
28831
28831
|
"src/cli/commands/daemon.ts": {
|
|
28832
|
-
"bytes":
|
|
28832
|
+
"bytes": 8988,
|
|
28833
28833
|
"imports": [
|
|
28834
28834
|
{
|
|
28835
28835
|
"path": "node:fs",
|
|
@@ -28856,6 +28856,11 @@
|
|
|
28856
28856
|
"kind": "dynamic-import",
|
|
28857
28857
|
"external": true
|
|
28858
28858
|
},
|
|
28859
|
+
{
|
|
28860
|
+
"path": "node:child_process",
|
|
28861
|
+
"kind": "dynamic-import",
|
|
28862
|
+
"external": true
|
|
28863
|
+
},
|
|
28859
28864
|
{
|
|
28860
28865
|
"path": "node:fs",
|
|
28861
28866
|
"kind": "dynamic-import",
|
|
@@ -29373,13 +29378,13 @@
|
|
|
29373
29378
|
},
|
|
29374
29379
|
"bytes": 1250
|
|
29375
29380
|
},
|
|
29376
|
-
"bundle/daemon-
|
|
29381
|
+
"bundle/daemon-PDOLHGWI.js.map": {
|
|
29377
29382
|
"imports": [],
|
|
29378
29383
|
"exports": [],
|
|
29379
29384
|
"inputs": {},
|
|
29380
|
-
"bytes":
|
|
29385
|
+
"bytes": 15710
|
|
29381
29386
|
},
|
|
29382
|
-
"bundle/daemon-
|
|
29387
|
+
"bundle/daemon-PDOLHGWI.js": {
|
|
29383
29388
|
"imports": [
|
|
29384
29389
|
{
|
|
29385
29390
|
"path": "bundle/chunk-EX2SRTUE.js",
|
|
@@ -29417,6 +29422,11 @@
|
|
|
29417
29422
|
"kind": "dynamic-import",
|
|
29418
29423
|
"external": true
|
|
29419
29424
|
},
|
|
29425
|
+
{
|
|
29426
|
+
"path": "node:child_process",
|
|
29427
|
+
"kind": "dynamic-import",
|
|
29428
|
+
"external": true
|
|
29429
|
+
},
|
|
29420
29430
|
{
|
|
29421
29431
|
"path": "node:fs",
|
|
29422
29432
|
"kind": "dynamic-import",
|
|
@@ -29469,10 +29479,10 @@
|
|
|
29469
29479
|
"entryPoint": "src/cli/commands/daemon.ts",
|
|
29470
29480
|
"inputs": {
|
|
29471
29481
|
"src/cli/commands/daemon.ts": {
|
|
29472
|
-
"bytesInOutput":
|
|
29482
|
+
"bytesInOutput": 8661
|
|
29473
29483
|
}
|
|
29474
29484
|
},
|
|
29475
|
-
"bytes":
|
|
29485
|
+
"bytes": 9320
|
|
29476
29486
|
},
|
|
29477
29487
|
"bundle/logs-EK4HYRKR.js.map": {
|
|
29478
29488
|
"imports": [],
|
|
@@ -40247,7 +40257,7 @@
|
|
|
40247
40257
|
"kind": "dynamic-import"
|
|
40248
40258
|
},
|
|
40249
40259
|
{
|
|
40250
|
-
"path": "bundle/daemon-
|
|
40260
|
+
"path": "bundle/daemon-PDOLHGWI.js",
|
|
40251
40261
|
"kind": "dynamic-import"
|
|
40252
40262
|
},
|
|
40253
40263
|
{
|