CLI: Rename process manager home from .studio/pm2 to .studio/daemon#3143
CLI: Rename process manager home from .studio/pm2 to .studio/daemon#3143
Conversation
📊 Performance Test ResultsComparing 917b494 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
epeicher
left a comment
There was a problem hiding this comment.
Thanks for removing leftovers about pm2 and adding the migration 👌. I have tested it, and I can confirm that the three scenarios work as expected. The end result is always the pm2 removed and the demon folder added successfully. LGTM!
| Fresh install | Upgrade path | Both folders exist |
|---|---|---|
![]() |
![]() |
![]() |
I have observed that the migration includes existing files like pm2.log or pm2.pid, should we include them too?
…m:Automattic/studio into stu-1390-rename-process-manager-home-path
|
@epeicher thanks for the review!
What do you think? FYI: I also dropped the merge scenario, I don't think there's a real use case where the user would have both folders. |
Thanks for the explanation, I agree on both of these points! |



Related issues
How AI was used in this PR
Built collaboratively with Claude Code. I drove the design decisions (folder name, migration approach, what's in/out of scope) and reviewed each change. Claude handled the mechanical rename, the migration, and the tests. I ran eslint, targeted typecheck, and the tests after each step. After a first round, testing surfaced a race between an import-time
mkdirSyncindaemon-client.tsand the yargs migrations middleware — I diagnosed the bug, Claude fixed it.Proposed Changes
Follow-up to the review thread on #2712 — the
PROCESS_MANAGER_HOMEdefault folder was namedpm2purely for back-compat, even though we no longer use pm2. This renames the folder and adds a migration so existing installations move cleanly.apps/cli/lib/paths.ts— change the default folder from~/.studio/pm2to~/.studio/daemon. The env varSTUDIO_PROCESS_MANAGER_HOMEis unchanged (the name is already neutral).apps/studio/src/ipc-handlers.ts— the main process had a duplicate hardcodedPM2_HOMEconstant and areadPm2Logshelper. Renamed both toPROCESS_MANAGER_HOME/readProcessManagerLogsand updated the path.apps/cli/lib/daemon-client.ts— the module previously had a top-levelfs.mkdirSync(PROCESS_MANAGER_HOME, …)side effect that ran at import time, before the yargs middleware ever calledrunMigrations. That caused the new folder to be created before the migration could check for it, so the rename silently skipped. Moved themkdirSyncinto a lazyensureProcessManagerHome()helper invoked fromconnectToDaemon().apps/cli/migrations/03-rename-pm-home.ts— new migration. If~/.studio/pm2/exists and~/.studio/daemon/does not,fs.renameSyncthe legacy folder to the new path. The rename preserves everything (including legacypm2.log/pm2.pidartifacts from older Studio versions that actually ran pm2 — harmless to keep, and migrations shouldn't second-guess what the user had).apps/cli/migrations/tests/03-rename-pm-home.test.ts— 5 tests covering the no-op cases, the rename, and content preservation.Why
daemon?It matches the file names already inside the folder (
daemon.sock,daemon-events.sock,process-manager-daemon.ts). Short, concrete, and reads naturally (~/.studio/daemon/logs/…).What's out of scope
Log rotation — the linked issue also mentions that pm2 gave us rotation for free and we should think about replacing it. That's already handled in #3132, so not bundled here.
Migration numbering note
I used
03-because #3132 already claims02-. The two migrations are independent — order doesn't affect correctness. Whichever lands second will need a trivial rebase to register both inapps/cli/migrations/index.ts.Testing Instructions
Build the CLI first:
npm run cli:build. Then runnode apps/cli/dist/cli/main.mjs site list(or any command that starts the daemon).1. Fresh install:
~/.studio/daemon/and~/.studio/pm2/if present.~/.studio/daemon/is created withdaemon.sock,daemon-events.sock, andlogs/. No~/.studio/pm2/should appear.2. Upgrade path (existing
pm2folder):~/.studio/pm2/with a few dummy files (e.g.logs/site-test-out.log,pm-connection.lock, and even apm2.logto confirm it comes along).~/.studio/daemon/if present.~/.studio/pm2/is gone and~/.studio/daemon/has all the preserved files.Pre-merge Checklist
apps/uiandapps/cli/logger.tspersist from trunk — not introduced here.)