Commit 91e67bbe authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

fix common funcs

parent cdf83ddc
......@@ -618,9 +618,6 @@ class DockerController:
self.sock.listen(32)
self.sock.setblocking(False)
loop = asyncio.get_event_loop()
loop.add_reader(self.sock, self._sock_callback)
self.image_manager = ImageManager(self)
self.sandbox_manager = SandboxManager(self)
......@@ -642,18 +639,32 @@ class DockerController:
return "%s-sandbox-%s" % (self.env, webapp.docker_name)
def gen_image_name(self, webapp):
return "%s/webapp/%s" % (self.env, webapp.docker_name)
return "%s/webapp/%s" % (self.registry, webapp.docker_name)
def check_host_path(self, funcname, path, *, nolink=True):
"""Validate a path before using it as an external volume in docker
- ensure the path is canonical:
- it is absolute
- it does not contain any '..' parts
- it does not contain any symbolic link
- ensure the path is of the right type (call os.path.`funcname`())
"""
if not os.path.isabs(path):
raise Error("host path %r is not absolute" % path)
if path != os.path.normpath(path):
raise Error("host path %r is not canonical (os.path.normpath())")
ctrpath = "/vol/host" + path
log.debug("ctrpath %r", ctrpath)
func = getattr(os.path, funcname)
if nolink and os.path.realpath(ctrpath) != os.path.normpath(ctrpath):
raise Error("host path %r uses a symbolic link" % path)
raise Error("host path %r contains a symbolic link" % path)
if not func(ctrpath):
raise Error("host path %r not found (os.path.%s())" % (path, funcname))
......@@ -692,6 +703,9 @@ class DockerController:
def shutdown(self):
#TODO: graceful shutdown
# - close socket
# - wait for all managers to finish their running tasks
# - cancel other tasks
self._finished.set_result(None)
def run(self):
......@@ -702,6 +716,7 @@ class DockerController:
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGTERM, self.shutdown)
loop.add_signal_handler(signal.SIGINT, self.shutdown)
loop.add_reader(self.sock, self._sock_callback)
self.check_db()
loop.run_until_complete(self._finished)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment