DevOps / Scripts
bash
Advanced
Rolling Restart for Node Cluster
Restart a PM2 Node.js cluster one instance at a time to avoid downtime.
bash
#!/bin/bash
APP_NAME=myapp
INSTANCES=$(pm2 list --no-color | grep $APP_NAME | wc -l)
for i in $(seq 0 $((INSTANCES-1))); do
pm2 restart $APP_NAME --only $i
sleep 3
echo Restarted instance $i
done
Prerequisites
- PM2
- Node.js cluster
Pro Tips
- → Check health endpoint between restarts.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- bash
- Level
- Advanced
- Read time
- 4 min
- Published
- May 2024
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Postgres S3 Backup
Dump a Postgres database, gzip it, push to S3 with AES256 encryption.
bash
·
Intermediate
Disk Usage Alert
Send an alert when any mounted filesystem exceeds a usage threshold.
bash
·
Beginner
Docker Image Cleanup Script
Remove dangling images, stopped containers and unused volumes in one pass.
bash
·
Intermediate