Skip to content

Instantly share code, notes, and snippets.

@popsikle
Last active August 29, 2015 14:13
Show Gist options
  • Save popsikle/1c782d28931cc676b218 to your computer and use it in GitHub Desktop.
Save popsikle/1c782d28931cc676b218 to your computer and use it in GitHub Desktop.
Port Enabled Sidekick Announcement
[Unit]
Description=Web App
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill web_app-%i
ExecStartPre=-/usr/bin/docker rm web_app-%i
ExecStartPre=/usr/bin/docker pull tutum/hello-world
ExecStart=/usr/bin/docker run -rm --name web_app-%i -p 80 tutum/hello-world
ExecStop=/usr/bin/docker stop web_app-%i
[X-Fleet]
Conflicts=web_app@*.service
[Unit]
Description=Announce Web App
BindsTo=web_app@%i.service
After=web_app@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c 'PORT=`docker port web_app-%i 80 | cut -f2 -d:`; while true; do etcdctl set /services/web/app@%i \'{"ip": "${COREOS_PRIVATE_IPV4}", "port": \'"$PORT"\' }\' --ttl 60; sleep 45; done'
ExecStop=/usr/bin/etcdctl rm /services/web/app@%i
[X-Fleet]
MachineOf=web_app@%i.service
@popsikle
Copy link
Author

The latest revision now works!

ip-172-29-2-108 ~ # etcdctl get /services/web/app@1
{ host: ip-172-29-2-108.us-west-2.compute.internal, ip: 172.29.2.108, port: 49156 }

ip-172-29-2-108 ~ # etcdctl get /services/web/app@2
{ host: ip-172-29-4-26.us-west-2.compute.internal, ip: 172.29.4.26, port: 49153 }

ip-172-29-2-108 ~ # etcdctl get /services/web/app@3
{ host: ip-172-29-2-109.us-west-2.compute.internal, ip: 172.29.2.109, port: 49155 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment