fix(cli): avoid self-killing code-server launcher

This commit is contained in:
Vincent Koc 2026-05-05 00:22:08 -07:00
parent 8ccf1a3f89
commit c18913b79d
No known key found for this signature in database
2 changed files with 8 additions and 3 deletions

View File

@ -168,13 +168,14 @@ func codeServerReadyCommand() string {
}
func startCodeServerCommand(workdir string) string {
pidfile := "/tmp/crabbox-code-server.pid"
return strings.Join([]string{
"mkdir -p " + shellQuote(workdir),
"pkill -f '" + codeServerBinary + ".*127.0.0.1:" + managedCodePort + "' >/dev/null 2>&1 || true",
"nohup env VSCODE_PROXY_URI='./proxy/{{port}}' " + codeServerBinary +
"pidfile=" + shellQuote(pidfile) + "; if [ -s \"$pidfile\" ]; then oldpid=$(cat \"$pidfile\" 2>/dev/null || true); if [ -n \"$oldpid\" ] && kill -0 \"$oldpid\" 2>/dev/null; then kill \"$oldpid\" 2>/dev/null || true; fi; fi",
"(nohup env VSCODE_PROXY_URI='./proxy/{{port}}' " + codeServerBinary +
" --auth none --bind-addr 127.0.0.1:" + managedCodePort +
" --disable-telemetry --disable-update-check " + shellQuote(workdir) +
" >/tmp/crabbox-code-server.log 2>&1 &",
" >/tmp/crabbox-code-server.log 2>&1 & echo $! >" + shellQuote(pidfile) + ")",
}, " && ")
}

View File

@ -38,9 +38,13 @@ func TestStartCodeServerCommand(t *testing.T) {
"--bind-addr 127.0.0.1:8080",
"VSCODE_PROXY_URI='./proxy/{{port}}'",
"/tmp/crabbox-code-server.log",
"/tmp/crabbox-code-server.pid",
} {
if !strings.Contains(got, want) {
t.Fatalf("startCodeServerCommand missing %q:\n%s", want, got)
}
}
if strings.Contains(got, "pkill -f") {
t.Fatalf("startCodeServerCommand should not use pkill -f:\n%s", got)
}
}