@jaibber/sdk 0.1.8 → 0.1.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/dist/cli.js +32 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1341,21 +1341,42 @@ WantedBy=default.target
|
|
|
1341
1341
|
const serviceDir = join(homedir(), ".config", "systemd", "user");
|
|
1342
1342
|
const serviceName = `jaibber-agent.service`;
|
|
1343
1343
|
const servicePath = join(serviceDir, serviceName);
|
|
1344
|
+
mkdirSync(serviceDir, { recursive: true });
|
|
1345
|
+
writeFileSync(servicePath, serviceContent);
|
|
1344
1346
|
try {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
execSync(`systemctl --user enable --now ${serviceName}`);
|
|
1349
|
-
console.log(`[cli] Service installed and started.`);
|
|
1350
|
-
console.log(`[cli] Manage with:`);
|
|
1347
|
+
execSync(`systemctl --user daemon-reload`, { stdio: "ignore" });
|
|
1348
|
+
execSync(`systemctl --user enable --now ${serviceName}`, { stdio: "ignore" });
|
|
1349
|
+
console.log(`[cli] Service installed and started (systemd).`);
|
|
1351
1350
|
console.log(`[cli] systemctl --user status jaibber-agent`);
|
|
1352
1351
|
console.log(`[cli] systemctl --user restart jaibber-agent`);
|
|
1353
1352
|
console.log(`[cli] journalctl --user -u jaibber-agent -f`);
|
|
1354
|
-
} catch
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1353
|
+
} catch {
|
|
1354
|
+
const cronLine = `@reboot ${execStart} >> ${homedir()}/jaibber-agent.log 2>&1`;
|
|
1355
|
+
try {
|
|
1356
|
+
let existing = "";
|
|
1357
|
+
try {
|
|
1358
|
+
existing = execSync("crontab -l 2>/dev/null").toString();
|
|
1359
|
+
} catch {
|
|
1360
|
+
}
|
|
1361
|
+
const filtered = existing.split("\n").filter((l) => !l.includes("jaibber-agent")).join("\n").trimEnd();
|
|
1362
|
+
const newCrontab = (filtered ? filtered + "\n" : "") + cronLine + "\n";
|
|
1363
|
+
execSync(`echo ${JSON.stringify(newCrontab)} | crontab -`);
|
|
1364
|
+
console.log(`[cli] Service installed via crontab (starts on reboot).`);
|
|
1365
|
+
console.log(`[cli] View log: tail -f ~/jaibber-agent.log`);
|
|
1366
|
+
console.log(`[cli] Remove: crontab -e (delete the jaibber-agent line)`);
|
|
1367
|
+
console.log(`[cli] Tip: run "sudo loginctl enable-linger ${process.env.USER || "ubuntu"}" to switch to systemd for better reliability.`);
|
|
1368
|
+
const { spawn: spawnBg } = await import("child_process");
|
|
1369
|
+
spawnBg(binaryPath, [scriptPath, ...flags], {
|
|
1370
|
+
detached: true,
|
|
1371
|
+
stdio: ["ignore", "ignore", "ignore"]
|
|
1372
|
+
}).unref();
|
|
1373
|
+
console.log(`[cli] Agent started in background.`);
|
|
1374
|
+
} catch (cronErr) {
|
|
1375
|
+
console.error(`[cli] Could not install via crontab either: ${cronErr instanceof Error ? cronErr.message : cronErr}`);
|
|
1376
|
+
console.error(`[cli] Service file written to: ${servicePath}`);
|
|
1377
|
+
console.error(`[cli] Run manually: sudo loginctl enable-linger $USER && systemctl --user enable --now jaibber-agent`);
|
|
1378
|
+
process.exit(1);
|
|
1379
|
+
}
|
|
1359
1380
|
}
|
|
1360
1381
|
process.exit(0);
|
|
1361
1382
|
}
|