compose-website/unit-files/wordpress-discovery@.service
2014-11-07 15:58:27 +00:00

34 lines
800 B
Desktop File

[Unit]
Description=%p for %i etcd registration
# Requirements
Requires=etcd.service
# Dependency ordering
After=etcd.service
After=wordpress@%i.service
# Dependency binding
BindsTo=wordpress@%i.service
[Service]
# Start
## Test whether service is accessible and then register useful information
ExecStart=/bin/bash -c ' \
sleep 30; \
while true; do \
app=`echo %p | cut -d"-" -f1`; \
ip=`docker inspect --format \'{{.NetworkSettings.IPAddress}}\' $app-%i`; \
curl -f $ip; \
if [ $? -eq 0 ]; then \
etcdctl set /services/$app/%i \'{"ip":"\'$ip\'", "port":"80"}\' --ttl 60; \
else \
etcdctl rm /services/$app/%i; \
fi; \
sleep 50; \
done'
# Stop
ExecStop=-/bin/bash -euxc ' \
app=`echo %p | cut -d"-" -f1`; \
/usr/bin/etcdctl rm /services/$app/%i