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 bash string works fine outside of fleet, but once submitted via fleet I get this in the logs:

Jan 15 16:11:03 ip-xxx.us-west-2.compute.internal systemd[1]: Started Announce Web App.

Jan 15 16:11:03 ip-xxx.us-west-2.compute.internal bash[20877]: Template parsing error: template: :1: unexpected "/" in operand; missing space?

Jan 15 16:11:03 ip-xxx.us-west-2.compute.internal bash[20877]: time="2015-01-15T16:11:03Z" level="info" msg="Template parsing error: template: :1: unexpected "/" in operand; missing space?"

Jan 15 16:11:03 ip-xxx.us-west-2.compute.internal bash[20877]: { host: ip-xxx.us-west-2.compute.internal, port: }

@popsikle
Copy link
Author

NAME=CoreOS
ID=coreos
VERSION=557.0.0
VERSION_ID=557.0.0
BUILD_ID=
PRETTY_NAME="CoreOS 557.0.0"
ANSI_COLOR="1;32"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"

@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