- Added UseForwardedHeaders to properly handle X-Forwarded-For and X-Forwarded-Proto - Fixes anti-forgery token validation when behind nginx proxy - Resolves HTTP 500 errors on POST requests to login endpoint
143 lines
5.6 KiB
Bash
143 lines
5.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Diagnose and Fix Unhealthy LittleShop Admin Container
|
|
echo "=========================================="
|
|
echo "LittleShop Admin Container Health Diagnosis"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# 1. Check container status and health
|
|
echo "1. Container Status:"
|
|
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "NAME|littleshop-admin"
|
|
echo ""
|
|
|
|
# 2. Check health check details
|
|
echo "2. Health Check Configuration:"
|
|
docker inspect littleshop-admin --format='{{json .State.Health}}' | python3 -m json.tool 2>/dev/null || \
|
|
docker inspect littleshop-admin | grep -A 10 '"Health"'
|
|
echo ""
|
|
|
|
# 3. Check if the application is actually responding
|
|
echo "3. Testing Application Response:"
|
|
echo " - Testing internal port 8080..."
|
|
docker exec littleshop-admin curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://localhost:8080/health 2>/dev/null || echo " Health endpoint not responding"
|
|
docker exec littleshop-admin curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://localhost:8080/ 2>/dev/null || echo " Root endpoint not responding"
|
|
echo ""
|
|
|
|
# 4. Check database file and permissions
|
|
echo "4. Database Status:"
|
|
echo " Host path: /opt/littleshop/data/"
|
|
ls -la /opt/littleshop/data/ 2>/dev/null || echo " Data directory not found"
|
|
echo ""
|
|
echo " Container path: /app/data/"
|
|
docker exec littleshop-admin ls -la /app/data/ 2>/dev/null || echo " Cannot access container data directory"
|
|
echo ""
|
|
|
|
# 5. Check recent logs for startup issues
|
|
echo "5. Recent Application Logs:"
|
|
docker logs --tail 30 littleshop-admin 2>&1 | grep -E "Now listening on:|fail|ERROR|Exception|Unable|warn" || docker logs --tail 30 littleshop-admin
|
|
echo ""
|
|
|
|
# 6. Check environment variables
|
|
echo "6. Key Environment Variables:"
|
|
docker inspect littleshop-admin | grep -E "ASPNETCORE_ENVIRONMENT|ConnectionStrings__DefaultConnection" | head -5
|
|
echo ""
|
|
|
|
# 7. Network connectivity check
|
|
echo "7. Network Configuration:"
|
|
docker inspect littleshop-admin --format='{{range .NetworkSettings.Networks}}{{.NetworkID}} {{end}}' | while read net; do
|
|
echo " Connected to network: $(docker network ls | grep $net | awk '{print $2}')"
|
|
done
|
|
echo ""
|
|
|
|
# 8. Memory and resource usage
|
|
echo "8. Resource Usage:"
|
|
docker stats --no-stream littleshop-admin 2>/dev/null || echo " Could not get stats"
|
|
echo ""
|
|
|
|
echo "=========================================="
|
|
echo "ATTEMPTING FIXES"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Fix 1: Database permissions
|
|
echo "Fix 1: Setting correct database permissions..."
|
|
sudo chown -R 1654:1654 /opt/littleshop/data/ 2>/dev/null && echo " ✓ Permissions fixed" || echo " ✗ Could not fix permissions"
|
|
|
|
# Fix 2: Ensure database exists
|
|
echo "Fix 2: Checking database file..."
|
|
if [ -f "/opt/littleshop/data/littleshop-production.db" ]; then
|
|
echo " ✓ Database file exists"
|
|
SIZE=$(stat -c%s "/opt/littleshop/data/littleshop-production.db" 2>/dev/null)
|
|
echo " Database size: $SIZE bytes"
|
|
if [ "$SIZE" -eq 0 ]; then
|
|
echo " ⚠ WARNING: Database file is empty!"
|
|
echo " The container should recreate it on restart"
|
|
fi
|
|
else
|
|
echo " ✗ Database file missing - will be created on container restart"
|
|
fi
|
|
|
|
# Fix 3: Connect to correct network
|
|
echo "Fix 3: Ensuring network connectivity..."
|
|
docker network connect littleshop-network littleshop-admin 2>/dev/null && echo " ✓ Connected to littleshop-network" || echo " Already connected or network doesn't exist"
|
|
|
|
# Fix 4: Restart with proper environment
|
|
echo "Fix 4: Restarting container with full configuration..."
|
|
docker stop littleshop-admin
|
|
docker rm littleshop-admin
|
|
|
|
# Recreate with all necessary environment variables
|
|
docker run -d \
|
|
--name littleshop-admin \
|
|
--restart unless-stopped \
|
|
--network littleshop-network \
|
|
-p 5000:8080 \
|
|
-v /opt/littleshop/data:/app/data \
|
|
-v /opt/littleshop/logs:/app/logs \
|
|
-v /opt/littleshop/uploads:/app/wwwroot/uploads \
|
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
-e ASPNETCORE_URLS="http://+:8080" \
|
|
-e ConnectionStrings__DefaultConnection="Data Source=/app/data/littleshop-production.db" \
|
|
-e SilverPay__BaseUrl="http://silverpay-api:8000" \
|
|
-e SilverPay__ApiKey="7703aa7a62fa4b40a87e9cfd867f5407147515c0986116ea54fc00c0a0bc30d8" \
|
|
-e SilverPay__WebhookSecret="Thefa1r1esd1d1twebhooks2024" \
|
|
-e SilverPay__DefaultWebhookUrl="https://admin.thebankofdebbie.giize.com/api/orders/payments/webhook" \
|
|
-e JWT_SECRET_KEY="ThisIsAVeryLongSecretKeyForJWTTokenGeneration123456789!" \
|
|
--health-cmd="curl -f http://localhost:8080/ || exit 1" \
|
|
--health-interval=30s \
|
|
--health-timeout=10s \
|
|
--health-retries=3 \
|
|
littleshop:latest
|
|
|
|
echo " Waiting for container to start..."
|
|
sleep 10
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "POST-FIX STATUS"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Final status check
|
|
echo "Container Status:"
|
|
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "NAME|littleshop-admin"
|
|
echo ""
|
|
|
|
echo "Application Logs (after restart):"
|
|
docker logs --tail 20 littleshop-admin
|
|
echo ""
|
|
|
|
echo "Testing Login Page:"
|
|
curl -s -o /dev/null -w "HTTP Status Code: %{http_code}\n" http://localhost:5000/Admin/Account/Login || echo "Not responding on port 5000"
|
|
echo ""
|
|
|
|
echo "=========================================="
|
|
echo "DIAGNOSIS COMPLETE"
|
|
echo ""
|
|
echo "If still showing unhealthy:"
|
|
echo "1. Check if port 5000 is already in use: netstat -tulpn | grep 5000"
|
|
echo "2. Check firewall: ufw status | grep 5000"
|
|
echo "3. Rebuild image from source: cd /opt/LittleShop && docker build -t littleshop:latest ."
|
|
echo "4. Check disk space: df -h /"
|
|
echo "==========================================" |