You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
956 B

#!/bin/bash
APP_NAME="your-app-name"
HEALTH_URL=${1:-"http://localhost:3000/health"}
MAX_RETRIES=${2:-10}
RETRY_INTERVAL=${3:-5}
echo "🔍 Starting health check for $APP_NAME..."
for i in $(seq 1 $MAX_RETRIES); do
echo "Attempt $i/$MAX_RETRIES..."
# بررسی وضعیت PM2
if ! pm2 list | grep -q $APP_NAME; then
echo "❌ PM2 process not found"
sleep $RETRY_INTERVAL
continue
fi
# بررسی وضعیت online بودن
if ! pm2 list | grep $APP_NAME | grep -q "online"; then
echo "❌ PM2 process not online"
sleep $RETRY_INTERVAL
continue
fi
# بررسی HTTP endpoint
if curl -f -s $HEALTH_URL > /dev/null; then
echo "✅ Health check passed!"
exit 0
fi
echo "❌ Health check failed, retrying in ${RETRY_INTERVAL}s..."
sleep $RETRY_INTERVAL
done
echo "💥 Health check failed after $MAX_RETRIES attempts"
exit 1