Skip to content

Commit 61247be

Browse files
authored
Merge pull request #1151 from pymonger/handle-logfile-permission-error
handle permission issue writing .jupyter-server-log.txt in REPO_DIR
2 parents 1d218af + 5df775a commit 61247be

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

repo2docker/buildpacks/repo2docker-entrypoint

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import select
1212
import signal
1313
import subprocess
1414
import sys
15+
import tempfile
1516

1617
# output chunk size to read
1718
CHUNK_SIZE = 1024
@@ -23,11 +24,23 @@ SIGNALS = set(signal.Signals) - {signal.SIGKILL, signal.SIGSTOP, signal.SIGCHLD}
2324

2425
def main():
2526

26-
# open log file to send output
27-
log_file = open(
28-
os.path.join(os.environ.get("REPO_DIR", "."), ".jupyter-server-log.txt"),
29-
"ab",
30-
)
27+
# open log file to send output to;
28+
# preferred location of log file is:
29+
# 1. REPO_DIR env variable
30+
# 2. current working directory: "."
31+
# 3. default temp directory for the OS (e.g. /tmp for linux)
32+
log_dirs = [".", tempfile.gettempdir()]
33+
if "REPO_DIR" in os.environ:
34+
log_dirs.insert(0, os.environ["REPO_DIR"])
35+
for d in log_dirs:
36+
log_path = os.path.join(d, ".jupyter-server-log.txt")
37+
try:
38+
log_file = open(log_path, "ab")
39+
except PermissionError:
40+
continue
41+
else:
42+
# success
43+
break
3144

3245
# build the command
3346
# like `exec "$@"`

0 commit comments

Comments
 (0)