Skip to content

Commit fe8a3c2

Browse files
committed
Merge pull request #1269 from deis/1251-fix_portless_apps
fix(scheduler/coreos): fix apps announcing themselves with no port
2 parents 5f16997 + 0da0f80 commit fe8a3c2

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

controller/scheduler/coreos.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def create(self, name, image, command='', template=None):
5656
env = self.env.copy()
5757
self._create_container(name, image, command, template or CONTAINER_TEMPLATE, env)
5858
self._create_log(name, image, command, LOG_TEMPLATE, env)
59-
self._create_announcer(name, image, command, ANNOUNCE_TEMPLATE, env)
59+
60+
# only announce web and cmd processes
61+
if command.lower() in ['start web', '']:
62+
self._create_announcer(name, image, command, ANNOUNCE_TEMPLATE, env)
63+
else:
64+
print "-- skipping announcer for {} - cmd type is {}".format(name,command)
6065

6166
def _create_container(self, name, image, command, template, env):
6267
l = locals().copy()
@@ -202,14 +207,15 @@ def attach(self, name):
202207
TimeoutStartSec=20m
203208
"""
204209

210+
# TODO revisit the "not getting a port" issue after we upgrade to Docker 1.1.0
205211
ANNOUNCE_TEMPLATE = """
206212
[Unit]
207213
Description={name} announce
208214
BindsTo={name}.service
209215
210216
[Service]
211217
EnvironmentFile=/etc/environment
212-
ExecStartPre=/bin/sh -c "until docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name} >/dev/null 2>&1; do sleep 2; done; port=$(docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); echo Waiting for $port/tcp...; until netstat -lnt | grep :$port >/dev/null; do sleep 1; done"
218+
ExecStartPre=/bin/sh -c "until docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name} >/dev/null 2>&1; do sleep 2; done; port=$(docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); if [[ -z $port ]]; then echo We have no port...; exit 1; fi; echo Waiting for $port/tcp...; until netstat -lnt | grep :$port >/dev/null; do sleep 1; done"
213219
ExecStart=/bin/sh -c "port=$(docker inspect -f '{{{{range $i, $e := .HostConfig.PortBindings }}}}{{{{$p := index $e 0}}}}{{{{$p.HostPort}}}}{{{{end}}}}' {name}); echo Connected to $COREOS_PRIVATE_IPV4:$port/tcp, publishing to etcd...; while netstat -lnt | grep :$port >/dev/null; do etcdctl set /deis/services/{app}/{name} $COREOS_PRIVATE_IPV4:$port --ttl 60 >/dev/null; sleep 45; done"
214220
ExecStop=/usr/bin/etcdctl rm --recursive /deis/services/{app}/{name}
215221

0 commit comments

Comments
 (0)