@@ -742,14 +742,69 @@ def _set_timeout_variables(self) -> list[str]:
742
742
result .append (f"--{ timeout_map [setting ]} ={ val } " )
743
743
return result
744
744
745
+ def _make_abnormal_landing_page (self ) -> None :
746
+ # This is very ad-hoc. Revisit after DP1.
747
+ # What we're doing is writing in an empty, ephemeral filesystem,
748
+ # to drop a document explaining what's going on, and to tweak the
749
+ # display settings such that markdown is displayed in its rendered
750
+ # form.
751
+ abnormal = bool (self ._env .get ("ABNORMAL_STARTUP" , "" ))
752
+ if not abnormal :
753
+ return
754
+ user = self ._env ["USER" ]
755
+ home = self ._env .get ("NUBLADO_HOME" , "" ) or self ._env .get ("HOME" , "" )
756
+ if not home :
757
+ home = f"/home/{ user } " # We're just guessing at this point.
758
+ txt = "# Abnormal startup\n "
759
+ txt += "\n Your Lab container did not start normally.\n "
760
+ txt += f"Error: `{ self ._env .get ("ABNORMAL_STARTUP_MESSAGE" ,"" )} `\n "
761
+ txt += "\n If that looks like a file space error, try using the "
762
+ txt += f"terminal to remove unneeded files in `{ home } `. You can "
763
+ txt += "use the `quota` command to check how much space is in use. "
764
+ txt += "After that, shut down and restart the Lab.\n "
765
+ txt += "\n Otherwise, please open an issue with your RSP site"
766
+ txt += " administrator.\n "
767
+ s_obj = {"defaultViewers" : {"markdown" : "Markdown Preview" }}
768
+ s_txt = json .dumps (s_obj )
769
+
770
+ try :
771
+ welcome = Path ("/tmp/notebooks/tutorials/welcome.md" )
772
+ welcome .parent .mkdir (exist_ok = True , parents = True )
773
+ welcome .write_text (txt )
774
+ settings = (
775
+ Path ("/tmp" )
776
+ / ".jupyter"
777
+ / "lab"
778
+ / "user-settings"
779
+ / "@jupyterlab"
780
+ / "docmanager-extension"
781
+ / "plugin.jupyterlab-settings"
782
+ )
783
+ settings .parent .mkdir (exist_ok = True , parents = True )
784
+ settings .write_text (s_txt )
785
+ except Exception :
786
+ self ._logger .exception ("Writing abnormal startup files failed" )
787
+
745
788
def _start (self ) -> None :
789
+ abnormal = bool (self ._env .get ("ABNORMAL_STARTUP" , "" ))
746
790
log_level = "DEBUG" if self ._debug else "INFO"
791
+ notebook_dir = f"{ self ._home !s} "
792
+ if abnormal :
793
+ self ._logger .warning (
794
+ f"Abnormal startup: { self ._env ['ABNORMAL_STARTUP_MESSAGE' ]} "
795
+ )
796
+ self ._make_abnormal_landing_page ()
797
+ self ._logger .warning ("Launching with homedir='/tmp'" )
798
+ self ._env ["HOME" ] = "/tmp"
799
+ os .environ ["HOME" ] = "/tmp"
800
+ notebook_dir = "/tmp"
801
+
747
802
cmd = [
748
803
"jupyterhub-singleuser" ,
749
804
"--ip=0.0.0.0" ,
750
805
"--port=8888" ,
751
806
"--no-browser" ,
752
- f"--notebook-dir={ self . _home !s } " ,
807
+ f"--notebook-dir={ notebook_dir } " ,
753
808
f"--log-level={ log_level } " ,
754
809
"--ContentsManager.allow_hidden=True" ,
755
810
"--FileContentsManager.hide_globs=[]" ,
0 commit comments