Skip to content
Snippets Groups Projects
wordpress-discovery@.service 800 B
Newer Older
[Unit]
Description=%p for %i etcd registration

# Requirements
Requires=etcd.service

Pierre Ozoux's avatar
Pierre Ozoux committed
# Dependency ordering
After=etcd.service
After=wordpress@%i.service
Pierre Ozoux's avatar
Pierre Ozoux committed

# Dependency binding
BindsTo=wordpress@%i.service

[Service]
# Start
## Test whether service is accessible and then register useful information
Pierre Ozoux's avatar
Pierre Ozoux committed
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 \
Pierre Ozoux's avatar
Pierre Ozoux committed
      etcdctl set /services/$app/%i \'{"ip":"\'$ip\'", "port":"80"}\' --ttl 60; \
    else \
      etcdctl rm /services/$app/%i; \
    fi; \
Pierre Ozoux's avatar
Pierre Ozoux committed
    sleep 50; \
ExecStop=-/bin/bash -euxc ' \
Pierre Ozoux's avatar
Pierre Ozoux committed
  app=`echo %p | cut -d"-" -f1`; \
  /usr/bin/etcdctl rm /services/$app/%i