tao-shen Claude Opus 4.6 commited on
Commit
955df2f
Β·
1 Parent(s): e97a432

fix: use stderr for all logs (HF Spaces captures stderr, not stdout)

Browse files

HF Spaces log API only captures stderr from Docker containers.
Changed all scripts to redirect stdout→stderr (exec 1>&2) and
Python to print to sys.stderr. Added PYTHONUNBUFFERED=1, removed
stdbuf wrapper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Dockerfile CHANGED
@@ -52,7 +52,8 @@ COPY scripts /scripts
52
  RUN chmod +x /scripts/entrypoint.sh /opt/start-server.sh
53
 
54
  ENV PERSIST_PATH=/data
55
- ENV RUN_CMD="stdbuf -oL -eL /opt/start-server.sh"
 
56
  ENV SSH_PORT=2222
57
 
58
  # Run as root (needed for: apt install persistence, bind mounts, sshd)
 
52
  RUN chmod +x /scripts/entrypoint.sh /opt/start-server.sh
53
 
54
  ENV PERSIST_PATH=/data
55
+ ENV PYTHONUNBUFFERED=1
56
+ ENV RUN_CMD="/opt/start-server.sh"
57
  ENV SSH_PORT=2222
58
 
59
  # Run as root (needed for: apt install persistence, bind mounts, sshd)
scripts/entrypoint.sh CHANGED
@@ -6,8 +6,8 @@
6
  # 3. Start sync-loop daemon in BACKGROUND
7
  # ─────────────────────────────────────────────────────────────────────
8
  set -e
9
- # Merge stderr β†’ stdout so HF runtime log API captures ALL output
10
- exec 2>&1
11
  echo "========================================"
12
  echo "[entrypoint] HuggingRun starting ..."
13
  echo "[entrypoint] Date: $(date -u)"
 
6
  # 3. Start sync-loop daemon in BACKGROUND
7
  # ─────────────────────────────────────────────────────────────────────
8
  set -e
9
+ # HF Spaces log API captures stderr β€” redirect ALL stdout β†’ stderr
10
+ exec 1>&2
11
  echo "========================================"
12
  echo "[entrypoint] HuggingRun starting ..."
13
  echo "[entrypoint] Date: $(date -u)"
ubuntu-server/git_sync_daemon.py CHANGED
@@ -43,7 +43,7 @@ UPLOAD_IGNORE = [
43
 
44
  def log(msg):
45
  ts = time.strftime("%H:%M:%S", time.gmtime())
46
- print(f"[sync {ts}] {msg}", flush=True)
47
 
48
 
49
  def run(cmd, cwd=None):
@@ -271,7 +271,7 @@ def cmd_sync_loop():
271
  except Exception as e:
272
  log(f" βœ— Sync cycle #{cycle} error: {e}")
273
  import traceback
274
- traceback.print_exc(file=sys.stdout)
275
  log(f" Sleeping {SYNC_INTERVAL}s until next cycle ...")
276
  time.sleep(SYNC_INTERVAL)
277
 
 
43
 
44
  def log(msg):
45
  ts = time.strftime("%H:%M:%S", time.gmtime())
46
+ print(f"[sync {ts}] {msg}", file=sys.stderr, flush=True)
47
 
48
 
49
  def run(cmd, cwd=None):
 
271
  except Exception as e:
272
  log(f" βœ— Sync cycle #{cycle} error: {e}")
273
  import traceback
274
+ traceback.print_exc(file=sys.stderr)
275
  log(f" Sleeping {SYNC_INTERVAL}s until next cycle ...")
276
  time.sleep(SYNC_INTERVAL)
277
 
ubuntu-server/start-server.sh CHANGED
@@ -4,8 +4,8 @@
4
  # Port 7860 (nginx): web terminal + SSH
5
  # ─────────────────────────────────────────────────────────────────────
6
 
7
- # Merge stderr β†’ stdout so HF runtime log API captures ALL output
8
- exec 2>&1
9
 
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"
 
4
  # Port 7860 (nginx): web terminal + SSH
5
  # ─────────────────────────────────────────────────────────────────────
6
 
7
+ # HF Spaces log API captures stderr β€” redirect ALL stdout β†’ stderr
8
+ exec 1>&2
9
 
10
  export SSH_PORT="${SSH_PORT:-2222}"
11
  export TTYD_PORT="${TTYD_PORT:-7681}"