#!/bin/bash # SkyArtShop System Verification Script # Verifies MongoDB, images, and application status echo "=========================================" echo "SkyArtShop System Verification" echo "=========================================" echo "" # Color codes GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check MongoDB echo "1. MongoDB Service Status" echo "-----------------------------------------" if systemctl is-active --quiet mongod; then echo -e "${GREEN}✓ MongoDB is running${NC}" else echo -e "${RED}✗ MongoDB is not running${NC}" fi # Check MongoDB connection echo "" echo "2. MongoDB Database Check" echo "-----------------------------------------" DB_CHECK=$(mongosh --quiet --eval "db.adminCommand('ping').ok" 2>&1) if [ "$DB_CHECK" = "1" ]; then echo -e "${GREEN}✓ MongoDB connection successful${NC}" else echo -e "${RED}✗ Cannot connect to MongoDB${NC}" fi # Check collections echo "" echo "3. MongoDB Collections" echo "-----------------------------------------" mongosh --quiet SkyArtShopDB --eval ' db.getCollectionNames().forEach(function(col) { var count = db.getCollection(col).countDocuments(); print(col + ": " + count + " documents"); })' # Check products and their images echo "" echo "4. Product Data Integrity" echo "-----------------------------------------" MISSING_IMAGES=0 mongosh --quiet SkyArtShopDB --eval ' var products = db.Products.find({}).toArray(); products.forEach(function(p) { print("Product: " + p.Name); print(" ID: " + p._id); print(" Price: $" + p.Price); print(" ImageUrl: " + (p.ImageUrl || "MISSING")); print(" Images: " + (p.Images ? p.Images.length : 0) + " images"); print(" Colors: " + (p.Colors ? p.Colors.join(", ") : "none")); print(" Active: " + p.IsActive); print(""); }); ' # Check if images exist on filesystem echo "" echo "5. Image File Verification" echo "-----------------------------------------" IMAGES_DIR="/var/www/SkyArtShop/wwwroot/uploads/images" if [ -d "$IMAGES_DIR" ]; then IMAGE_COUNT=$(find "$IMAGES_DIR" -type f | wc -l) echo -e "${GREEN}✓ Images directory exists${NC}" echo " Total images: $IMAGE_COUNT" # Check product images mongosh --quiet SkyArtShopDB --eval ' var products = db.Products.find({}).toArray(); products.forEach(function(p) { if (p.ImageUrl) { var filename = p.ImageUrl.split("/").pop(); print(filename); } if (p.Images) { p.Images.forEach(function(img) { var filename = img.split("/").pop(); print(filename); }); } }); ' | while read -r img; do if [ -n "$img" ] && [ ! -f "$IMAGES_DIR/$img" ]; then echo -e "${RED} ✗ Missing: $img${NC}" MISSING_IMAGES=$((MISSING_IMAGES + 1)) fi done if [ $MISSING_IMAGES -eq 0 ]; then echo -e "${GREEN} ✓ All product images exist${NC}" fi else echo -e "${RED}✗ Images directory not found${NC}" fi # Check application status echo "" echo "6. Application Status" echo "-----------------------------------------" if pgrep -f "SkyArtShop.dll" > /dev/null; then echo -e "${GREEN}✓ Application is running${NC}" APP_PID=$(pgrep -f "SkyArtShop.dll") echo " Process ID: $APP_PID" # Check if port is listening if ss -tln | grep -q ":5001"; then echo -e "${GREEN}✓ Application listening on port 5001${NC}" else echo -e "${YELLOW}⚠ Application not listening on expected port${NC}" fi else echo -e "${RED}✗ Application is not running${NC}" fi # Check Nginx echo "" echo "7. Web Server Status" echo "-----------------------------------------" if systemctl is-active --quiet nginx; then echo -e "${GREEN}✓ Nginx is running${NC}" if ss -tln | grep -q ":80"; then echo -e "${GREEN}✓ Nginx listening on port 80${NC}" fi else echo -e "${RED}✗ Nginx is not running${NC}" fi # Test website response echo "" echo "8. Website Response Test" echo "-----------------------------------------" HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5001/ 2>&1) if [ "$HTTP_CODE" = "200" ]; then echo -e "${GREEN}✓ Website responding correctly (HTTP 200)${NC}" elif [ "$HTTP_CODE" = "000" ]; then echo -e "${RED}✗ Cannot connect to website${NC}" else echo -e "${YELLOW}⚠ Website returned HTTP $HTTP_CODE${NC}" fi # Test shop page SHOP_TEST=$(curl -s http://localhost:5001/shop 2>&1 | grep -c "product-card") if [ "$SHOP_TEST" -gt 0 ]; then echo -e "${GREEN}✓ Shop page displaying $SHOP_TEST products${NC}" else echo -e "${YELLOW}⚠ Shop page may have issues${NC}" fi # Disk space check echo "" echo "9. Disk Space" echo "-----------------------------------------" df -h /var/www/SkyArtShop | tail -1 | awk '{print " Used: " $3 " / " $2 " (" $5 ")"}' # Summary echo "" echo "=========================================" echo "Verification Complete" echo "=========================================" echo "" echo "All critical systems checked." echo "If any issues were found, please review the output above." echo ""