Skip to content

Commit 1ccd675

Browse files
authored
Merge pull request #88 from lsst-sqre/tickets/DM-51606
Force notebook dir to /tmp if abnormal startup set
2 parents 3664d05 + ac6eb5b commit 1ccd675

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Find changes for the upcoming release in the project's [changelog.d directory](h
66

77
<!-- scriv-insert-here -->
88

9+
<a id='changelog-0.9.4'></a>
10+
## 0.9.4 (2025-06-28)
11+
12+
### Bug fixes
13+
14+
- Make Lab startup more robust when confronted with out-of-quota errors.
15+
916
<a id='changelog-0.9.3'></a>
1017
## 0.9.3 (2025-06-13)
1118

src/lsst/rsp/startup/services/labrunner/labrunner.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,69 @@ def _set_timeout_variables(self) -> list[str]:
742742
result.append(f"--{timeout_map[setting]}={val}")
743743
return result
744744

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 += "\nYour Lab container did not start normally.\n"
760+
txt += f"Error: `{self._env.get("ABNORMAL_STARTUP_MESSAGE","")}`\n"
761+
txt += "\nIf 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 += "\nOtherwise, 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+
745788
def _start(self) -> None:
789+
abnormal = bool(self._env.get("ABNORMAL_STARTUP", ""))
746790
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+
747802
cmd = [
748803
"jupyterhub-singleuser",
749804
"--ip=0.0.0.0",
750805
"--port=8888",
751806
"--no-browser",
752-
f"--notebook-dir={self._home!s}",
807+
f"--notebook-dir={notebook_dir}",
753808
f"--log-level={log_level}",
754809
"--ContentsManager.allow_hidden=True",
755810
"--FileContentsManager.hide_globs=[]",

0 commit comments

Comments
 (0)