Put the temp page under a flag

This commit is contained in:
GeorgianaElena
2020-08-11 14:09:11 +03:00
parent 69a6f89518
commit fcb5257901
2 changed files with 34 additions and 26 deletions

View File

@@ -115,23 +115,23 @@ def serve_forever(server):
pass pass
def main(): def main():
# Serve the loading page until TLJH builds if "--temporary-page" in sys.argv:
index_url="https://raw.githubusercontent.com/GeorgianaElena/the-littlest-jupyterhub/in-progress-page/bootstrap/index.html" # Serve the loading page until TLJH builds
favicon_url="https://raw.githubusercontent.com/jupyterhub/jupyterhub/master/share/jupyterhub/static/favicon.ico" index_url="https://raw.githubusercontent.com/GeorgianaElena/the-littlest-jupyterhub/in-progress-page/bootstrap/index.html"
urllib.request.urlretrieve(index_url, "index.html") favicon_url="https://raw.githubusercontent.com/jupyterhub/jupyterhub/master/share/jupyterhub/static/favicon.ico"
urllib.request.urlretrieve(favicon_url, "favicon.ico") urllib.request.urlretrieve(index_url, "index.html")
urllib.request.urlretrieve(favicon_url, "favicon.ico")
# If the bootstrap is run to upgrade TLJH, then this will raise an "Address already in use" error
# If the bootstrap is run to upgrade TLJH, then this will raise an "Address already in use" error try:
try: loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler)
loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler) p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,))
p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,)) p.start()
p.start() with open('/loading.pid', 'w+') as f:
with open('/loading.pid', 'w+') as f: f.write(str(p.pid))
f.write(str(p.pid)) except OSError:
except OSError: # Only serve the loading page when installing TLJH
# Only serve the loading page when installing TLJH pass
pass
validate_host() validate_host()
install_prefix = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh') install_prefix = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')

View File

@@ -486,6 +486,12 @@ def main():
nargs='*', nargs='*',
help='Plugin pip-specs to install' help='Plugin pip-specs to install'
) )
argparser.add_argument(
'--temporary-page',
action='store_true',
default=False,
help='Serve a temporary page while TLJH is building'
)
args = argparser.parse_args() args = argparser.parse_args()
@@ -502,16 +508,18 @@ def main():
ensure_jupyterlab_extensions() ensure_jupyterlab_extensions()
# Stop the http server with the loading page before traefik starts # Stop the http server with the loading page before traefik starts
try: if args.temporary_page:
with open(pidfile, "r") as f: pidfile = "/loading.pid"
pid = f.read() try:
os.kill(int(pid), signal.SIGINT) with open(pidfile, "r") as f:
# Remove the pid file and the temporary html page pid = f.read()
os.remove('/loading.pid') os.kill(int(pid), signal.SIGINT)
os.remove('/index.html') # Remove the pid file and the temporary html page
os.remove('/favicon.ico') os.remove(pidfile)
except: os.remove('/index.html')
pass os.remove('/favicon.ico')
except Exception as e:
pass
ensure_jupyterhub_service(HUB_ENV_PREFIX) ensure_jupyterhub_service(HUB_ENV_PREFIX)
ensure_jupyterhub_running() ensure_jupyterhub_running()