Claude Code Claude Opus 4.6 commited on
Commit
a983f51
·
1 Parent(s): 05faf4e

Claude Code: add auto-restart loop to entrypoint.sh and explicit startup prints

Browse files

- entrypoint.sh: wrap uvicorn in while loop for auto-restart on crashes
- entrypoint.sh: add timestamped logging for each restart attempt
- app.py: add explicit print() statements for pre-startup visibility

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

Files changed (2) hide show
  1. app.py +9 -0
  2. entrypoint.sh +18 -6
app.py CHANGED
@@ -10,6 +10,15 @@ import logging
10
  from fastapi import FastAPI, status as http_status
11
  from fastapi.responses import JSONResponse
12
 
 
 
 
 
 
 
 
 
 
13
  # Configure logging to stdout for container visibility
14
  logging.basicConfig(
15
  level=logging.INFO,
 
10
  from fastapi import FastAPI, status as http_status
11
  from fastapi.responses import JSONResponse
12
 
13
+ # EXPLICIT PRE-STARTUP PRINTS (visible in container logs)
14
+ print(">>> " + "="*50)
15
+ print(">>> CAIN: Python app.py loading...")
16
+ print(">>> " + "="*50)
17
+ print(">>> CAIN: Python version:", sys.version.split()[0])
18
+ print(">>> CAIN: Working directory:", os.getcwd())
19
+ print(">>> CAIN: PORT =", os.environ.get('PORT', '7860'))
20
+ print(">>> " + "="*50)
21
+
22
  # Configure logging to stdout for container visibility
23
  logging.basicConfig(
24
  level=logging.INFO,
entrypoint.sh CHANGED
@@ -1,8 +1,6 @@
1
  #!/bin/bash
2
  # Entrypoint for HuggingClaw - Cain
3
- # Provides explicit logging for startup sequence debugging
4
-
5
- set -e
6
 
7
  echo "=========================================="
8
  echo "Cain Starting..."
@@ -34,8 +32,22 @@ ls -la /app/*.py 2>/dev/null || echo " (no .py files in /app root)"
34
 
35
  echo ""
36
  echo "=========================================="
37
- echo "Starting uvicorn..."
38
  echo "=========================================="
39
 
40
- # Start uvicorn with explicit host/port
41
- exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/bin/bash
2
  # Entrypoint for HuggingClaw - Cain
3
+ # Provides explicit logging and auto-restart on crashes
 
 
4
 
5
  echo "=========================================="
6
  echo "Cain Starting..."
 
32
 
33
  echo ""
34
  echo "=========================================="
35
+ echo "Starting uvicorn with auto-restart on crash..."
36
  echo "=========================================="
37
 
38
+ # Auto-restart loop: if uvicorn crashes, wait 2s and restart
39
+ while true; do
40
+ echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Starting uvicorn on 0.0.0.0:${PORT:-7860}..."
41
+ uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
42
+ EXIT_CODE=$?
43
+
44
+ echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] uvicorn exited with code: $EXIT_CODE"
45
+
46
+ if [ $EXIT_CODE -eq 0 ]; then
47
+ echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Clean exit, not restarting"
48
+ break
49
+ fi
50
+
51
+ echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Crash detected! Restarting in 2 seconds..."
52
+ sleep 2
53
+ done