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.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

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.