From d1bee23a7dd6aefb94f5208b3bbd5012502b9c17 Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Tue, 11 Aug 2020 16:01:44 +0300 Subject: [PATCH] Pass the pid to the installer as a cmd arg --- bootstrap/bootstrap.py | 9 +++++---- tljh/installer.py | 8 +------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py index d6efcdf..fa9c415 100644 --- a/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap.py @@ -102,7 +102,7 @@ class LoaderPageRequestHandler(SimpleHTTPRequestHandler): elif self.path == "/index.html" or self.path == "/favicon.ico": return SimpleHTTPRequestHandler.do_GET(self) elif self.path == "/": - self.send_response(301) + self.send_response(302) self.send_header('Location','/index.html') self.end_headers() else: @@ -115,7 +115,8 @@ def serve_forever(server): pass def main(): - if "--temporary-page" in sys.argv: + temp_page_flag = "--temporary-page" + if temp_page_flag in sys.argv: # Serve the loading page until TLJH builds index_url="https://raw.githubusercontent.com/GeorgianaElena/the-littlest-jupyterhub/in-progress-page/bootstrap/index.html" favicon_url="https://raw.githubusercontent.com/jupyterhub/jupyterhub/master/share/jupyterhub/static/favicon.ico" @@ -127,8 +128,8 @@ def main(): loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler) p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,)) p.start() - with open('/loading.pid', 'w+') as f: - f.write(str(p.pid)) + # Put the pid after the temp page flag to be passed to the istaller + sys.argv.insert(sys.argv.index(temp_page_flag)+1, str(p.pid)) except OSError: # Only serve the loading page when installing TLJH pass diff --git a/tljh/installer.py b/tljh/installer.py index fd00ef7..7756757 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -488,8 +488,6 @@ def main(): ) argparser.add_argument( '--temporary-page', - action='store_true', - default=False, help='Serve a temporary page while TLJH is building' ) @@ -509,13 +507,9 @@ def main(): # Stop the http server with the loading page before traefik starts if args.temporary_page: - pidfile = "/loading.pid" try: - with open(pidfile, "r") as f: - pid = f.read() - os.kill(int(pid), signal.SIGINT) + os.kill(int(args.temporary_page), signal.SIGINT) # Remove the pid file and the temporary html page - os.remove(pidfile) os.remove('/index.html') os.remove('/favicon.ico') except Exception as e: