@fulldivevr/workcord-cli 3.0.5 → 3.0.6
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/machine/service.js +17 -2
- package/package.json +1 -1
package/dist/machine/service.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
3
|
+
import { homedir, userInfo } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
const exec = promisify(execFile);
|
|
@@ -87,10 +87,25 @@ export async function installService(spec) {
|
|
|
87
87
|
await writeFile(paths.systemd, systemdUnit(spec), { mode: 0o644 });
|
|
88
88
|
await exec("systemctl", ["--user", "daemon-reload"]);
|
|
89
89
|
await exec("systemctl", ["--user", "enable", "--now", SYSTEMD_UNIT]);
|
|
90
|
-
|
|
90
|
+
const linger = await ensureLinger(userInfo().username);
|
|
91
|
+
return { path: paths.systemd, manager: "systemd", linger };
|
|
91
92
|
}
|
|
92
93
|
throw new Error(`install-service supports macOS (launchd) and Linux (systemd), not ${process.platform}.`);
|
|
93
94
|
}
|
|
95
|
+
// Without lingering, systemd stops the user manager (and this service) when the last login session ends.
|
|
96
|
+
export async function ensureLinger(user, run = exec, warn = (line) => process.stderr.write(line)) {
|
|
97
|
+
const { stdout } = await run("loginctl", ["show-user", user, "-p", "Linger"]).catch(() => ({ stdout: "" }));
|
|
98
|
+
if (/^Linger=yes$/m.test(stdout))
|
|
99
|
+
return true;
|
|
100
|
+
try {
|
|
101
|
+
await run("loginctl", ["enable-linger", user]);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
warn(`WARNING: the service stops when you log out. Run: sudo loginctl enable-linger ${user}\n`);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
94
109
|
export async function uninstallService(home = homedir()) {
|
|
95
110
|
const paths = servicePaths(home);
|
|
96
111
|
if (process.platform === "darwin") {
|