Skip to content

Instantly share code, notes, and snippets.

@mhamrah
Last active September 27, 2020 17:54
Show Gist options
  • Save mhamrah/255c35c450077d899600 to your computer and use it in GitHub Desktop.
Save mhamrah/255c35c450077d899600 to your computer and use it in GitHub Desktop.
FleetCtl Service File for Consul/Docker on CoreOS
[Unit]
Description=Consul Discovery
BindsTo=consul@%i.service
After=consul@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/sh -c "while true; do etcdctl mk /services/consul $COREOS_PUBLIC_IPV4 --ttl 60;/usr/bin/docker exec consul consul join $(etcdctl get /services/consul);sleep 45;done"
ExecStop=/usr/bin/etcdctl rm /services/consul --with-value %H
[X-Fleet]
MachineOf=consul@%i.service
[Unit]
Description=Consul
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
EnvironmentFile=/etc/environment
ExecStartPre=-/usr/bin/docker kill consul
ExecStartPre=-/usr/bin/docker rm consul
ExecStartPre=/usr/bin/docker pull progrium/consul
ExecStartPre=-/usr/bin/etcdctl mk /consul $COREOS_PUBLIC_IPV4
ExecStart=/usr/bin/docker run --rm --name consul -h %H -p "$(COREOS_PUBLIC_IPV4)":8300:8300 -p "$(COREOS_PUBLIC_IPV4)":8301:8301 -p "$(COREOS_PUBLIC_IPV4)":8301:8301/udp -p "$(COREOS_PUBLIC_IPV4)":8302:8302 -p "$(COREOS_PUBLIC_IPV4)":8302:8302/udp -p "$(COREOS_PUBLIC_IPV4)":8400:8400 -p "$(COREOS_PUBLIC_IPV4)":8500:8500 -p 10.1.42.1:53:53/udp progrium/consul -server -bootstrap-expect 3 -advertise $COREOS_PUBLIC_IPV4
[X-Fleet]
Conflicts=consul@*.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment