feat: Major VTL System Upgrade (Auth, Monitoring, CLI, Installer)

- Web UI:
  - Added secure Authentication system (Login, 2 Roles: Admin/Viewer)
  - Added System Monitoring Dashboard (Health, Services, Power Mgmt)
  - Added User Management Interface (Create, Delete, Enable/Disable)
  - Added Device Mapping view in iSCSI tab (lsscsi output)
- Backend:
  - Implemented secure session management (auth.php)
  - Added power management APIs (restart/shutdown appliance)
  - Added device mapping API
- CLI:
  - Created global 'vtl' management tool
  - Added scripts for reliable startup (vtllibrary fix)
- Installer:
  - Updated install.sh with new dependencies (tgt, sudoers, permissions)
  - Included all new components in build-installer.sh
- Docs:
  - Consolidated documentation into docs/ folder
This commit is contained in:
2025-12-09 18:15:36 +00:00
parent 8a0523a265
commit 01080498af
53 changed files with 13399 additions and 425 deletions

125
scripts/clean-reboot-mhvtl.sh Executable file
View File

@@ -0,0 +1,125 @@
#!/bin/bash
echo "=========================================="
echo "MHVTL Clean Reboot Script"
echo "=========================================="
echo ""
# Stop mhvtl service gracefully
echo "1. Stopping mhvtl service..."
systemctl stop mhvtl
sleep 2
# Kill any remaining processes
echo "2. Cleaning up processes..."
pkill -9 vtltape 2>/dev/null || true
pkill -9 vtllibrary 2>/dev/null || true
sleep 1
# Clear lock files
echo "3. Clearing lock files..."
rm -f /var/lock/mhvtl/mhvtl* 2>/dev/null || true
# Show current configuration
echo ""
echo "=========================================="
echo "Current Configuration:"
echo "=========================================="
echo ""
echo "Library:"
grep "^Library:" /etc/mhvtl/device.conf
echo ""
echo "Drives:"
grep "^Drive:" /etc/mhvtl/device.conf
echo ""
# Create verification script for after reboot
cat > /tmp/verify-mhvtl-after-reboot.sh << 'EOF'
#!/bin/bash
echo "=========================================="
echo "MHVTL Post-Reboot Verification"
echo "=========================================="
echo ""
echo "1. Checking mhvtl service status..."
systemctl status mhvtl --no-pager -l
echo ""
echo "2. Checking running processes..."
ps aux | grep -E "(vtltape|vtllibrary)" | grep -v grep
echo ""
echo "3. SCSI Devices (lsscsi -g):"
lsscsi -g
echo ""
echo "4. Detailed SCSI info (/proc/scsi/scsi):"
cat /proc/scsi/scsi
echo ""
echo "5. Verifying drive types..."
echo "Expected: All HP Ultrium 6-SCSI"
echo "Actual:"
lsscsi -g | grep tape | awk '{print $3, $4, $5}'
echo ""
# Check if all drives are HP
IBM_COUNT=$(lsscsi -g | grep tape | grep IBM | wc -l)
HP_COUNT=$(lsscsi -g | grep tape | grep HP | wc -l)
echo "=========================================="
echo "Verification Result:"
echo "=========================================="
echo "IBM drives found: $IBM_COUNT"
echo "HP drives found: $HP_COUNT"
echo ""
if [ $IBM_COUNT -eq 0 ] && [ $HP_COUNT -eq 4 ]; then
echo "✅ SUCCESS! All drives are HP Ultrium 6-SCSI"
echo "✅ Configuration is correct!"
else
echo "⚠️ WARNING: Drive types don't match expected configuration"
echo " Expected: 0 IBM, 4 HP"
echo " Found: $IBM_COUNT IBM, $HP_COUNT HP"
fi
echo ""
echo "=========================================="
echo "To access Web UI:"
echo "http://localhost/mhvtl-config/"
echo "=========================================="
EOF
chmod +x /tmp/verify-mhvtl-after-reboot.sh
echo "=========================================="
echo "Pre-Reboot Checklist:"
echo "=========================================="
echo "✅ mhvtl service stopped"
echo "✅ Processes cleaned up"
echo "✅ Lock files cleared"
echo "✅ Verification script created at /tmp/verify-mhvtl-after-reboot.sh"
echo ""
echo "=========================================="
echo "READY TO REBOOT"
echo "=========================================="
echo ""
echo "After reboot, run this command to verify:"
echo " sudo /tmp/verify-mhvtl-after-reboot.sh"
echo ""
echo "Or check manually:"
echo " lsscsi -g"
echo ""
echo "Rebooting in 5 seconds..."
echo "Press Ctrl+C to cancel"
echo ""
for i in 5 4 3 2 1; do
echo "$i..."
sleep 1
done
echo ""
echo "Rebooting now..."
reboot

