Created
August 7, 2014 21:28
-
-
Save dspe/fdde479452b11b6f0bf7 to your computer and use it in GitHub Desktop.
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 | |
# Fail hard and fast | |
set -eo pipefail | |
export ETCD_PORT=${ETCD_PORT:-4001} | |
export HOST_IP=${HOST_IP:-172.17.42.1} | |
export ETCD=$HOST_IP:4001 | |
echo "[nginx] booting container. ETCD: $ETCD" | |
# Loop until confd has updated the nginx config | |
until confd -onetime -node $ETCD -config-file /etc/confd/conf.d/nginx.toml; do | |
echo "[nginx] waiting for confd to refresh nginx.conf" | |
sleep 5 | |
done | |
# Run confd in the background to watch the upstream servers | |
confd -interval 10 -node $ETCD -config-file /etc/confd/conf.d/nginx.toml & | |
echo "[nginx] confd is listening for changes on etcd..." | |
# Start nginx | |
echo "[nginx] starting nginx service..." | |
service nginx start | |
# Tail all nginx log files | |
tail -f /var/log/nginx/*.log |
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
[Unit] | |
Description=Hello World | |
After=docker.service | |
Requires=docker.service | |
[Service] | |
EnvironmentFile=/etc/environment | |
#ExecStartPre=/usr/bin/etcdctl set /ez/server/test.example.com/%m ${COREOS_PUBLIC_IPV4} | |
#ExecStart=/usr/bin/docker run --name test --rm -p :80 joshuaconner/hello-world-docker-bottle | |
ExecStart=/bin/bash -c '/usr/bin/docker start -a test || /usr/bin/docker run --rm --name test -p :80 joshuaconner/hello-world-docker-bottle' | |
ExecStartPost=/bin/bash -c '/usr/bin/etcdctl set /ez/server/test.example.com $(/usr/bin/docker port test 80)' | |
ExecStop=/usr/bin/etcdctl rm /ez/server/test.example.com | |
ExecStop=/usr/bin/docker kill test |
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
{{ range $server := .ez_server }} | |
server { | |
server_name {{ $server.Key }}; | |
location / { | |
proxy_pass {{ $server.Value }}; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-UP $remote_add; | |
proxy_set_header X-Forwarded-For $proxy_add_x_formwarded_for; | |
} | |
} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment