codeclaw-backup / keep-alive.sh
somratpro's picture
feat: add WhatsApp pairing guardian, improve DNS resolution, and implement workspace sync status reporting
51ec4bc
raw
history blame
1.09 kB
#!/bin/bash
# Self-ping keep-alive for HF Spaces
# HF Spaces sleeps after 48h of inactivity (no HTTP requests)
# This script pings the Space's own URL to prevent that
#
# HF provides SPACE_HOST env var automatically (e.g., "username-spacename.hf.space")
# Runs as a background process alongside the gateway
INTERVAL="${KEEP_ALIVE_INTERVAL:-300}" # Default: every 5 minutes
if [ "$INTERVAL" = "0" ]; then
echo "鈴革笍 Keep-alive: disabled (KEEP_ALIVE_INTERVAL=0)"
exit 0
fi
if [ -z "$SPACE_HOST" ]; then
echo "鈴革笍 Keep-alive: SPACE_HOST not set (not on HF Spaces?), skipping."
exit 0
fi
# Ping the health endpoint so we keep the Space warm without touching the gateway
PING_URL="https://${SPACE_HOST}/health"
echo "馃挀 Keep-alive started: pinging ${PING_URL} every ${INTERVAL}s"
while true; do
sleep "$INTERVAL"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$PING_URL" 2>/dev/null)
if [ "$HTTP_CODE" = "000" ]; then
echo "馃挀 Keep-alive: ping failed (network error), retrying next cycle..."
else
echo "馃挀 Keep-alive: OK"
fi
done