add /api/shutdown handler

POST /api/shutdown triggers clean shutdown.
URL parameters allow specifying whether servers and/or proxy should be cleaned up.
This commit is contained in:
Min RK
2015-02-27 13:57:34 -08:00
parent daeb650228
commit 71ada39027
3 changed files with 64 additions and 4 deletions

View File

@@ -846,6 +846,7 @@ class JupyterHub(Application):
@gen.coroutine
def cleanup(self):
"""Shutdown our various subprocesses and cleanup runtime files."""
futures = []
if self.cleanup_servers:
self.log.info("Cleaning up single-user servers...")
@@ -868,7 +869,7 @@ class JupyterHub(Application):
yield f
except Exception as e:
self.log.error("Failed to stop user: %s", e)
self.db.commit()
if self.pid_file and os.path.exists(self.pid_file):
@@ -963,9 +964,16 @@ class JupyterHub(Application):
# start the webserver
self.http_server = tornado.httpserver.HTTPServer(self.tornado_application, xheaders=True)
self.http_server.listen(self.hub_port)
atexit.register(self.atexit)
def atexit(self):
"""atexit callback"""
# run the cleanup step (in a new loop, because the interrupted one is unclean)
IOLoop.clear_current()
loop = IOLoop()
loop.make_current()
loop.run_sync(self.cleanup)
atexit.register(lambda : IOLoop().run_sync(self.cleanup))
def stop(self):
if not self.io_loop: