abtars 0.1.0-alpha.13 → 0.1.0-alpha.14
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-VIBI3SQQ.js +286 -0
- package/bundle/daemon-VIBI3SQQ.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-VIBI3SQQ.js");
|
|
1402
1402
|
return await daemonCmd(argv.slice(1));
|
|
1403
1403
|
}
|
|
1404
1404
|
case "logs": {
|
|
@@ -0,0 +1,286 @@
|
|
|
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
|
+
const manifestPath = join(home, "manifest.json");
|
|
119
|
+
try {
|
|
120
|
+
const { readFileSync: rfs, writeFileSync: wfs } = await import("node:fs");
|
|
121
|
+
const mf = JSON.parse(rfs(manifestPath, "utf-8"));
|
|
122
|
+
mf.installMode = "supervised-daemon";
|
|
123
|
+
wfs(manifestPath, JSON.stringify(mf, null, 2) + "\n");
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
process.stdout.write(`\u2713 systemd unit installed at ${dst}
|
|
127
|
+
`);
|
|
128
|
+
process.stdout.write(`\u2713 bridge runs as ${sudoUser}, survives logout + reboot
|
|
129
|
+
`);
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
process.stderr.write(`Unsupported platform: ${platform}
|
|
133
|
+
`);
|
|
134
|
+
return 2;
|
|
135
|
+
}
|
|
136
|
+
async function daemonUninstall() {
|
|
137
|
+
const scope = detectScope();
|
|
138
|
+
if (!scope) {
|
|
139
|
+
process.stderr.write("No daemon service found.\n");
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
if (scope === "system") {
|
|
143
|
+
if (process.getuid?.() !== 0) {
|
|
144
|
+
process.stderr.write(`Requires sudo: sudo -k $(which abtars) daemon uninstall
|
|
145
|
+
`);
|
|
146
|
+
return 2;
|
|
147
|
+
}
|
|
148
|
+
const { execFileSync } = await import("node:child_process");
|
|
149
|
+
const { unlinkSync } = await import("node:fs");
|
|
150
|
+
try {
|
|
151
|
+
execFileSync("systemctl", ["stop", "abtars"]);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
logAndSwallow("daemon", "op", err);
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
execFileSync("systemctl", ["disable", "abtars"]);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
logAndSwallow("daemon", "op", err);
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
unlinkSync("/etc/systemd/system/abtars.service");
|
|
162
|
+
} catch (err) {
|
|
163
|
+
logAndSwallow("daemon", "op", err);
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
execFileSync("systemctl", ["daemon-reload"]);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
logAndSwallow("daemon", "op", err);
|
|
169
|
+
}
|
|
170
|
+
process.stdout.write("\u2713 system service removed\n");
|
|
171
|
+
} else {
|
|
172
|
+
const { execFileSync } = await import("node:child_process");
|
|
173
|
+
const { unlinkSync } = await import("node:fs");
|
|
174
|
+
const unit = join(process.env["HOME"] ?? "", ".config", "systemd", "user", "abtars-watchdog.service");
|
|
175
|
+
try {
|
|
176
|
+
execFileSync("systemctl", ["--user", "stop", "abtars-watchdog"]);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
logAndSwallow("daemon", "op", err);
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
execFileSync("systemctl", ["--user", "disable", "abtars-watchdog"]);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
logAndSwallow("daemon", "op", err);
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
unlinkSync(unit);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
logAndSwallow("daemon", "op", err);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
execFileSync("systemctl", ["--user", "daemon-reload"]);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
logAndSwallow("daemon", "op", err);
|
|
194
|
+
}
|
|
195
|
+
process.stdout.write("\u2713 user service removed\n");
|
|
196
|
+
}
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
async function daemonControl(action) {
|
|
200
|
+
const scope = detectScope();
|
|
201
|
+
if (!scope) {
|
|
202
|
+
process.stderr.write("No daemon service found. Run: abtars daemon install\n");
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
const { execFileSync } = await import("node:child_process");
|
|
206
|
+
const unit = unitName(scope);
|
|
207
|
+
const args = scope === "user" ? ["--user", action, unit] : [action, unit];
|
|
208
|
+
try {
|
|
209
|
+
execFileSync("systemctl", args, { stdio: "inherit" });
|
|
210
|
+
process.stdout.write(`\u2713 ${action} ${unit}
|
|
211
|
+
`);
|
|
212
|
+
} catch {
|
|
213
|
+
process.stderr.write(`\u2717 ${action} failed
|
|
214
|
+
`);
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
async function daemonStatus() {
|
|
220
|
+
const scope = detectScope();
|
|
221
|
+
if (!scope) {
|
|
222
|
+
process.stdout.write("No daemon service installed.\n");
|
|
223
|
+
process.stdout.write(" Install: sudo $(which abtars) daemon install\n");
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
const { spawnSync } = await import("node:child_process");
|
|
227
|
+
const unit = unitName(scope);
|
|
228
|
+
const args = scope === "user" ? ["--user", "status", unit] : ["status", unit];
|
|
229
|
+
const r = spawnSync("systemctl", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
230
|
+
const output = r.stdout || r.stderr || "";
|
|
231
|
+
const activeMatch = output.match(/Active:\s+(.+)/);
|
|
232
|
+
const pidMatch = output.match(/Main PID:\s+(\d+)/);
|
|
233
|
+
process.stdout.write(`\u25CF ${unit} (${scope} scope)
|
|
234
|
+
`);
|
|
235
|
+
process.stdout.write(` ${activeMatch?.[1] ?? "unknown"}
|
|
236
|
+
`);
|
|
237
|
+
if (pidMatch) process.stdout.write(` PID: ${pidMatch[1]}
|
|
238
|
+
`);
|
|
239
|
+
const home = abtarsHome();
|
|
240
|
+
const lockPath = join(home, "bridge.lock");
|
|
241
|
+
if (existsSync(lockPath)) {
|
|
242
|
+
try {
|
|
243
|
+
const lock = JSON.parse(readFileSync(lockPath, "utf-8"));
|
|
244
|
+
if (lock.pid) process.stdout.write(` Bridge PID: ${lock.pid}
|
|
245
|
+
`);
|
|
246
|
+
if (lock.startedAt) {
|
|
247
|
+
const upMs = Date.now() - new Date(lock.startedAt).getTime();
|
|
248
|
+
const upMin = Math.round(upMs / 6e4);
|
|
249
|
+
process.stdout.write(` Uptime: ${upMin >= 60 ? `${Math.floor(upMin / 60)}h ${upMin % 60}m` : `${upMin}m`}
|
|
250
|
+
`);
|
|
251
|
+
}
|
|
252
|
+
if (lock.version) process.stdout.write(` Version: ${lock.version}
|
|
253
|
+
`);
|
|
254
|
+
if (lock.restartReason) process.stdout.write(` Last restart: ${lock.restartReason}
|
|
255
|
+
`);
|
|
256
|
+
} catch {
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
async function daemon(args) {
|
|
262
|
+
const sub = args[0] ?? "status";
|
|
263
|
+
switch (sub) {
|
|
264
|
+
case "install":
|
|
265
|
+
return daemonInstall();
|
|
266
|
+
case "uninstall":
|
|
267
|
+
return daemonUninstall();
|
|
268
|
+
case "start":
|
|
269
|
+
return daemonControl("start");
|
|
270
|
+
case "stop":
|
|
271
|
+
return daemonControl("stop");
|
|
272
|
+
case "restart":
|
|
273
|
+
return daemonControl("restart");
|
|
274
|
+
case "status":
|
|
275
|
+
return daemonStatus();
|
|
276
|
+
default:
|
|
277
|
+
process.stderr.write(`Unknown: abtars daemon ${sub}
|
|
278
|
+
Usage: abtars daemon [install|uninstall|start|stop|restart|status]
|
|
279
|
+
`);
|
|
280
|
+
return 1;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export {
|
|
284
|
+
daemon
|
|
285
|
+
};
|
|
286
|
+
//# sourceMappingURL=daemon-VIBI3SQQ.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 // Update manifest mode\n const manifestPath = join(home, \"manifest.json\");\n try {\n const { readFileSync: rfs, writeFileSync: wfs } = await import(\"node:fs\");\n const mf = JSON.parse(rfs(manifestPath, \"utf-8\"));\n mf.installMode = \"supervised-daemon\";\n wfs(manifestPath, JSON.stringify(mf, null, 2) + \"\\n\");\n } catch { /* best effort */ }\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,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
28822
|
-
"bytes":
|
|
28822
|
+
"bytes": 9351,
|
|
28823
28823
|
"imports": [
|
|
28824
28824
|
{
|
|
28825
28825
|
"path": "node:fs",
|
|
@@ -28866,6 +28866,11 @@
|
|
|
28866
28866
|
"kind": "dynamic-import",
|
|
28867
28867
|
"external": true
|
|
28868
28868
|
},
|
|
28869
|
+
{
|
|
28870
|
+
"path": "node:fs",
|
|
28871
|
+
"kind": "dynamic-import",
|
|
28872
|
+
"external": true
|
|
28873
|
+
},
|
|
28869
28874
|
{
|
|
28870
28875
|
"path": "node:child_process",
|
|
28871
28876
|
"kind": "dynamic-import",
|
|
@@ -29264,13 +29269,13 @@
|
|
|
29264
29269
|
},
|
|
29265
29270
|
"bytes": 1250
|
|
29266
29271
|
},
|
|
29267
|
-
"bundle/daemon-
|
|
29272
|
+
"bundle/daemon-VIBI3SQQ.js.map": {
|
|
29268
29273
|
"imports": [],
|
|
29269
29274
|
"exports": [],
|
|
29270
29275
|
"inputs": {},
|
|
29271
|
-
"bytes":
|
|
29276
|
+
"bytes": 16322
|
|
29272
29277
|
},
|
|
29273
|
-
"bundle/daemon-
|
|
29278
|
+
"bundle/daemon-VIBI3SQQ.js": {
|
|
29274
29279
|
"imports": [
|
|
29275
29280
|
{
|
|
29276
29281
|
"path": "bundle/chunk-EX2SRTUE.js",
|
|
@@ -29328,6 +29333,11 @@
|
|
|
29328
29333
|
"kind": "dynamic-import",
|
|
29329
29334
|
"external": true
|
|
29330
29335
|
},
|
|
29336
|
+
{
|
|
29337
|
+
"path": "node:fs",
|
|
29338
|
+
"kind": "dynamic-import",
|
|
29339
|
+
"external": true
|
|
29340
|
+
},
|
|
29331
29341
|
{
|
|
29332
29342
|
"path": "node:child_process",
|
|
29333
29343
|
"kind": "dynamic-import",
|
|
@@ -29365,10 +29375,10 @@
|
|
|
29365
29375
|
"entryPoint": "src/cli/commands/daemon.ts",
|
|
29366
29376
|
"inputs": {
|
|
29367
29377
|
"src/cli/commands/daemon.ts": {
|
|
29368
|
-
"bytesInOutput":
|
|
29378
|
+
"bytesInOutput": 8982
|
|
29369
29379
|
}
|
|
29370
29380
|
},
|
|
29371
|
-
"bytes":
|
|
29381
|
+
"bytes": 9641
|
|
29372
29382
|
},
|
|
29373
29383
|
"bundle/logs-EK4HYRKR.js.map": {
|
|
29374
29384
|
"imports": [],
|
|
@@ -40247,7 +40257,7 @@
|
|
|
40247
40257
|
"kind": "dynamic-import"
|
|
40248
40258
|
},
|
|
40249
40259
|
{
|
|
40250
|
-
"path": "bundle/daemon-
|
|
40260
|
+
"path": "bundle/daemon-VIBI3SQQ.js",
|
|
40251
40261
|
"kind": "dynamic-import"
|
|
40252
40262
|
},
|
|
40253
40263
|
{
|