cofluxd 2.2.1 → 2.4.0

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/cofluxd.mjs CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  parseReleaseManifestEntry,
22
22
  verifyReleaseArtifact,
23
23
  } from "./release-trust.mjs";
24
+ import { executorRuntime, plistXml, systemdUnit } from "./service-unit.mjs";
24
25
 
25
26
  // 默认中心服务(公共 SaaS);自托管用 --server 覆盖。
26
27
  const DEFAULT_SERVER = "wss://api.coflux.dev/daemon";
@@ -395,49 +396,25 @@ function applyConfig({ serverUrl, deviceName, shell }) {
395
396
  return settings;
396
397
  }
397
398
 
398
- function plistXml() {
399
- return `<?xml version="1.0" encoding="UTF-8"?>
400
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
401
- <plist version="1.0">
402
- <dict>
403
- <key>Label</key><string>com.coflux.daemon</string>
404
- <key>ProgramArguments</key>
405
- <array><string>${SUP_BIN}</string></array>
406
- <key>EnvironmentVariables</key>
407
- <dict><key>COFLUX_HOME</key><string>${HOME}</string></dict>
408
- <key>RunAtLoad</key><true/>
409
- <key>KeepAlive</key><true/>
410
- <key>StandardOutPath</key><string>${LOG_FILE}</string>
411
- <key>StandardErrorPath</key><string>${LOG_FILE}</string>
412
- </dict>
413
- </plist>
414
- `;
415
- }
416
- function systemdUnit() {
417
- return `[Unit]
418
- Description=coflux daemon (supervisor)
419
- After=network-online.target
420
- Wants=network-online.target
421
-
422
- [Service]
423
- Environment=COFLUX_HOME=${HOME}
424
- ExecStart=${SUP_BIN}
425
- Restart=always
426
- RestartSec=2
427
-
428
- [Install]
429
- WantedBy=default.target
430
- `;
399
+ /**
400
+ * The executor runtime recorded in the unit, worked out once per `cofluxd up`. See
401
+ * `service-unit.mjs`: null simply means this installation does not host an executor.
402
+ */
403
+ function executorUnitRuntime() {
404
+ const runtime = executorRuntime();
405
+ if (!runtime) console.log("· 本次安装不托管 executor(找不到 @coflux/executor);由 Coflux.app 托管或先重装 cofluxd");
406
+ return runtime;
431
407
  }
408
+
432
409
  function installService(start) {
433
410
  if (IS_MAC) {
434
411
  fs.mkdirSync(dirname(PLIST), { recursive: true });
435
- fs.writeFileSync(PLIST, plistXml());
412
+ fs.writeFileSync(PLIST, plistXml({ supervisorBin: SUP_BIN, home: HOME, logFile: LOG_FILE, executor: executorUnitRuntime() }));
436
413
  if (start) { run("launchctl", ["unload", PLIST]); run("launchctl", ["load", PLIST]); }
437
414
  console.log(`✓ launchd: ${PLIST}`);
438
415
  } else if (IS_LINUX) {
439
416
  fs.mkdirSync(dirname(UNIT), { recursive: true });
440
- fs.writeFileSync(UNIT, systemdUnit());
417
+ fs.writeFileSync(UNIT, systemdUnit({ supervisorBin: SUP_BIN, home: HOME, executor: executorUnitRuntime() }));
441
418
  if (start) { run("systemctl", ["--user", "daemon-reload"]); run("systemctl", ["--user", "enable", "--now", "coflux-daemon.service"]); }
442
419
  console.log(`✓ systemd: ${UNIT}`);
443
420
  } else die("仅支持 macOS / Linux");