#!/bin/bash # VTL System Startup Verification Script # Checks all critical services and components echo "==========================================" echo "VTL System Startup Verification" echo "==========================================" echo "" echo "Checking all critical services..." echo "" # Color codes for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to check service status check_service() { local service=$1 local description=$2 if systemctl is-active --quiet $service; then echo -e "${GREEN}✅ $description${NC} - Running" return 0 else echo -e "${RED}❌ $description${NC} - Not Running" return 1 fi } # Function to check if service is enabled check_enabled() { local service=$1 local description=$2 if systemctl is-enabled --quiet $service 2>/dev/null; then echo -e "${GREEN}✅ $description${NC} - Enabled (auto-start on boot)" return 0 else echo -e "${YELLOW}⚠️ $description${NC} - Disabled (won't auto-start)" return 1 fi } echo "==========================================" echo "1. Service Status Check" echo "==========================================" echo "" # Check mhvtl check_service "mhvtl" "MHVTL (Virtual Tape Library)" MHVTL_RUNNING=$? # Check Apache check_service "apache2" "Apache Web Server (Web UI)" APACHE_RUNNING=$? # Check tgt (iSCSI) check_service "tgt" "TGT (iSCSI Target)" TGT_RUNNING=$? echo "" echo "==========================================" echo "2. Auto-Start Configuration" echo "==========================================" echo "" check_enabled "mhvtl" "MHVTL Service" MHVTL_ENABLED=$? check_enabled "apache2" "Apache Web Server" APACHE_ENABLED=$? check_enabled "tgt" "TGT iSCSI Target" TGT_ENABLED=$? echo "" echo "==========================================" echo "3. MHVTL Components" echo "==========================================" echo "" # Check vtltape processes VTLTAPE_COUNT=$(pgrep -f "vtltape" | wc -l) if [ $VTLTAPE_COUNT -gt 0 ]; then echo -e "${GREEN}✅ vtltape processes${NC} - $VTLTAPE_COUNT running" ps aux | grep vtltape | grep -v grep | awk '{print " " $11 " " $12 " " $13}' else echo -e "${RED}❌ vtltape processes${NC} - None running" fi echo "" # Check vtllibrary process if pgrep -f "vtllibrary" > /dev/null; then echo -e "${GREEN}✅ vtllibrary process${NC} - Running" ps aux | grep vtllibrary | grep -v grep | awk '{print " " $11 " " $12 " " $13}' else echo -e "${RED}❌ vtllibrary process${NC} - Not running" fi echo "" echo "==========================================" echo "4. SCSI Devices" echo "==========================================" echo "" # Check library if lsscsi -g | grep -q "mediumx"; then echo -e "${GREEN}✅ Library (Changer)${NC} - Detected" lsscsi -g | grep mediumx | awk '{print " " $0}' else echo -e "${RED}❌ Library (Changer)${NC} - Not detected" fi echo "" # Check tape drives TAPE_COUNT=$(lsscsi -g | grep "tape" | wc -l) if [ $TAPE_COUNT -gt 0 ]; then echo -e "${GREEN}✅ Tape Drives${NC} - $TAPE_COUNT detected" lsscsi -g | grep tape | nl -w2 -s'. ' else echo -e "${RED}❌ Tape Drives${NC} - None detected" fi echo "" echo "==========================================" echo "5. Web UI Access" echo "==========================================" echo "" # Check if web UI files exist if [ -d "/var/www/html/mhvtl-config" ]; then echo -e "${GREEN}✅ Web UI Files${NC} - Installed" echo " Location: /var/www/html/mhvtl-config/" else echo -e "${RED}❌ Web UI Files${NC} - Not found" fi echo "" # Check Apache port if netstat -tuln 2>/dev/null | grep -q ":80 " || ss -tuln 2>/dev/null | grep -q ":80 "; then echo -e "${GREEN}✅ Web Server Port${NC} - Listening on port 80" else echo -e "${YELLOW}⚠️ Web Server Port${NC} - Not listening on port 80" fi echo "" echo " Access URL: http://localhost/mhvtl-config/" echo "" echo "==========================================" echo "6. iSCSI Targets" echo "==========================================" echo "" # Check iSCSI targets TARGET_COUNT=$(tgtadm --lld iscsi --mode target --op show 2>/dev/null | grep "Target" | grep -v "System" | wc -l) if [ $TARGET_COUNT -gt 0 ]; then echo -e "${GREEN}✅ iSCSI Targets${NC} - $TARGET_COUNT configured" tgtadm --lld iscsi --mode target --op show 2>/dev/null | grep "Target" | grep -v "System" | head -5 else echo -e "${YELLOW}⚠️ iSCSI Targets${NC} - None configured (use Web UI to create)" fi echo "" echo "==========================================" echo "7. Configuration Files" echo "==========================================" echo "" # Check device.conf if [ -f "/etc/mhvtl/device.conf" ]; then echo -e "${GREEN}✅ device.conf${NC} - Present" echo " Library ID: $(grep "^Library:" /etc/mhvtl/device.conf | awk '{print $2}')" echo " Drives: $(grep "^Drive:" /etc/mhvtl/device.conf | wc -l)" else echo -e "${RED}❌ device.conf${NC} - Not found" fi echo "" # Check library_contents LIBRARY_ID=$(grep "^Library:" /etc/mhvtl/device.conf 2>/dev/null | awk '{print $2}') if [ -f "/etc/mhvtl/library_contents.$LIBRARY_ID" ]; then echo -e "${GREEN}✅ library_contents.$LIBRARY_ID${NC} - Present" else echo -e "${YELLOW}⚠️ library_contents.$LIBRARY_ID${NC} - Not found" fi echo "" echo "==========================================" echo "Summary" echo "==========================================" echo "" # Calculate overall status TOTAL_CHECKS=0 PASSED_CHECKS=0 # Services running if [ $MHVTL_RUNNING -eq 0 ]; then ((PASSED_CHECKS++)); fi if [ $APACHE_RUNNING -eq 0 ]; then ((PASSED_CHECKS++)); fi if [ $TGT_RUNNING -eq 0 ]; then ((PASSED_CHECKS++)); fi TOTAL_CHECKS=$((TOTAL_CHECKS + 3)) # Services enabled if [ $MHVTL_ENABLED -eq 0 ]; then ((PASSED_CHECKS++)); fi if [ $APACHE_ENABLED -eq 0 ]; then ((PASSED_CHECKS++)); fi if [ $TGT_ENABLED -eq 0 ]; then ((PASSED_CHECKS++)); fi TOTAL_CHECKS=$((TOTAL_CHECKS + 3)) # Components if [ $VTLTAPE_COUNT -gt 0 ]; then ((PASSED_CHECKS++)); fi if pgrep -f "vtllibrary" > /dev/null; then ((PASSED_CHECKS++)); fi TOTAL_CHECKS=$((TOTAL_CHECKS + 2)) # Devices if lsscsi -g | grep -q "mediumx"; then ((PASSED_CHECKS++)); fi if [ $TAPE_COUNT -gt 0 ]; then ((PASSED_CHECKS++)); fi TOTAL_CHECKS=$((TOTAL_CHECKS + 2)) echo "Status: $PASSED_CHECKS/$TOTAL_CHECKS checks passed" echo "" if [ $PASSED_CHECKS -eq $TOTAL_CHECKS ]; then echo -e "${GREEN}✅ ALL SYSTEMS OPERATIONAL${NC}" echo "" echo "VTL system is fully functional and will auto-start on boot!" exit 0 elif [ $PASSED_CHECKS -ge $((TOTAL_CHECKS * 2 / 3)) ]; then echo -e "${YELLOW}⚠️ SYSTEM PARTIALLY OPERATIONAL${NC}" echo "" echo "Some components may need attention. Check warnings above." exit 1 else echo -e "${RED}❌ SYSTEM ISSUES DETECTED${NC}" echo "" echo "Multiple components are not working. Please review errors above." exit 2 fi