Skip to content

Commit 49c92f1

Browse files
newbe36524Copilot
andcommitted
fix(code-server): use cmd.exe to launch code-server via PM2 on Windows
PowerShell's execution policy and process tracking make .ps1 + --interpreter powershell.exe unreliable in PM2: the process exits immediately with no logs (14 unstable restarts). Switch to .cmd wrapper launched via explicit cmd.exe /d /s /c, which: - Runs node synchronously (cmd.exe waits for node to exit) - PM2 tracks cmd.exe and sees it as online while node runs - Avoids any PowerShell execution policy issues Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dfc4012 commit 49c92f1

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

packages/code-server/scripts/verify-startup.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async function assertPackagedEntrypoints(runtimeRoot) {
172172
}
173173

174174
export function getNativeSmokeEntrypoint(runtimeRoot, hostPlatform = process.platform) {
175-
return path.join(runtimeRoot, "bin", hostPlatform === "win32" ? "code-server.ps1" : "code-server")
175+
return path.join(runtimeRoot, "bin", hostPlatform === "win32" ? "code-server.cmd" : "code-server")
176176
}
177177

178178
function getPm2Command(hostPlatform = process.platform) {
@@ -181,10 +181,13 @@ function getPm2Command(hostPlatform = process.platform) {
181181

182182
function getPm2WrapperStartCommand(wrapperPath, hostPlatform = process.platform) {
183183
if (hostPlatform === "win32") {
184+
// Use cmd.exe explicitly so PM2 tracks the cmd process (which stays alive
185+
// while node runs synchronously inside the .cmd wrapper).
186+
const cmdExe = process.env.ComSpec || "C:\\Windows\\System32\\cmd.exe"
184187
return {
185-
command: wrapperPath,
186-
pm2Args: ["--interpreter", "powershell.exe"],
187-
runtimeArgs: [],
188+
command: cmdExe,
189+
pm2Args: ["--interpreter", "none"],
190+
runtimeArgs: ["/d", "/s", "/c", wrapperPath],
188191
}
189192
}
190193

packages/code-server/scripts/verify-startup.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test("findReleaseRoot locates the extracted release by entrypoint", async () =>
3939
test("getNativeSmokeEntrypoint selects platform-specific wrappers", () => {
4040
assert.equal(getNativeSmokeEntrypoint("/tmp/release", "linux"), path.join("/tmp/release", "bin", "code-server"))
4141
assert.equal(getNativeSmokeEntrypoint("/tmp/release", "darwin"), path.join("/tmp/release", "bin", "code-server"))
42-
assert.equal(getNativeSmokeEntrypoint("C:\\temp\\release", "win32"), path.join("C:\\temp\\release", "bin", "code-server.ps1"))
42+
assert.equal(getNativeSmokeEntrypoint("C:\\temp\\release", "win32"), path.join("C:\\temp\\release", "bin", "code-server.cmd"))
4343
})
4444

4545
test("resolveSpawnInvocation routes Windows PowerShell wrappers through powershell.exe", () => {

0 commit comments

Comments
 (0)