Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web-vscode): 卸载只停自己安装目录的服务单元

lmliheng7dfa6442fb8c
diff --git a/plugins/web-vscode/package.json b/plugins/web-vscode/package.json
index d9cd790f..ca499dca 100644
--- a/plugins/web-vscode/package.json
+++ b/plugins/web-vscode/package.json
@@ -1,6 +1,6 @@
{
"name": "@adelie/web-vscode",
- "version": "0.6.4",
+ "version": "0.6.5",
"description": "Stand up VS Code in the browser on a server and make it actually usable: code-server behind an HTTPS reverse proxy with a local certificate authority, verified end to end, with the certificate-trust steps for Windows, macOS, iOS and Android.",
"license": "Apache-2.0",
"repository": {
diff --git a/plugins/web-vscode/plugin.json b/plugins/web-vscode/plugin.json
index 65822e01..8e732064 100644
--- a/plugins/web-vscode/plugin.json
+++ b/plugins/web-vscode/plugin.json
@@ -3,7 +3,7 @@
"description_zh": "把 VS Code 装到服务器上做成能用的浏览器版本:code-server + 自带证书机构的 HTTPS 反向代理,配上 Windows/macOS/iOS/Android 的证书信任步骤,以及验收必须跑的三项检查——包括为什么「点继续前往」的自签证书仍然跑不了 webview。",
"short_description": "VS Code in the browser: code-server, HTTPS proxy, trusted certificate, verified.",
"short_description_zh": "浏览器版 VS Code:code-server + HTTPS 反代 + 证书信任 + 端到端验收。",
- "version": "2026.11.06.1",
+ "version": "2026.11.06.2",
"category": "software-development",
"preinstall": false
}
diff --git a/plugins/web-vscode/skills/web-vscode/SKILL.md b/plugins/web-vscode/skills/web-vscode/SKILL.md
index 92b418cc..daf854bf 100644
--- a/plugins/web-vscode/skills/web-vscode/SKILL.md
+++ b/plugins/web-vscode/skills/web-vscode/SKILL.md
@@ -121,6 +121,10 @@ node scripts/install.mjs uninstall # 停服务、删单元,文件留
node scripts/install.mjs uninstall --purge # 连 /opt/web-vscode 一起删
```
+只停「这个安装目录自己的」单元:`web-vscode*.service` 里 ExecStart 指向别的目录的一律跳过并提示,
+所以同机另一份安装或手工维护的入口不会被带走;单元名是固定的,装第二份时遇到别人的同名单元会拒绝覆盖
+(要覆盖加 `--force`)。
+
code-server 本体不会被卸(可能还有别的用途),要删自己 `npm rm -g code-server`。
## 参考资料
diff --git a/plugins/web-vscode/skills/web-vscode/scripts/install.mjs b/plugins/web-vscode/skills/web-vscode/scripts/install.mjs
index 48ac8bd7..aa0f699e 100644
--- a/plugins/web-vscode/skills/web-vscode/scripts/install.mjs
+++ b/plugins/web-vscode/skills/web-vscode/scripts/install.mjs
@@ -32,6 +32,9 @@ const PROXY_TEMPLATE = path.join(HERE, "proxy-server.js");
const SERVICE_CODE = "web-vscode.service";
const SERVICE_PROXY = "web-vscode-proxy.service";
+// 单元目录:默认 /etc/systemd/system。测这套逻辑时指到临时目录,别去碰真机的单元。
+const UNIT_DIR = process.env.WEB_VSCODE_UNIT_DIR || "/etc/systemd/system";
+
const DEFAULTS = {
prefix: "/opt/web-vscode",
port: 6666,
@@ -127,6 +130,18 @@ function localIPv4() {
return out;
}
+/**
+ * 一个单元文件是不是这个安装目录生成的:找 prefix,但要求它后面不是一个路径字符。
+ * 这样 /opt/web-vscode 不会命中 /opt/web-vscode-proxy —— 兄弟目录名太像,误判的代价是删掉别人的服务。
+ */
+function unitBelongsTo(body, prefix) {
+ for (let i = body.indexOf(prefix); i !== -1; i = body.indexOf(prefix, i + 1)) {
+ const next = body[i + prefix.length];
+ if (next === undefined || !/[A-Za-z0-9_-]/.test(next)) return true;
+ }
+ return false;
+}
+
function certFingerprint(file) {
const out = trySh("openssl", ["x509", "-in", file, "-noout", "-fingerprint", "-sha256"]);
return out ? out.split("=")[1] : null;
@@ -408,9 +423,21 @@ async function install(opts) {
// 5. 起服务
if (useSystemd) {
if (dry) {
- info(`将写入 /etc/systemd/system/${SERVICE_CODE} 与 ${SERVICE_PROXY},并 enable --now`);
+ info(`将写入 ${UNIT_DIR}/${SERVICE_CODE} 与 ${SERVICE_PROXY},并 enable --now`);
} else {
- const unitDir = "/etc/systemd/system";
+ const unitDir = UNIT_DIR;
+ // 单元名固定:同一台机器上装第二份会覆盖第一份的单元。已有的单元如果不是这个 prefix
+ // 生成的,说明另一份安装(或手工维护的入口)正在用它,宁可不装也不覆盖。
+ for (const unit of [SERVICE_CODE, SERVICE_PROXY]) {
+ const file = path.join(unitDir, unit);
+ if (
+ fs.existsSync(file) &&
+ !unitBelongsTo(fs.readFileSync(file, "utf8"), prefix) &&
+ !force
+ ) {
+ fail(`${file} 已存在且指向别的安装目录;先卸载那一份,或换 --prefix,或加 --force 覆盖`);
+ }
+ }
writeFile(path.join(unitDir, SERVICE_CODE), unitCodeServer(prefix, port, workspace), 0o644);
writeFile(path.join(unitDir, SERVICE_PROXY), unitProxy(prefix, tlsPort), 0o644);
sh("systemctl", ["daemon-reload"]);
@@ -527,12 +554,21 @@ function ca(opts) {
function uninstall(opts) {
const prefix = path.resolve(opts.prefix || DEFAULTS.prefix);
+ // 单元文件里写着它自己的安装目录。只停写着「这个 prefix」的单元:
+ // 同一台机器上另一个安装实例(或手工维护的入口)不能被一次 --prefix 清理带走。
for (const unit of [SERVICE_PROXY, SERVICE_CODE]) {
- if (trySh("systemctl", ["is-enabled", unit]) !== null) {
- trySh("systemctl", ["disable", "--now", unit]);
- fs.rmSync(`/etc/systemd/system/${unit}`, { force: true });
- ok(`已停止并删除 ${unit}`);
+ const file = path.join(UNIT_DIR, unit);
+ if (!fs.existsSync(file)) {
+ info(`${unit} 不存在,跳过`);
+ continue;
+ }
+ if (!unitBelongsTo(fs.readFileSync(file, "utf8"), prefix)) {
+ warn(`${unit} 指向的不是 ${prefix},不碰它(要停请手动 systemctl disable --now ${unit})`);
+ continue;
}
+ trySh("systemctl", ["disable", "--now", unit]);
+ fs.rmSync(file, { force: true });
+ ok(`已停止并删除 ${unit}`);
}
trySh("systemctl", ["daemon-reload"]);
const runDir = path.join(prefix, "run");