Skip to content

Instantly share code, notes, and snippets.

@mdobson
Last active August 29, 2015 14:14
Show Gist options
  • Save mdobson/04246d9eff9b94d7b0b8 to your computer and use it in GitHub Desktop.
Save mdobson/04246d9eff9b94d7b0b8 to your computer and use it in GitHub Desktop.
Zetta Fleet Service
[Unit]
Description=Zetta API
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill zetta
ExecStartPre=-/usr/bin/docker rm zetta
ExecStartPre=/usr/bin/docker pull mdobson/zetta-docker
ExecStart=/usr/bin/docker run -rm --name zetta -p 80:3000 mdobson/zetta-docker
ExecStop=/usr/bin/docker stop zetta
[X-Fleet]
Conflicts=zetta@*.service
[Unit]
Description=Zetta Sidekick Process
Requires=etcd.service
Requires=zetta@%i.service
After=etcd.service
After=zetta@%i.service
BindsTo=zetta@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
curl -f ${COREOS_PUBLIC_IPV4}:80; \
if [ $? -eq 0]; then \
etcdctl set /services/zetta/${COREOS_PUBLIC_IPV4} \'{"host": "%H", "ipv4_addr":${COREOS_PUBLIC_IPV4}, "port": 80}\' --ttl 30; \
else \
etcdctl rm /services/zetta/${COREOS_PUBLIC_IPV4}; \
fi; \
sleep 20; \
done'
ExecStop=/usr/bin/etcdctl rm /services/zetta/${COREOS_PUBLIC_IPV4}
[X-Fleet]
X-ConditionMachineOf=zetta@%i.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment