Spaces:
Sleeping
Sleeping
Upload scripts/entrypoint.sh with huggingface_hub
Browse files- scripts/entrypoint.sh +47 -5
scripts/entrypoint.sh
CHANGED
|
@@ -2,13 +2,32 @@
|
|
| 2 |
|
| 3 |
set -e
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
echo "Waiting for DNS resolution..."
|
| 7 |
for i in {1..30}; do
|
| 8 |
if nslookup cain-voice.hf.space > /dev/null 2>&1; then
|
|
|
|
| 9 |
break
|
| 10 |
fi
|
| 11 |
sleep 1
|
|
|
|
|
|
|
|
|
|
| 12 |
done
|
| 13 |
|
| 14 |
# Set environment variables
|
|
@@ -20,13 +39,19 @@ export OPENCLAW_LANGUAGE="en"
|
|
| 20 |
mkdir -p /app/.openclaw
|
| 21 |
mkdir -p /app/output
|
| 22 |
|
| 23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
echo "Starting OpenClaw..."
|
| 25 |
cd /app
|
| 26 |
nohup python -m openclaw.server --host 0.0.0.0 --port 7860 > openclaw.log 2>&1 &
|
| 27 |
OPENCLAW_PID=$!
|
| 28 |
|
| 29 |
-
# Wait for OpenClaw to start
|
| 30 |
echo "Waiting for OpenClaw to initialize..."
|
| 31 |
for i in {1..30}; do
|
| 32 |
if curl -f $OPENCLAW_HOST > /dev/null 2>&1; then
|
|
@@ -34,9 +59,26 @@ for i in {1..30}; do
|
|
| 34 |
break
|
| 35 |
fi
|
| 36 |
sleep 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
done
|
| 38 |
|
| 39 |
-
# Start the sync process
|
| 40 |
echo "Starting Cain..."
|
| 41 |
cd /app
|
| 42 |
-
python scripts/sync_hf.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
set -e
|
| 4 |
|
| 5 |
+
# Function to handle errors
|
| 6 |
+
handle_error() {
|
| 7 |
+
echo "Error occurred at line $1: $2"
|
| 8 |
+
# Save error state to dataset
|
| 9 |
+
echo '{"error": "'"$2"'", "time": "'$(date -Iseconds)'", "line": "'"$1"'"}' > /app/dataset/.error_state.json
|
| 10 |
+
# Attempt to save important state
|
| 11 |
+
if [ -f /app/.openclaw/openclaw.json ]; then
|
| 12 |
+
cp /app/.openclaw/openclaw.json /app/dataset/
|
| 13 |
+
fi
|
| 14 |
+
# Exit with error code
|
| 15 |
+
exit 1
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
trap 'handle_error ${LINENO} "$?"' ERR
|
| 19 |
+
|
| 20 |
+
# Wait for DNS resolution with retries
|
| 21 |
echo "Waiting for DNS resolution..."
|
| 22 |
for i in {1..30}; do
|
| 23 |
if nslookup cain-voice.hf.space > /dev/null 2>&1; then
|
| 24 |
+
echo "DNS resolved"
|
| 25 |
break
|
| 26 |
fi
|
| 27 |
sleep 1
|
| 28 |
+
if [ $i -eq 30 ]; then
|
| 29 |
+
echo "DNS resolution failed, continuing anyway..."
|
| 30 |
+
fi
|
| 31 |
done
|
| 32 |
|
| 33 |
# Set environment variables
|
|
|
|
| 39 |
mkdir -p /app/.openclaw
|
| 40 |
mkdir -p /app/output
|
| 41 |
|
| 42 |
+
# Check for previous state in dataset
|
| 43 |
+
if [ -f /app/dataset/.openclaw/openclaw.json ]; then
|
| 44 |
+
echo "Restoring previous state..."
|
| 45 |
+
cp /app/dataset/.openclaw/openclaw.json /app/.openclaw/
|
| 46 |
+
fi
|
| 47 |
+
|
| 48 |
+
# Start OpenClaw in the background with logging
|
| 49 |
echo "Starting OpenClaw..."
|
| 50 |
cd /app
|
| 51 |
nohup python -m openclaw.server --host 0.0.0.0 --port 7860 > openclaw.log 2>&1 &
|
| 52 |
OPENCLAW_PID=$!
|
| 53 |
|
| 54 |
+
# Wait for OpenClaw to start with timeout
|
| 55 |
echo "Waiting for OpenClaw to initialize..."
|
| 56 |
for i in {1..30}; do
|
| 57 |
if curl -f $OPENCLAW_HOST > /dev/null 2>&1; then
|
|
|
|
| 59 |
break
|
| 60 |
fi
|
| 61 |
sleep 1
|
| 62 |
+
if [ $i -eq 30 ]; then
|
| 63 |
+
echo "OpenClaw startup timed out, but continuing..."
|
| 64 |
+
# Save PID anyway for potential recovery
|
| 65 |
+
echo $OPENCLAW_PID > /app/dataset/.openclaw.pid
|
| 66 |
+
fi
|
| 67 |
done
|
| 68 |
|
| 69 |
+
# Start the sync process with error handling
|
| 70 |
echo "Starting Cain..."
|
| 71 |
cd /app
|
| 72 |
+
if ! python scripts/sync_hf.py; then
|
| 73 |
+
echo "Sync process failed, attempting recovery..."
|
| 74 |
+
# Try with fallback parameters
|
| 75 |
+
python scripts/sync_hf.py --fallback
|
| 76 |
+
exit 1
|
| 77 |
+
fi
|
| 78 |
+
|
| 79 |
+
# Save successful startup state
|
| 80 |
+
echo '{"startup_time": "'$(date -Iseconds)'", "pid": "'$OPENCLAW_PID'"}' > /app/dataset/.startup_state.json
|
| 81 |
+
|
| 82 |
+
# Keep the script running to maintain background processes
|
| 83 |
+
echo "Cain is running with PID $OPENCLAW_PID"
|
| 84 |
+
wait $OPENCLAW_PID
|