feat(startup): embed Bun runtime in generated init script when running under Bun - #6139
Open
leonardoag2026-beep wants to merge 1 commit into
Open
Conversation
…g under Bun When PM2 runs under Bun (cst.IS_BUN), the 'pm2 startup' command now prefixes the pm2 binary path with process.execPath (the Bun runtime) in both the copy/paste command hint and the generated init script. Without this, the init script starts the PM2 daemon with the shebang interpreter (node), which breaks cluster mode for Bun applications (ERR_UNKNOWN_FILE_EXTENSION: Unknown file extension ".ts"). With this change, running 'pm2 startup' under Bun generates: ExecStart=/path/to/bun /path/to/pm2/bin/pm2 resurrect while behavior under Node.js is unchanged. Also unifies the isNotRoot() hint to use the resolved pm2 binary path instead of the hardcoded 'pm2' string when --user is passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When PM2 is run under Bun (
cst.IS_BUN), thepm2 startupcommand now embeds the Bun runtime (process.execPath) in front of the pm2 binary path — both in the copy/paste command hint and in the generated init script (%PM2_PATH%).Without this, the init script starts the PM2 daemon with the shebang interpreter (
node), which breaks cluster mode for Bun applications:Before / After
Running
pm2 startupunder Bun now generates:Behavior under Node.js is unchanged (verified:
ExecStartstill the bare pm2 binary path).Why this matters
Per the PM2 Bun docs: "Cluster mode follows the runtime of the PM2 daemon itself" — to load-balance a Bun app you must run PM2 with Bun (
bunx --bun pm2 start app.ts -i max). If the init script boots the daemon with node, Bun cluster apps saved viapm2 savefail on reboot. This PR makespm2 startupproduce a Bun-runtime init script automatically when PM2 is running under Bun.Also unifies the
isNotRoot()hint to use the resolved pm2 binary path instead of the hardcoded'pm2'string when--useris passed.Testing
pm2 startupunder Node → command hint and unit unchanged (no regression)pm2 startupunder Bun (bun bin/pm2 startup) → hint showsbun <pm2_bin>, generated systemd unit hasExecStart=/path/to/bun .../pm2/bin/pm2 resurrect(verified with a real unit generation + cleanup)npm run test:unit— only pre-existing flaky testexp_backoff_restart_delay.mocha.jsfails (fails identically without this change; the project's own runner retries it)Related issues: #5893, #5777, #5967 (cluster mode with Bun).