mslxdff 0.1.75 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/autostart.js +30 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mslxdff",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/autostart.js CHANGED
@@ -127,7 +127,8 @@ After=network.target
127
127
 
128
128
  [Service]
129
129
  Type=simple
130
- ExecStart=${node} ${script}
130
+ Environment=MSLXDFF_DAEMON=1
131
+ ExecStart=${node} ${script} --daemon
131
132
  Restart=always
132
133
  RestartSec=3
133
134
 
@@ -155,21 +156,37 @@ async function linuxEnable() {
155
156
  lingerRes = lr.err ? (lr.stderr || lr.stdout || lr.err.message || "").slice(0, 200) : "ok";
156
157
  }
157
158
  } catch {}
158
- // 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)
159
160
  try {
160
- const { readPid, isPidAlive } = await import("../daemon.js");
161
- const { existsSync: exists2, readFileSync: read2 } = await import("node:fs");
162
- // Only stop if pid exists and is alive and not already managed by systemd
161
+ const { isPidAlive, stopDaemon } = await import("../daemon.js");
163
162
  const pidFile = join(homedir(), ".config", "mslxdff", "daemon.pid");
164
- if (exists2(pidFile)) {
165
- const raw = read2(pidFile, "utf8").trim().split("\n")[0];
166
- const pid = Number(raw);
167
- if (Number.isInteger(pid) && pid > 0) {
168
- try { if (isPidAlive(pid)) { const { stopDaemon } = await import("../daemon.js"); stopDaemon(); await new Promise((r2) => setTimeout(r2, 600)); } } catch {}
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;
169
170
  }
170
- } else {
171
- // No pid file, try generic stop (no-op if none)
172
- try { const { stopDaemon } = await import("../daemon.js"); stopDaemon(); } catch {}
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 {}
173
190
  }
174
191
  } catch {}
175
192
  let r = await execAsync("systemctl", ["--user", "daemon-reload"]);