-
-
Save teebu/19d1317bd67f3df40d61c45514cb4192 to your computer and use it in GitHub Desktop.
Resolve ELB IPs and create a dynamic Varnish backend list (intended to run out of cron).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ... | |
| include "dynamic_backends.vcl"; | |
| # ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| elb_hostname=${elb_hostname:-myapp.herokuapp.com} | |
| backend_vcl=${backend_vcl:-/etc/varnish/dynamic_backends.vcl} | |
| ips=$(ruby -rresolv -e "puts Resolv::DNS.new.getaddresses('$elb_hostname').map(&:to_s)") | |
| # clear out existing backends | |
| cat <<EOF > $backend_vcl | |
| director my_backend round-robin { | |
| EOF | |
| # create a new backends.vcl | |
| for ip in $ips; do | |
| cat <<EOF >> $backend_vcl | |
| { | |
| .backend = { | |
| .host = "$ip"; | |
| .port = "http"; | |
| } | |
| } | |
| EOF | |
| done | |
| cat <<EOF >> $backend_vcl | |
| } | |
| EOF | |
| # restart varnish | |
| /etc/init.d/varnish reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment