Spaces:
Sleeping
Sleeping
File size: 3,198 Bytes
15b06d3 2edbaaf b5ed151 005fd43 a17fe15 2edbaaf a17fe15 2edbaaf 46c2524 f57943a 2edbaaf 15b06d3 46c2524 15b06d3 07b8a4e 0c79ba5 ebe6433 0c79ba5 ebe6433 2dc609c 8283992 0abdf8e ebe6433 2dc609c ebe6433 0c79ba5 2edbaaf bad336e d173fe5 a983f51 5ecf34c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #!/bin/bash
set -e
# Entrypoint for HuggingClaw - Cain
# Ensure frontend directory exists (defensive: created at build time, but verify at runtime)
mkdir -p /app/frontend
mkdir -p /data/frontend
# Ensure /data is writable and exists
mkdir -p /data
chmod 777 /data 2>/dev/null || true
echo "=========================================="
echo "Cain Starting..."
echo "=========================================="
echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
echo "PORT: ${PORT:-7860}"
echo "Working Directory: $(pwd)"
echo "Python Version: $(python --version)"
echo "Data directory: $(ls -la /data 2>&1 | head -5)"
echo "=========================================="
# Change to app directory
cd /app
# Set data directory to dataset mount point
export OPENCLAW_DATA_DIR=/data
# Verify app.py exists
if [ ! -f "/app/app.py" ]; then
echo "ERROR: app.py not found in /app"
exit 1
fi
echo "✓ app.py found"
# List key files for debugging
echo ""
echo "Files in /app:"
ls -la /app/*.py 2>/dev/null || echo " (no .py files in /app root)"
# Create logs directory
mkdir -p /app/logs
# Ensure cain_status.json directory exists
mkdir -p /data
# CRITICAL: Clear stale error field from cain_status.json before startup
# This prevents "unknown" errors from persisting across container restarts
# Clean ALL possible status file locations to ensure consistency
echo "Cleaning stale error field from status files..."
python3 -c "
import json
from pathlib import Path
status_files = [
Path('/data/cain_status.json'), # Primary (OPENCLAW_DATA_DIR)
Path('/app/openclaw/.openclaw/agents/cain_status.json'), # Nested structure
Path('/app/.openclaw/agents/cain_status.json'), # Legacy flat structure
Path('/app/cain_status.json'), # App root
Path('/app/data/cain_status.json'), # App data subdirectory
Path('/app/memory/cain_status.json'), # Memory directory (CRITICAL: was missing!)
Path('/data/memory/cain_status.json'), # Data memory directory
]
cleaned = 0
for status_file in status_files:
try:
if status_file.exists():
with open(status_file, 'r') as f:
data = json.load(f)
error = data.get('error')
# Fix: if error is string 'unknown' or contains 'unknown', set to null
if isinstance(error, str) and error.strip().lower() in ('unknown', 'none', 'null', ''):
data['error'] = None
data['_cleaned_at'] = 'entrypoint'
with open(status_file, 'w') as f:
json.dump(data, f, indent=2)
cleaned += 1
print(f' Cleaned: {status_file}')
elif error is None:
print(f' OK: {status_file} (error already null)')
except Exception as e:
print(f' Could not clean {status_file}: {e}')
print(f'Cleaned {cleaned} status file(s)')
" 2>/dev/null || echo "(Could not clean status files - continuing)"
echo ""
echo ""
echo "=========================================="
echo "Starting uvicorn..."
echo "=========================================="
# Run uvicorn directly in foreground (no forking, no piping)
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
|