67
scripts/fix-mhvtl-config.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
# Fix MHVTL configuration to properly map drives to library
# Problem: Drive IDs must follow convention: Library_ID + Slot_Number
# For Library 10, drives should be 11, 12, 13, 14 (not 00, 01, 02, 03)
echo "Fixing MHVTL configuration..."
# Stop mhvtl service first
echo "Stopping mhvtl service..."
systemctl stop mhvtl
# Wait for processes to stop
sleep 2
# Backup current configuration
cp /etc/mhvtl/device.conf /etc/mhvtl/device.conf.backup-$(date +%Y%m%d-%H%M%S)
cp /etc/mhvtl/library_contents.10 /etc/mhvtl/library_contents.10.backup-$(date +%Y%m%d-%H%M%S)
# Fix device.conf: Change Drive IDs from 00,01,02,03 to 11,12,13,14
echo "Updating device.conf..."
sed -i 's/^Drive: 00 /Drive: 11 /' /etc/mhvtl/device.conf
sed -i 's/^Drive: 01 /Drive: 12 /' /etc/mhvtl/device.conf
sed -i 's/^Drive: 02 /Drive: 13 /' /etc/mhvtl/device.conf
sed -i 's/^Drive: 03 /Drive: 14 /' /etc/mhvtl/device.conf
# Fix library_contents.10: Map drive slots to correct drive IDs
echo "Updating library_contents.10..."
sed -i 's/^Drive 1: 00$/Drive 1: 11/' /etc/mhvtl/library_contents.10
sed -i 's/^Drive 2: 01$/Drive 2: 12/' /etc/mhvtl/library_contents.10
sed -i 's/^Drive 3: 02$/Drive 3: 13/' /etc/mhvtl/library_contents.10
sed -i 's/^Drive 4: 03$/Drive 4: 14/' /etc/mhvtl/library_contents.10
# Remove old lock files
rm -f /var/lock/mhvtl/mhvtl* 2>/dev/null || true
# Verify changes
echo ""
echo "=== Updated device.conf ==="
grep -E "^(Library|Drive):" /etc/mhvtl/device.conf
echo ""
echo "=== Updated library_contents.10 ==="
head -10 /etc/mhvtl/library_contents.10
echo ""
# Start mhvtl service
echo "Starting mhvtl service..."
systemctl start mhvtl
# Wait for devices to initialize
sleep 3
# Check status
echo ""
echo "=== MHVTL Service Status ==="
systemctl status mhvtl --no-pager -l
echo ""
echo "=== Running Processes ==="
ps aux | grep -E "(vtltape|vtllibrary)" | grep -v grep
echo ""
echo "=== SCSI Devices ==="
lsscsi -g
echo ""
echo "Fix completed!"

View File

