cleanup of install and monitoring

This commit is contained in:
Deckard
2025-10-15 00:22:52 -04:00
parent d24da206e2
commit 90a90e40ad
11 changed files with 189 additions and 77 deletions

View File

@@ -290,8 +290,8 @@ nuclear_cleanup() {
cleanup_storage_preserve_backups() {
if [ -d "./storage" ]; then
# Find the storage path from environment files
STORAGE_ROOT=$(grep "^STORAGE_ROOT=" docker-compose-azerothcore-database*.env 2>/dev/null | head -1 | cut -d'=' -f2 || echo "/nfs/containers")
BACKUP_PATH="${STORAGE_ROOT}/azerothcore/backups"
STORAGE_ROOT=$(grep "^STORAGE_ROOT=" docker-compose-azerothcore-database*.env 2>/dev/null | head -1 | cut -d'=' -f2 || echo "/nfs/azerothcore")
BACKUP_PATH="${STORAGE_ROOT}/backups"
# Temporarily move backups if they exist
if [ -d "${BACKUP_PATH}" ]; then
@@ -305,7 +305,7 @@ nuclear_cleanup() {
# Restore backups if they were preserved
if [ -d "/tmp/azerothcore-backups-preserve/backups" ]; then
sudo mkdir -p "${STORAGE_ROOT}/azerothcore" 2>/dev/null || mkdir -p "${STORAGE_ROOT}/azerothcore"
sudo mkdir -p "${STORAGE_ROOT}" 2>/dev/null || mkdir -p "${STORAGE_ROOT}"
sudo mv /tmp/azerothcore-backups-preserve/backups "${BACKUP_PATH}" 2>/dev/null || mv /tmp/azerothcore-backups-preserve/backups "${BACKUP_PATH}"
sudo rm -rf /tmp/azerothcore-backups-preserve 2>/dev/null || rm -rf /tmp/azerothcore-backups-preserve
print_status "SUCCESS" "Backups preserved at ${BACKUP_PATH}"

View File

@@ -4,10 +4,23 @@ set -e
echo "🔧 Conditional AzerothCore Database Import"
echo "========================================"
# Restoration status markers
# Restoration status markers - use writable location
RESTORE_STATUS_DIR="/var/lib/mysql-persistent"
MARKER_STATUS_DIR="/tmp"
RESTORE_SUCCESS_MARKER="$RESTORE_STATUS_DIR/.restore-completed"
RESTORE_FAILED_MARKER="$RESTORE_STATUS_DIR/.restore-failed"
RESTORE_SUCCESS_MARKER_TMP="$MARKER_STATUS_DIR/.restore-completed"
RESTORE_FAILED_MARKER_TMP="$MARKER_STATUS_DIR/.restore-failed"
# Ensure we can write to the status directory, fallback to tmp
mkdir -p "$RESTORE_STATUS_DIR" 2>/dev/null || true
if ! touch "$RESTORE_STATUS_DIR/.test-write" 2>/dev/null; then
echo "⚠️ Cannot write to $RESTORE_STATUS_DIR, using $MARKER_STATUS_DIR for markers"
RESTORE_SUCCESS_MARKER="$RESTORE_SUCCESS_MARKER_TMP"
RESTORE_FAILED_MARKER="$RESTORE_FAILED_MARKER_TMP"
else
rm -f "$RESTORE_STATUS_DIR/.test-write" 2>/dev/null || true
fi
echo "🔍 Checking restoration status..."
@@ -42,53 +55,36 @@ echo "🔍 Checking for backups to restore..."
BACKUP_DIRS="/backups"
# Function to find and validate the most recent backup
find_latest_backup() {
# Priority 1: Legacy single backup file
if [ -f "/var/lib/mysql-persistent/backup.sql" ]; then
if head -10 "/var/lib/mysql-persistent/backup.sql" | grep -q "CREATE DATABASE\|INSERT INTO\|CREATE TABLE"; then
echo "/var/lib/mysql-persistent/backup.sql"
return 0
fi
fi
# Priority 2: Modern timestamped backups
if [ -d "$BACKUP_DIRS" ] && [ "$(ls -A $BACKUP_DIRS)" ]; then
# Try daily backups first
if [ -d "$BACKUP_DIRS/daily" ] && [ "$(ls -A $BACKUP_DIRS/daily)" ]; then
local latest_daily=$(ls -1t $BACKUP_DIRS/daily | head -n 1)
if [ -n "$latest_daily" ] && [ -d "$BACKUP_DIRS/daily/$latest_daily" ]; then
# Validate backup has actual data
if ls "$BACKUP_DIRS/daily/$latest_daily"/*.sql.gz >/dev/null 2>&1; then
for backup_file in "$BACKUP_DIRS/daily/$latest_daily"/*.sql.gz; do
if [ -f "$backup_file" ] && [ -s "$backup_file" ]; then
if zcat "$backup_file" | head -20 | grep -q "CREATE DATABASE\|INSERT INTO\|CREATE TABLE"; then
echo "$BACKUP_DIRS/daily/$latest_daily"
return 0
fi
fi
done
fi
fi
fi
fi
return 1
}
# Function to restore from timestamped backup directory
# Function to restore from backup (directory or single file)
restore_from_directory() {
local backup_dir="$1"
echo "🔄 Restoring from backup directory: $backup_dir"
local backup_path="$1"
echo "🔄 Restoring from backup: $backup_path"
local restore_success=true
# Restore each database backup
for backup_file in "$backup_dir"/*.sql.gz; do
# Handle single .sql file (legacy backup)
if [ -f "$backup_path" ] && [[ "$backup_path" == *.sql ]]; then
echo "📥 Restoring legacy backup file: $(basename "$backup_path")"
if timeout 300 mysql -h ${CONTAINER_MYSQL} -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} < "$backup_path"; then
echo "✅ Successfully restored legacy backup"
return 0
else
echo "❌ Failed to restore legacy backup"
return 1
fi
fi
# Handle directory with .sql.gz files (modern timestamped backups)
if [ -d "$backup_path" ]; then
echo "🔄 Restoring from backup directory: $backup_path"
# Restore each database backup
for backup_file in "$backup_path"/*.sql.gz; do
if [ -f "$backup_file" ]; then
local db_name=$(basename "$backup_file" .sql.gz)
echo "📥 Restoring database: $db_name"
if zcat "$backup_file" | mysql -h ${CONTAINER_MYSQL} -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD}; then
if timeout 300 zcat "$backup_file" | mysql -h ${CONTAINER_MYSQL} -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD}; then
echo "✅ Successfully restored $db_name"
else
echo "❌ Failed to restore $db_name"
@@ -97,16 +93,76 @@ restore_from_directory() {
fi
done
if [ "$restore_success" = true ]; then
return 0
else
return 1
if [ "$restore_success" = true ]; then
return 0
else
return 1
fi
fi
# If we get here, backup_path is neither a valid .sql file nor a directory
echo "❌ Invalid backup path: $backup_path (not a .sql file or directory)"
return 1
}
# Attempt backup restoration
backup_path=$(find_latest_backup)
if [ $? -eq 0 ] && [ -n "$backup_path" ]; then
# Attempt backup restoration with full functionality restored
echo "🔄 Checking for backups..."
backup_path=""
# Priority 1: Legacy single backup file with content validation
echo "🔍 Checking for legacy backup file..."
if [ -f "/var/lib/mysql-persistent/backup.sql" ]; then
echo "📄 Found legacy backup file, validating content..."
if timeout 10 head -10 "/var/lib/mysql-persistent/backup.sql" 2>/dev/null | grep -q "CREATE DATABASE\|INSERT INTO\|CREATE TABLE"; then
echo "✅ Legacy backup file validated"
backup_path="/var/lib/mysql-persistent/backup.sql"
else
echo "⚠️ Legacy backup file exists but appears invalid or empty"
fi
else
echo "🔍 No legacy backup found"
fi
# Priority 2: Modern timestamped backups (only if no legacy backup found)
if [ -z "$backup_path" ] && [ -d "$BACKUP_DIRS" ]; then
echo "📁 Backup directory exists, checking for timestamped backups..."
if [ "$(ls -A $BACKUP_DIRS 2>/dev/null | wc -l)" -gt 0 ]; then
# Check daily backups first
if [ -d "$BACKUP_DIRS/daily" ] && [ "$(ls -A $BACKUP_DIRS/daily 2>/dev/null | wc -l)" -gt 0 ]; then
echo "📅 Found daily backup directory, finding latest..."
latest_daily=$(ls -1t $BACKUP_DIRS/daily 2>/dev/null | head -n 1)
if [ -n "$latest_daily" ] && [ -d "$BACKUP_DIRS/daily/$latest_daily" ]; then
echo "📦 Checking backup directory: $latest_daily"
# Check if directory has .sql.gz files
if ls "$BACKUP_DIRS/daily/$latest_daily"/*.sql.gz >/dev/null 2>&1; then
# Validate at least one backup file has content
echo "🔍 Validating backup content..."
for backup_file in "$BACKUP_DIRS/daily/$latest_daily"/*.sql.gz; do
if [ -f "$backup_file" ] && [ -s "$backup_file" ]; then
# Use timeout to prevent hanging on zcat
if timeout 10 zcat "$backup_file" 2>/dev/null | head -20 | grep -q "CREATE DATABASE\|INSERT INTO\|CREATE TABLE"; then
echo "✅ Valid backup found: $(basename $backup_file)"
backup_path="$BACKUP_DIRS/daily/$latest_daily"
break
fi
fi
done
else
echo "⚠️ No .sql.gz files found in backup directory"
fi
fi
else
echo "📅 No daily backup directory found"
fi
else
echo "📁 Backup directory is empty"
fi
else
echo "📁 No backup directory found or legacy backup already selected"
fi
echo "🔄 Final backup path result: '$backup_path'"
if [ -n "$backup_path" ]; then
echo "📦 Found backup: $(basename $backup_path)"
if restore_from_directory "$backup_path"; then
echo "✅ Database restoration completed successfully!"
@@ -210,7 +266,12 @@ if ./dbimport; then
echo "✅ Database import completed successfully!"
# Create import completion marker
echo "$(date): Database import completed successfully" > "$RESTORE_STATUS_DIR/.import-completed"
if touch "$RESTORE_STATUS_DIR/.import-completed" 2>/dev/null; then
echo "$(date): Database import completed successfully" > "$RESTORE_STATUS_DIR/.import-completed"
else
echo "$(date): Database import completed successfully" > "$MARKER_STATUS_DIR/.import-completed"
echo "⚠️ Using temporary location for completion marker"
fi
# Verify import was successful
echo "🔍 Verifying import results..."
@@ -230,7 +291,12 @@ if ./dbimport; then
fi
else
echo "❌ Database import failed!"
echo "$(date): Database import failed" > "$RESTORE_STATUS_DIR/.import-failed"
if touch "$RESTORE_STATUS_DIR/.import-failed" 2>/dev/null; then
echo "$(date): Database import failed" > "$RESTORE_STATUS_DIR/.import-failed"
else
echo "$(date): Database import failed" > "$MARKER_STATUS_DIR/.import-failed"
echo "⚠️ Using temporary location for failed marker"
fi
exit 1
fi

View File

@@ -138,7 +138,7 @@ wait_for_service() {
case "$service_name" in
"Client Data")
local last_log=$(docker logs "$container_name" --tail 1 2>/dev/null | head -c 80 || echo "...")
printf "${YELLOW}${NC} ${elapsed}s elapsed, ${remaining}s remaining | Status: $status | Latest: $last_log\n"
printf "%s⏳%s %ss elapsed, %ss remaining | Status: %s | Latest: %s\n" "${YELLOW}" "${NC}" "${elapsed}" "${remaining}" "$status" "$last_log"
;;
"Database Import")
printf "${YELLOW}${NC} ${elapsed}s elapsed, ${remaining}s remaining | Status: $status | Importing databases...\n"
@@ -330,7 +330,7 @@ deploy_stack() {
# Wait for client data extraction
print_status "INFO" "Waiting for client data download and extraction (this may take 15-25 minutes)..."
print_status "INFO" "Press Ctrl+C to exit if needed..."
wait_for_service "Client Data" 999999 "docker logs ac-client-data 2>/dev/null | grep -q 'Game data setup complete'"
wait_for_service "Client Data" 480 "docker logs ac-client-data 2>/dev/null | grep -q 'Game data setup complete'"
# Wait for worldserver to be healthy
wait_for_service "World Server" 24 "check_container_health ac-worldserver"

View File

@@ -294,7 +294,7 @@ main() {
else
echo "Storage options:"
echo "1) ./storage (local directory)"
echo "2) /nfs/containers (NFS mount)"
echo "2) /nfs/azerothcore (NFS mount)"
echo "3) Custom path"
while true; do
@@ -305,7 +305,7 @@ main() {
break
;;
2)
STORAGE_ROOT="/nfs/containers"
STORAGE_ROOT="/nfs/azerothcore"
break
;;
3)
@@ -348,7 +348,7 @@ main() {
# Create directories if requested
if [ "$PRE_CREATE_DIRECTORIES" = true ]; then
print_status "INFO" "Creating storage directories..."
STORAGE_PATH="${STORAGE_ROOT}/azerothcore"
STORAGE_PATH="${STORAGE_ROOT}"
# Create all required directories
DIRECTORIES=(

View File

@@ -167,6 +167,12 @@ display_service_status() {
printf "${CYAN}%-20s${NC} " "$service_display_name"
get_container_status "$container_name"
# Show image name if container exists
if docker ps -a --format "table {{.Names}}" | grep -q "^${container_name}$"; then
local image_name=$(docker inspect --format='{{.Config.Image}}' "$container_name" 2>/dev/null || echo "unknown")
printf " ${CYAN}🏷️ Image: $image_name${NC}\n"
fi
if [ "$SHOW_LOGS" = true ]; then
show_service_logs "$container_name" "$service_display_name"
fi
@@ -191,6 +197,45 @@ get_client_data_progress() {
fi
}
# Function to get enabled modules info
get_enabled_modules() {
printf "${CYAN}%-20s${NC} " "Enabled Modules"
# Check if modules are enabled by looking for environment files
local modules_enabled=false
local module_count=0
local modules_list=""
if [ -f "docker-compose-azerothcore-modules.env" ] || [ -f "docker-compose-azerothcore-modules-custom.env" ]; then
# Check for playerbots module
if docker ps --format "table {{.Names}}" | grep -q "^ac-modules$"; then
if docker logs ac-modules 2>/dev/null | grep -q "playerbot\|playerbots"; then
modules_list="playerbots"
module_count=$((module_count + 1))
modules_enabled=true
fi
fi
# Check for eluna module
if docker ps --format "table {{.Names}}" | grep -q "^ac-eluna$"; then
if [ -n "$modules_list" ]; then
modules_list="$modules_list, eluna"
else
modules_list="eluna"
fi
module_count=$((module_count + 1))
modules_enabled=true
fi
fi
if [ "$modules_enabled" = true ]; then
printf "${GREEN}${NC} $module_count modules active\n"
printf " ${CYAN}📦 Modules: $modules_list${NC}\n"
else
printf "${YELLOW}${NC} No modules enabled\n"
fi
}
# Main status display function
show_status() {
# Capture all output to a temp file, then display at once
@@ -228,6 +273,11 @@ show_status() {
display_service_status "ac-post-install" "Post-Install" "Configuration automation"
echo ""
# Enabled Modules
printf "${MAGENTA}=== MODULE STATUS ===${NC}\n"
get_enabled_modules
echo ""
# Network and ports
printf "${MAGENTA}=== NETWORK STATUS ===${NC}\n"
if docker network ls | grep -q azerothcore; then