-
Notifications
You must be signed in to change notification settings - Fork 0
PM2 Process Management
HMAHD edited this page Jan 31, 2026
·
1 revision
Guide for managing Luvora processes with PM2.
From ecosystem.config.js:
{
name: 'luvora-production-3002',
script: 'node_modules/next/dist/bin/next',
args: 'start',
cwd: '/home/luvora-production/Luvora',
env: {
NODE_ENV: 'production',
PORT: 3002,
},
instances: 1,
exec_mode: 'cluster',
}{
name: 'luvora-staging-3003',
script: 'node_modules/next/dist/bin/next',
args: 'start',
cwd: '/home/luvora-staging/Luvora',
env: {
NODE_ENV: 'production',
PORT: 3003,
},
instances: 1,
exec_mode: 'cluster',
}# List all processes
pm2 list
# Start a process
pm2 start ecosystem.config.js --only luvora-production-3002
# Stop a process
pm2 stop luvora-production-3002
# Restart a process (with downtime)
pm2 restart luvora-production-3002
# Reload a process (zero-downtime)
pm2 reload luvora-production-3002
# Delete a process
pm2 delete luvora-production-3002# View logs (live)
pm2 logs luvora-production-3002
# View logs (last 50 lines)
pm2 logs luvora-production-3002 --lines 50
# View only error logs
pm2 logs luvora-production-3002 --err
# Real-time monitoring dashboard
pm2 monit
# Detailed process info
pm2 show luvora-production-3002# Save current process list
pm2 save
# Setup PM2 to start on boot
pm2 startup
# This will output a command to run with sudo
# Copy and run that command
# After running the startup command, save again
pm2 save# Reload with updated environment variables
pm2 reload luvora-production-3002 --update-env
# Restart with updated environment variables
pm2 restart luvora-production-3002 --update-env# Check logs for errors
pm2 logs luvora-production-3002 --lines 100
# Check if port is already in use
sudo lsof -i :3002
# Delete and restart
pm2 delete luvora-production-3002
pm2 start ecosystem.config.js --only luvora-production-3002# Check resource usage
pm2 list
# View detailed metrics
pm2 show luvora-production-3002
# Reload to clear memory
pm2 reload luvora-production-3002# View error logs
pm2 logs luvora-production-3002 --err --lines 200
# Check if .env.local exists
ls -la /home/luvora-production/Luvora/.env.local
# Verify build is successful
cd /home/luvora-production/Luvora
bun run build
# Check Node/Bun version
node --version
bun --version-
Always use
reloadinstead ofrestartfor zero-downtime deployments -
Run
pm2 saveafter making changes to persist configuration - Check logs before and after deployments to catch issues early
-
Use
--update-envflag when environment variables change -
Monitor resource usage regularly with
pm2 list
# Clear all logs
pm2 flush
# Rotate logs (requires pm2-logrotate)
pm2 install pm2-logrotate# Enable metrics collection
pm2 install pm2-metrics
# View web dashboard
pm2 webTo run multiple instances for load balancing, update ecosystem.config.js:
{
instances: 2, // or 'max' for CPU count
exec_mode: 'cluster',
}Then reload:
pm2 reload luvora-production-3002