@@ -28,19 +28,24 @@ done
sleep 2
LIBRARY_NUMS=$(grep "^Library:" "$CONFIG_FILE" | awk '{print $2}' | sort -u)
for library in $LIBRARY_NUMS; do
if ! pgrep -f "vtllibrary.*$library" > /dev/null; then
echo "Starting vtllibrary for library $library..."
/usr/bin/vtllibrary $library > /dev/null 2>&1 &
/usr/bin/vtllibrary -q $library > /dev/null 2>&1 &
else
echo "vtllibrary for library $library is already running"
fi
done
# Wait for vtllibrary to initialize
sleep 2
RUNNING_DRIVES=$(pgrep -f "vtltape" | wc -l)
RUNNING_LIBS=$(pgrep -f "vtllibrary" | wc -l)
echo "mhvtl started: $RUNNING_DRIVES drives, $RUNNING_LIBS libraries"
exit 0

245
scripts/verify-vtl-startup.sh Executable file
View File

@@ -0,0 +1,245 @@
#!/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

365
scripts/vtl Executable file
View File

@@ -0,0 +1,365 @@
#!/bin/bash
# VTL Management CLI Tool
# Global command for managing Virtual Tape Library system
VERSION="1.0.0"
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Functions for service management
start_service() {
local service=$1
echo -ne "Starting ${service}... "
if systemctl start $service 2>/dev/null; then
echo -e "${GREEN}✓${NC}"
return 0
else
echo -e "${RED}✗${NC}"
return 1
fi
}
stop_service() {
local service=$1
echo -ne "Stopping ${service}... "
if systemctl stop $service 2>/dev/null; then
echo -e "${GREEN}✓${NC}"
return 0
else
echo -e "${RED}✗${NC}"
return 1
fi
}
restart_service() {
local service=$1
echo -ne "Restarting ${service}... "
if systemctl restart $service 2>/dev/null; then
echo -e "${GREEN}✓${NC}"
return 0
else
echo -e "${RED}✗${NC}"
return 1
fi
}
# Status check function
check_status() {
echo -e "${BOLD}${CYAN}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BOLD}${CYAN}║ VTL System Status Dashboard ║${NC}"
echo -e "${BOLD}${CYAN}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Services Status
echo -e "${BOLD}${BLUE}📊 Services Status:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Check mhvtl
if systemctl is-active --quiet mhvtl; then
echo -e " ${GREEN}●${NC} mhvtl ${GREEN}running${NC} (Virtual Tape Library)"
else
echo -e " ${RED}●${NC} mhvtl ${RED}stopped${NC} (Virtual Tape Library)"
fi
# Check apache2
if systemctl is-active --quiet apache2; then
echo -e " ${GREEN}●${NC} apache2 ${GREEN}running${NC} (Web UI Server)"
else
echo -e " ${RED}●${NC} apache2 ${RED}stopped${NC} (Web UI Server)"
fi
# Check tgt
if systemctl is-active --quiet tgt; then
echo -e " ${GREEN}●${NC} tgt ${GREEN}running${NC} (iSCSI Target)"
else
echo -e " ${RED}●${NC} tgt ${RED}stopped${NC} (iSCSI Target)"
fi
echo ""
# Components Status
echo -e "${BOLD}${BLUE}🔧 Components:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# vtltape processes
VTLTAPE_COUNT=$(pgrep -f "vtltape" | wc -l)
if [ $VTLTAPE_COUNT -gt 0 ]; then
echo -e " ${GREEN}✓${NC} vtltape ${GREEN}$VTLTAPE_COUNT processes${NC}"
else
echo -e " ${RED}✗${NC} vtltape ${RED}not running${NC}"
fi
# vtllibrary process
if pgrep -f "vtllibrary" > /dev/null; then
echo -e " ${GREEN}✓${NC} vtllibrary ${GREEN}running${NC}"
else
echo -e " ${RED}✗${NC} vtllibrary ${RED}not running${NC}"
fi
echo ""
# Devices Status
echo -e "${BOLD}${BLUE}💾 SCSI Devices:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Library
if lsscsi -g 2>/dev/null | grep -q "mediumx"; then
LIBRARY_INFO=$(lsscsi -g 2>/dev/null | grep mediumx | awk '{print $3, $4, "-", $NF}')
echo -e " ${GREEN}✓${NC} Library ${GREEN}detected${NC} ($LIBRARY_INFO)"
else
echo -e " ${RED}✗${NC} Library ${RED}not detected${NC}"
fi
# Tape Drives
TAPE_COUNT=$(lsscsi -g 2>/dev/null | grep "tape" | wc -l)
if [ $TAPE_COUNT -gt 0 ]; then
echo -e " ${GREEN}✓${NC} Tape Drives ${GREEN}$TAPE_COUNT detected${NC}"
lsscsi -g 2>/dev/null | grep tape | while read line; do
VENDOR=$(echo $line | awk '{print $3}')
MODEL=$(echo $line | awk '{print $4}')
DEVICE=$(echo $line | awk '{print $NF}')
echo -e " └─ $VENDOR $MODEL → $DEVICE"
done
else
echo -e " ${RED}✗${NC} Tape Drives ${RED}none detected${NC}"
fi
echo ""
# Network Services
echo -e "${BOLD}${BLUE}🌐 Network Services:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Web UI
if netstat -tuln 2>/dev/null | grep -q ":80 " || ss -tuln 2>/dev/null | grep -q ":80 "; then
echo -e " ${GREEN}✓${NC} Web UI ${GREEN}http://localhost/mhvtl-config/${NC}"
else
echo -e " ${RED}✗${NC} Web UI ${RED}not accessible${NC}"
fi
# iSCSI
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}✓${NC} iSCSI Targets ${GREEN}$TARGET_COUNT configured${NC}"
else
echo -e " ${YELLOW}⚠${NC} iSCSI Targets ${YELLOW}none configured${NC}"
fi
echo ""
# Overall Health
echo -e "${BOLD}${BLUE}💚 Overall Health:${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Calculate health score
SCORE=0
MAX_SCORE=6
systemctl is-active --quiet mhvtl && ((SCORE++))
systemctl is-active --quiet apache2 && ((SCORE++))
systemctl is-active --quiet tgt && ((SCORE++))
[ $VTLTAPE_COUNT -gt 0 ] && ((SCORE++))
pgrep -f "vtllibrary" > /dev/null && ((SCORE++))
lsscsi -g 2>/dev/null | grep -q "mediumx" && ((SCORE++))
PERCENTAGE=$((SCORE * 100 / MAX_SCORE))
if [ $PERCENTAGE -eq 100 ]; then
echo -e " ${GREEN}●${NC} System Status: ${GREEN}${BOLD}HEALTHY${NC} (${SCORE}/${MAX_SCORE} checks passed)"
echo -e " ${GREEN}✓${NC} All components operational"
elif [ $PERCENTAGE -ge 66 ]; then
echo -e " ${YELLOW}●${NC} System Status: ${YELLOW}${BOLD}DEGRADED${NC} (${SCORE}/${MAX_SCORE} checks passed)"
echo -e " ${YELLOW}⚠${NC} Some components need attention"
else
echo -e " ${RED}●${NC} System Status: ${RED}${BOLD}CRITICAL${NC} (${SCORE}/${MAX_SCORE} checks passed)"
echo -e " ${RED}✗${NC} Multiple components offline"
fi
echo ""
}
# List devices
list_devices() {
echo -e "${BOLD}${CYAN}SCSI Devices:${NC}"
echo ""
lsscsi -g
echo ""
}
# Show help
show_help() {
echo -e "${BOLD}${CYAN}VTL Management Tool v${VERSION}${NC}"
echo ""
echo -e "${BOLD}Usage:${NC}"
echo " vtl <command> [options]"
echo ""
echo -e "${BOLD}Commands:${NC}"
echo ""
echo -e " ${GREEN}status${NC} Show VTL system status and health"
echo -e " ${GREEN}start${NC} Start all VTL services"
echo -e " ${GREEN}stop${NC} Stop all VTL services"
echo -e " ${GREEN}restart${NC} Restart all VTL services"
echo -e " ${GREEN}devices${NC} List all SCSI devices"
echo ""
echo -e " ${GREEN}start-mhvtl${NC} Start only MHVTL service"
echo -e " ${GREEN}stop-mhvtl${NC} Stop only MHVTL service"
echo -e " ${GREEN}restart-mhvtl${NC} Restart only MHVTL service"
echo ""
echo -e " ${GREEN}start-web${NC} Start only Web UI (Apache)"
echo -e " ${GREEN}stop-web${NC} Stop only Web UI (Apache)"
echo -e " ${GREEN}restart-web${NC} Restart only Web UI (Apache)"
echo ""
echo -e " ${GREEN}start-iscsi${NC} Start only iSCSI service (TGT)"
echo -e " ${GREEN}stop-iscsi${NC} Stop only iSCSI service (TGT)"
echo -e " ${GREEN}restart-iscsi${NC} Restart only iSCSI service (TGT)"
echo ""
echo -e " ${GREEN}logs${NC} [service] Show logs for service (mhvtl|apache2|tgt)"
echo -e " ${GREEN}web${NC} Open Web UI URL"
echo -e " ${GREEN}version${NC} Show version information"
echo -e " ${GREEN}help${NC} Show this help message"
echo ""
echo -e "${BOLD}Examples:${NC}"
echo " vtl status # Check system status"
echo " vtl start # Start all services"
echo " vtl restart-mhvtl # Restart only MHVTL"
echo " vtl logs mhvtl # View MHVTL logs"
echo ""
}
# Show logs
show_logs() {
local service=${1:-mhvtl}
echo -e "${BOLD}${CYAN}Logs for ${service}:${NC}"
echo ""
journalctl -u $service -n 50 --no-pager
}
# Main command handler
case "${1}" in
status)
check_status
;;
start)
echo -e "${BOLD}${CYAN}Starting VTL Services...${NC}"
echo ""
start_service "mhvtl"
sleep 2
start_service "apache2"
start_service "tgt"
echo ""
echo -e "${GREEN}✓${NC} All services started"
echo ""
sleep 2
check_status
;;
stop)
echo -e "${BOLD}${CYAN}Stopping VTL Services...${NC}"
echo ""
stop_service "mhvtl"
stop_service "apache2"
stop_service "tgt"
echo ""
echo -e "${GREEN}✓${NC} All services stopped"
;;
restart)
echo -e "${BOLD}${CYAN}Restarting VTL Services...${NC}"
echo ""
restart_service "mhvtl"
sleep 2
restart_service "apache2"
restart_service "tgt"
echo ""
echo -e "${GREEN}✓${NC} All services restarted"
echo ""
sleep 2
check_status
;;
start-mhvtl)
start_service "mhvtl"
sleep 2
check_status
;;
stop-mhvtl)
stop_service "mhvtl"
;;
restart-mhvtl)
restart_service "mhvtl"
sleep 2
check_status
;;
start-web)
start_service "apache2"
;;
stop-web)
stop_service "apache2"
;;
restart-web)
restart_service "apache2"
;;
start-iscsi)
start_service "tgt"
;;
stop-iscsi)
stop_service "tgt"
;;
restart-iscsi)
restart_service "tgt"
;;
devices)
list_devices
;;
logs)
show_logs "${2}"
;;
web)
echo -e "${BOLD}${CYAN}Web UI URL:${NC}"
echo ""
echo " http://localhost/mhvtl-config/"
echo ""
;;
version)
echo -e "${BOLD}${CYAN}VTL Management Tool${NC}"
echo "Version: ${VERSION}"
echo "MHVTL: $(vtltape --version 2>&1 | head -1 || echo 'Not installed')"
echo ""
;;
help|--help|-h)
show_help
;;
*)
if [ -z "$1" ]; then
check_status
else
echo -e "${RED}Error: Unknown command '${1}'${NC}"
echo ""
echo "Run 'vtl help' for usage information"
exit 1
fi
;;
esac