nowk
7/26/2015 - 5:20 PM

app-redis-sk.service

[Unit]
Description=App Redis Sidekick
Requires=docker.service
Requires=etcd.service

After=docker.service
After=etcd.service
After=app-redis.service
BindsTo=app-redis.service

[Service]
EnvironmentFile=/etc/environment
User=core

TimeoutStartSec=0
ExecStart=/bin/bash -c '\
  while true; do \
    port=$(docker inspect --format=\'{{(index (index .NetworkSettings.Ports "6379/tcp") 0).HostPort}}\' app-redis.service); \
    etcdctl set /services/app-redis/dfw ${COREOS_PRIVATE_IPV4}:$port --ttl 10; \
    sleep 5; \
    done'

ExecStop=/usr/bin/etcdctl rm /services/app-redis/dfw


[X-Fleet]
MachineOf=app-redis.service
[Unit]
Description=App Redis
After=docker.service
Requires=docker.service
Requires=app-redis-sk.service

[Service]
EnvironmentFile=/etc/environment

TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker kill %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull redis
ExecStart=/usr/bin/docker run --name %n -p ${COREOS_PRIVATE_IPV4}::6379 redis:latest redis-server --requirepass XYZ1234
ExecStop=/usr/bin/docker stop %n