Files
SkyArtShop/backend/scripts/health-monitor.sh

102 lines
2.9 KiB
Bash
Raw Permalink Normal View History

2026-01-23 23:54:24 -06:00
#!/bin/bash
# Health Monitor for SkyArtShop
# Checks backend, database, and site availability
# Run this script with: ./health-monitor.sh
set -e
echo "🔍 SkyArtShop Health Check"
echo "=========================="
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check 1: PM2 Process Status
echo -n "1. PM2 Process Status... "
if pm2 list | grep -q "skyartshop.*online"; then
echo -e "${GREEN}✓ Running${NC}"
else
echo -e "${RED}✗ Not Running${NC}"
echo " Attempting to restart..."
pm2 restart skyartshop
fi
# Check 2: Backend Port
echo -n "2. Backend Port 5000... "
if netstat -tlnp 2>/dev/null | grep -q ":5000" || ss -tlnp 2>/dev/null | grep -q ":5000"; then
echo -e "${GREEN}✓ Listening${NC}"
else
echo -e "${RED}✗ Not Listening${NC}"
fi
# Check 3: Database Connection
echo -n "3. Database Connection... "
if psql -U pts -d skyartshop -c "SELECT 1;" > /dev/null 2>&1; then
echo -e "${GREEN}✓ Connected${NC}"
else
echo -e "${RED}✗ Failed${NC}"
fi
# Check 4: Database Permissions
echo -n "4. Database Permissions... "
if psql -U pts -d skyartshop -c "SELECT COUNT(*) FROM pages WHERE isactive = true;" > /dev/null 2>&1; then
echo -e "${GREEN}✓ OK${NC}"
else
echo -e "${RED}✗ Permission Denied${NC}"
echo " Run: sudo -u postgres psql -d skyartshop -c \"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO pts;\""
fi
# Check 5: Backend HTTP Response
echo -n "5. Backend HTTP (localhost:5000)... "
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/ 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
echo -e "${GREEN}✓ OK (200)${NC}"
else
echo -e "${RED}✗ Failed ($HTTP_CODE)${NC}"
fi
# Check 6: HTTPS Site
echo -n "6. HTTPS Site (skyartshop.dynns.com)... "
HTTPS_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://skyartshop.dynns.com/ 2>/dev/null)
if [ "$HTTPS_CODE" = "200" ]; then
echo -e "${GREEN}✓ OK (200)${NC}"
else
echo -e "${RED}✗ Failed ($HTTPS_CODE)${NC}"
fi
# Check 7: CSS Assets
echo -n "7. CSS Assets Loading... "
CSS_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://skyartshop.dynns.com/assets/css/modern-theme.css 2>/dev/null)
if [ "$CSS_CODE" = "200" ]; then
echo -e "${GREEN}✓ OK (200)${NC}"
else
echo -e "${RED}✗ Failed ($CSS_CODE)${NC}"
fi
# Check 8: Recent Errors
echo -n "8. Recent Backend Errors... "
ERROR_COUNT=$(tail -100 /media/pts/Website/SkyArtShop/backend/logs/error.log 2>/dev/null | grep "$(date +%Y-%m-%d)" | wc -l)
if [ "$ERROR_COUNT" -eq 0 ]; then
echo -e "${GREEN}✓ None Today${NC}"
elif [ "$ERROR_COUNT" -lt 5 ]; then
echo -e "${YELLOW}$ERROR_COUNT errors today${NC}"
else
echo -e "${RED}$ERROR_COUNT errors today${NC}"
fi
echo ""
echo "=========================="
echo "Health Check Complete"
echo ""
# Exit with error if backend is not running
if ! pm2 list | grep -q "skyartshop.*online"; then
exit 1
fi
exit 0