mslxdff 0.1.76 → 0.1.77
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/autostart.js +28 -12
package/package.json
CHANGED
package/src/autostart.js
CHANGED
|
@@ -156,21 +156,37 @@ async function linuxEnable() {
|
|
|
156
156
|
lingerRes = lr.err ? (lr.stderr || lr.stdout || lr.err.message || "").slice(0, 200) : "ok";
|
|
157
157
|
}
|
|
158
158
|
} catch {}
|
|
159
|
-
// stop bare detached daemon that may hold the port, let systemd take over (best-effort)
|
|
159
|
+
// stop bare detached daemon that may hold the port, let systemd take over (best-effort, wait for port free)
|
|
160
160
|
try {
|
|
161
|
-
const {
|
|
162
|
-
const { existsSync: exists2, readFileSync: read2 } = await import("node:fs");
|
|
163
|
-
// Only stop if pid exists and is alive and not already managed by systemd
|
|
161
|
+
const { isPidAlive, stopDaemon } = await import("../daemon.js");
|
|
164
162
|
const pidFile = join(homedir(), ".config", "mslxdff", "daemon.pid");
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
163
|
+
const { existsSync: exists2, readFileSync: read2 } = await import("node:fs");
|
|
164
|
+
let pidToWait = null;
|
|
165
|
+
try {
|
|
166
|
+
if (exists2(pidFile)) {
|
|
167
|
+
const raw = read2(pidFile, "utf8").trim().split("\n")[0];
|
|
168
|
+
const n = Number(raw);
|
|
169
|
+
if (Number.isInteger(n) && n > 0 && isPidAlive(n)) pidToWait = n;
|
|
170
170
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
} catch {}
|
|
172
|
+
try { stopDaemon(); } catch {}
|
|
173
|
+
// ensure bare daemon really exits (SIGTERM -> SIGKILL)
|
|
174
|
+
for (let i = 0; i < 15; i++) {
|
|
175
|
+
if (pidToWait && isPidAlive(pidToWait)) {
|
|
176
|
+
if (i === 7) try { process.kill(pidToWait, "SIGKILL"); } catch {}
|
|
177
|
+
await new Promise((r2) => setTimeout(r2, 200));
|
|
178
|
+
} else break;
|
|
179
|
+
}
|
|
180
|
+
// best-effort: fuser kill port if still held (some pid without pid file)
|
|
181
|
+
try { await execAsync("fuser", ["-k", "8989/tcp"]); } catch {}
|
|
182
|
+
// stop any leftover systemd instance before start
|
|
183
|
+
try { await execAsync("systemctl", ["--user", "stop", SERVICE_NAME]); } catch {}
|
|
184
|
+
// wait for :8989 to be free
|
|
185
|
+
for (let i = 0; i < 15; i++) {
|
|
186
|
+
const chk = await execAsync("ss", ["-ltn"]);
|
|
187
|
+
if (!chk.stdout.includes(":8989")) break;
|
|
188
|
+
await new Promise((r2) => setTimeout(r2, 200));
|
|
189
|
+
if (i === 8) try { await execAsync("fuser", ["-k", "8989/tcp"]); } catch {}
|
|
174
190
|
}
|
|
175
191
|
} catch {}
|
|
176
192
|
let r = await execAsync("systemctl", ["--user", "daemon-reload"]);
|