I have a CoreOS cluster in which i have a SystemD service that just run a Docker container. However, for flexibility purpose, i want the Docker Registry the container gets pulled from to be discovered when the service start, what i do easily using Etcd (the node discovery system from the CoreOS project).
So, i tried it in a normal terminal, what just gives me a command like this /usr/bin/etcdctl get /services/registry
to get the current IP address of the registry. And it works! But from a SystemD service, the command is returned as typed and not executed as someone should do in a Shell script with backticks. I tried backticks, $()
and ${}
syntaxes but the command is still returned as is.
If anybody has a suggestion, i'm taking it 🙂 Thanks!
Best Answer
If you make your ExecStart use
/bin/sh -c "echo $(etcdctl ls /)"
it will perform in the way that you desire.Here's a full unit file taking advantage of this: https://github.com/coreos/unit-examples/blob/master/simple-fleet/apache-discovery.2.service#L6