[Unit] Description=%p for %i etcd registration # Requirements Requires=etcd.service # Dependency binding BindsTo=u@%i.service [Service] Type=oneshot RemainAfterExit=yes Environment=URL=%i ExecStart=/bin/bash -xc ' \ ip=""; \ while [ -z $ip ]; \ do \ container_name=`echo ${URL}_web_1 | sed "s/\.//g" | sed "s/-//g"`; \ ip=`docker inspect --format \'{{.NetworkSettings.IPAddress}}\' $container_name`; \ sleep 1; \ done; \ etcdctl --peers 172.17.42.1:4001 set /services/web/%i \'{"ip":"\'$ip\'", "port":"80"}\';' ExecStop=-/usr/bin/etcdctl rm /services/web/%i