Skip to content

Instantly share code, notes, and snippets.

@zilin
Last active August 29, 2015 14:01
Show Gist options
  • Save zilin/4994db87e41de1c35364 to your computer and use it in GitHub Desktop.
Save zilin/4994db87e41de1c35364 to your computer and use it in GitHub Desktop.
#############################
# apache.service
#############################
[Unit]
Description=My Apache Frontend
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/docker run --name apache -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
ExecStop=/usr/bin/docker stop apache
[X-Fleet]
X-Conflicts=apache@*.service
#############################
# apache-discovery.service
#############################
[Unit]
Description=Announce Apache 1
BindsTo=apache@1.service
[Service]
ExecStart=/bin/bash -c "HOST_IP=$(/bin/ifconfig enp0s8 | awk '/inet /{print $2}') && CONTAINER_PORT=$(docker inspect apache | grep -m 1 HostPort | tr -d ' ' | cut -d: -f2 | tr -d '\"') && while true; do etcdctl set /services/web/%H \"{ \\\"host\\\": \\\"$HOST_IP\\\", \\\"port\\\": \\\"$CONTAINER_PORT\\\"}\" --ttl 60;sleep 45;done"
ExecStop=/usr/bin/etcdctl rm /services/web/%H
[X-Fleet]
X-ConditionMachineOf=apache@1.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment