Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,213 Bytes
7a6c881 |
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 |
#!/bin/bash
# Keep-alive script for Tranception Hugging Face Space
# Add to crontab: */5 * * * * /path/to/keep_alive_cron.sh
SPACE_URL="https://huggingface.co/spaces/MoraxCheng/Transeption_iGEM_BASISCHINA_2025"
LOG_FILE="/var/log/tranception_keep_alive.log"
# Function to log with timestamp
log_message() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
}
# Ping the Space
response=$(curl -s -o /dev/null -w "%{http_code}" "$SPACE_URL" --max-time 30)
if [ "$response" = "200" ]; then
log_message "SUCCESS: Space is alive (HTTP $response)"
else
log_message "WARNING: Space returned HTTP $response"
# Try to wake it up with a simple request
curl -s -X POST "$SPACE_URL/api/predict" \
-H "Content-Type: application/json" \
-d '{"fn_index": 0, "data": ["MSKGEELFT", 1, 5, "Small", false, 10]}' \
--max-time 60 > /dev/null
log_message "Sent wake-up request"
fi
# Keep log file size under control (max 1MB)
if [ -f "$LOG_FILE" ] && [ $(stat -f%z "$LOG_FILE" 2>/dev/null || stat -c%s "$LOG_FILE" 2>/dev/null) -gt 1048576 ]; then
tail -n 1000 "$LOG_FILE" > "$LOG_FILE.tmp"
mv "$LOG_FILE.tmp" "$LOG_FILE"
log_message "Log file rotated"
fi |