#!/usr/bin/env bash
# مدقق بقاء على قيد الحياة — شغّله كل 5 دقائق من Cron Jobs في cPanel.
# يعيد تشغيل التطبيق فقط إذا كان متوقفًا (لا ينشئ نسخًا مكررة).
APP_DIR="$(cd "$(dirname "$0")" && pwd)"

if pgrep -f "$APP_DIR/.venv/bin/python app.py" >/dev/null 2>&1; then
  exit 0
fi

cd "$APP_DIR" || exit 1
nohup "$APP_DIR/run.sh" >/dev/null 2>&1 &
echo "$(date): restarted" >> "$APP_DIR/keepalive.log"
