DevOps / Scripts
bash
Advanced
Blue-Green Deploy Script
Switch traffic between two app instances with zero downtime using Nginx upstream.
bash
#!/bin/bash
ACTIVE=$(cat /etc/nginx/active_slot)
NEXT=$([ "$ACTIVE" = blue ] && echo green || echo blue)
echo Deploying to $NEXT slot
systemctl start app-$NEXT
nginx -s reload
systemctl stop app-$ACTIVE
echo $NEXT > /etc/nginx/active_slot
Prerequisites
- Nginx
- Two app instances
Pro Tips
- → Add health check before switching slots.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- bash
- Level
- Advanced
- Read time
- 5 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