#!/bin/bash # SkyArtShop Cleanup and Verification Script # This script removes temporary files, verifies system health, and displays performance metrics echo "========================================" echo " SkyArtShop Cleanup & Verification" echo "========================================" echo "" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Step 1: Clean temporary files echo -e "${YELLOW}[1/7] Cleaning temporary files...${NC}" cd /var/www/SkyArtShop # Remove backup files find . -type f \( -name "*.bak" -o -name "*.old" -o -name "*.broken" -o -name "*.tmp" \) -delete 2>/dev/null echo -e "${GREEN}✓ Temporary files removed${NC}" # Remove empty directories find . -type d -empty -delete 2>/dev/null echo -e "${GREEN}✓ Empty directories removed${NC}" echo "" # Step 2: Clean build artifacts echo -e "${YELLOW}[2/7] Cleaning build artifacts...${NC}" rm -rf ./obj/Release/* 2>/dev/null rm -rf ./bin/Release/* 2>/dev/null echo -e "${GREEN}✓ Build artifacts cleaned${NC}" echo "" # Step 3: Check services echo -e "${YELLOW}[3/7] Checking services status...${NC}" SERVICES=("nginx" "mongod" "skyartshop") ALL_RUNNING=true for service in "${SERVICES[@]}"; do if systemctl is-active --quiet "$service"; then echo -e "${GREEN}✓ $service is running${NC}" else echo -e "${RED}✗ $service is not running${NC}" ALL_RUNNING=false fi done echo "" # Step 4: Test website connectivity echo -e "${YELLOW}[4/7] Testing website connectivity...${NC}" HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost 2>/dev/null) if [ "$HTTP_CODE" = "200" ]; then echo -e "${GREEN}✓ Website responding (HTTP $HTTP_CODE)${NC}" else echo -e "${RED}✗ Website not responding (HTTP $HTTP_CODE)${NC}" fi echo "" # Step 5: Check MongoDB echo -e "${YELLOW}[5/7] Checking MongoDB connection...${NC}" if mongosh --quiet --eval "db.adminCommand('ping').ok" SkyArtShopDB >/dev/null 2>&1; then echo -e "${GREEN}✓ MongoDB connected${NC}" # Get collection counts PRODUCTS=$(mongosh --quiet --eval "db.Products.countDocuments()" SkyArtShopDB 2>/dev/null) PAGES=$(mongosh --quiet --eval "db.Pages.countDocuments()" SkyArtShopDB 2>/dev/null) MENU_ITEMS=$(mongosh --quiet --eval "db.MenuItems.countDocuments()" SkyArtShopDB 2>/dev/null) ADMIN_USERS=$(mongosh --quiet --eval "db.AdminUsers.countDocuments()" SkyArtShopDB 2>/dev/null) echo " - Products: $PRODUCTS" echo " - Pages: $PAGES" echo " - Menu Items: $MENU_ITEMS" echo " - Admin Users: $ADMIN_USERS" else echo -e "${RED}✗ MongoDB connection failed${NC}" fi echo "" # Step 6: System resources echo -e "${YELLOW}[6/7] System resources:${NC}" echo "--- Memory ---" free -h | grep "^Mem:" | awk '{print " Used: " $3 " / " $2 " (" int($3/$2*100) "%)"}' echo "" echo "--- CPU ---" CPU_COUNT=$(nproc) CPU_LOAD=$(uptime | awk -F'load average:' '{print $2}' | cut -d, -f1) echo " Cores: $CPU_COUNT" echo " Load: $CPU_LOAD" echo "" echo "--- Disk ---" df -h /var/www | tail -1 | awk '{print " Used: " $3 " / " $2 " (" $5 ")"}' echo "" echo "--- Network Connections ---" CONNECTIONS=$(ss -s | grep TCP: | awk '{print $4}') echo " Active TCP: $CONNECTIONS" echo "" # Step 7: Configuration verification echo -e "${YELLOW}[7/7] Configuration verification:${NC}" # Check Nginx config if sudo nginx -t >/dev/null 2>&1; then echo -e "${GREEN}✓ Nginx configuration valid${NC}" else echo -e "${RED}✗ Nginx configuration has errors${NC}" fi # Check file permissions if [ -x "/var/www/SkyArtShop/publish/SkyArtShop.dll" ]; then echo -e "${GREEN}✓ Application files have correct permissions${NC}" else echo -e "${RED}✗ Application files may have permission issues${NC}" fi # Check .NET runtime if command -v dotnet &> /dev/null; then DOTNET_VERSION=$(dotnet --version) echo -e "${GREEN}✓ .NET runtime installed ($DOTNET_VERSION)${NC}" else echo -e "${RED}✗ .NET runtime not found${NC}" fi echo "" echo "========================================" echo " Verification Complete" echo "========================================" echo "" # Final summary if [ "$ALL_RUNNING" = true ] && [ "$HTTP_CODE" = "200" ]; then echo -e "${GREEN}✓ System is healthy and running optimally${NC}" echo "" echo "Access your website at:" echo " - Local: http://localhost" echo " - Domain: http://skyarts.ddns.net" echo "" echo "Admin Panel:" echo " - URL: http://skyarts.ddns.net/admin" echo " - User: admin@skyartshop.com" echo "" echo "For detailed performance info, see:" echo " /var/www/SkyArtShop/PERFORMANCE_OPTIMIZATION.md" exit 0 else echo -e "${RED}⚠ System has issues that need attention${NC}" echo "" echo "Check logs with:" echo " sudo journalctl -u skyartshop.service -n 50" echo " sudo tail -f /var/log/nginx/error.log" exit 1 fi