Claude Code commited on
Commit
0d0e2dd
·
1 Parent(s): 29ac1bd

Claude Code: Fix container exit issue - log paths and restart loop

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. entrypoint.sh +26 -3
  3. error_handlers.py +1 -1
app.py CHANGED
@@ -34,7 +34,7 @@ from error_handlers import (
34
  # CONFIGURATION & LOGGING
35
  # ============================================================================
36
 
37
- LOG_PATH = "/var/log/cain.log"
38
  FRONTEND_PATH = Path(__file__).parent / "frontend"
39
  AGENT_DASHBOARD = FRONTEND_PATH / "agent-dashboard.html"
40
 
 
34
  # CONFIGURATION & LOGGING
35
  # ============================================================================
36
 
37
+ LOG_PATH = "/app/logs/cain.log" # Writable in Docker container
38
  FRONTEND_PATH = Path(__file__).parent / "frontend"
39
  AGENT_DASHBOARD = FRONTEND_PATH / "agent-dashboard.html"
40
 
entrypoint.sh CHANGED
@@ -205,6 +205,29 @@ echo " - Uvicorn: $UVICORN_PID"
205
  echo " - A2A Proxy: $A2A_PID"
206
  echo ""
207
 
208
- # Keep container running - wait indefinitely for any background process
209
- # This prevents the container from exiting when startup completes
210
- wait
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  echo " - A2A Proxy: $A2A_PID"
206
  echo ""
207
 
208
+ # Keep container running - monitor background processes and restart if needed
209
+ # This prevents the container from exiting when uvicorn crashes
210
+ while true; do
211
+ # Check if uvicorn is still running
212
+ if ! kill -0 $UVICORN_PID 2>/dev/null; then
213
+ echo "WARNING: Uvicorn died (PID $UVICORN_PID), restarting..."
214
+ uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}" > /app/logs/uvicorn.log 2>&1 &
215
+ UVICORN_PID=$!
216
+ echo " Uvicorn restarted with PID: $UVICORN_PID"
217
+ echo $UVICORN_PID > /tmp/uvicorn.pid
218
+ fi
219
+
220
+ # Check if a2a-proxy is still running (if it was started)
221
+ if [ -n "$A2A_PID" ] && ! kill -0 $A2A_PID 2>/dev/null; then
222
+ echo "WARNING: A2A proxy died (PID $A2A_PID), restarting..."
223
+ if [ -f "/app/scripts/a2a-proxy.cjs" ]; then
224
+ node /app/scripts/a2a-proxy.cjs > /app/logs/a2a-proxy.log 2>&1 &
225
+ A2A_PID=$!
226
+ echo " A2A proxy restarted with PID: $A2A_PID"
227
+ echo $A2A_PID > /tmp/a2a-proxy.pid
228
+ fi
229
+ fi
230
+
231
+ # Sleep before next check
232
+ sleep 5
233
+ done
error_handlers.py CHANGED
@@ -15,7 +15,7 @@ from fastapi import HTTPException, Request
15
  from fastapi.responses import JSONResponse
16
 
17
  # Dedicated error logger for exception tracking
18
- _error_log_path = "/var/log/cain_errors.log"
19
  try:
20
  error_handler = logging.FileHandler(_error_log_path)
21
  error_handler.setFormatter(logging.Formatter(
 
15
  from fastapi.responses import JSONResponse
16
 
17
  # Dedicated error logger for exception tracking
18
+ _error_log_path = "/app/logs/cain_errors.log" # Writable in Docker container
19
  try:
20
  error_handler = logging.FileHandler(_error_log_path)
21
  error_handler.setFormatter(logging.Formatter(