pm2 save fix + test work
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 27m44s

This commit is contained in:
2026-02-18 15:39:27 -08:00
parent 743216ef1b
commit fe79522ea4
14 changed files with 194 additions and 30 deletions

View File

@@ -249,26 +249,39 @@ module.exports = {
### PM2 Commands Reference
**CRITICAL**: Every `pm2 start`, `pm2 restart`, `pm2 stop`, or `pm2 delete` command MUST be immediately followed by `pm2 save`. Without this, processes become ephemeral and will disappear on PM2 daemon restarts, server reboots, or internal reconciliation events.
```bash
# Start/reload with environment
# ✅ CORRECT - Start/reload with environment and save
pm2 startOrReload ecosystem.config.cjs --env production --update-env && pm2 save
# ✅ CORRECT - Restart and save
pm2 restart flyer-crawler-api && pm2 save
# ✅ CORRECT - Stop and save
pm2 stop flyer-crawler-api && pm2 save
# ✅ CORRECT - Delete and save
pm2 delete flyer-crawler-api && pm2 save
# ❌ WRONG - Missing save (processes become ephemeral)
pm2 startOrReload ecosystem.config.cjs --env production --update-env
# Save process list for startup
pm2 save
# View logs
# View logs (read-only operation, no save needed)
pm2 logs flyer-crawler-api --lines 50
# Monitor processes
# Monitor processes (read-only operation, no save needed)
pm2 monit
# List all processes
# List all processes (read-only operation, no save needed)
pm2 list
# Describe process details
# Describe process details (read-only operation, no save needed)
pm2 describe flyer-crawler-api
```
**Why This Matters**: PM2 maintains an in-memory process list. The `pm2 save` command writes this list to `~/.pm2/dump.pm2`, which PM2 uses to resurrect processes after daemon restarts. Without it, your carefully managed process state is lost.
### Resource Limits
| Process | Memory Limit | Restart Delay | Kill Timeout |

View File

@@ -115,6 +115,31 @@ echo "=== END POST-CLEANUP VERIFICATION ==="
**Purpose**: Immediately identifies cross-environment contamination.
#### Layer 6: PM2 Process List Persistence
**CRITICAL**: Save the PM2 process list after every state-changing operation:
```bash
# After any pm2 start/stop/restart/delete operation
pm2 save
# Example: After cleanup loop completes
targetProcesses.forEach(p => {
exec('pm2 delete ' + p.pm2_env.pm_id);
});
exec('pm2 save'); // Persist all deletions
```
**Purpose**: Ensures PM2 process state persists across daemon restarts, server reboots, and internal reconciliation events.
**Why This Matters**: PM2 maintains an in-memory process list. Without `pm2 save`, processes become ephemeral:
- Daemon restart → All unsaved processes disappear
- Server reboot → Process list reverts to last saved state
- PM2 internal reconciliation → Unsaved processes may be lost
**Pattern**: Every `pm2 start`, `pm2 restart`, `pm2 stop`, or `pm2 delete` MUST be followed by `pm2 save`.
## Consequences
### Positive