How to wait for an etcd variable is set before starting the unit/service
<p>I am currently working on logging with the ELK (Elasticsearch, Logstash, Kibana) stack in an CoreOS cluster. I found out, you can use gelf to automatically send the logs from docker to logstash. I am using a sidekick to write a etcd variable of the logstash container IP address. Since I have to pass the IP of logstash to a flag in the docker run command I need to wait until the variable is set.</p>

<p>My question is how can I wait until <code>etcdctl get /network/logstash</code> returns the IP address.</p>

<p>This is how my unit-file looks at the moment:</p>

<pre><code>[Unit]
Description=nginx with elk logging
After=logstash-discovery.service
Requires=docker.service

[Service]
TimeoutStartSec=0
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment ADDR=$(etcdctl get /network/logstash)"
ExecStartPre=-/usr/bin/docker kill nginx1
ExecStartPre=-/usr/bin/docker rm nginx1
ExecStartPre=/usr/bin/docker pull 10.0.2.2:5000/nginx
ExecStart=/usr/bin/docker run -p 80:80 --name=nginx1 --net=host --log-driver=gelf --log-opt gelf-address=udp://${ADDR}:12201 --log-opt gelf-tag="fe" 10.0.2.2:5000/nginx
ExecStop=/usr/bin/docker stop nginx1

[X-Fleet]
Conflicts=logstash.service
</code></pre>