From 11951fd515096e95fb4cef3430855ae83b2d4515 Mon Sep 17 00:00:00 2001 From: uprightbass360 Date: Tue, 30 Sep 2025 14:05:20 -0400 Subject: [PATCH] add scripts --- .gitignore | 3 +- readme.md | 1 + scripts/CLEANUP.md | 238 ++++++++++++++++++++++++ scripts/DEPLOYMENT.md | 167 +++++++++++++++++ scripts/README.md | 67 +++++++ scripts/cleanup.sh | 360 ++++++++++++++++++++++++++++++++++++ scripts/deploy-and-check.sh | 344 ++++++++++++++++++++++++++++++++++ 7 files changed, 1179 insertions(+), 1 deletion(-) create mode 100644 scripts/CLEANUP.md create mode 100644 scripts/DEPLOYMENT.md create mode 100644 scripts/README.md create mode 100755 scripts/cleanup.sh create mode 100755 scripts/deploy-and-check.sh diff --git a/.gitignore b/.gitignore index 30cb557..3e48106 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data/ -backups/ \ No newline at end of file +backups/ +local-data-tools/ diff --git a/readme.md b/readme.md index 17619be..499b450 100644 --- a/readme.md +++ b/readme.md @@ -226,6 +226,7 @@ Configuration is managed through separate `.env` files for each layer: #### Database Layer (`docker-compose-azerothcore-database.env`) - `MYSQL_ROOT_PASSWORD`: Database root password (default: azerothcore123) +- `MYSQL_EXTERNAL_PORT`: External MySQL port (default: 64306) - `STORAGE_PATH`: Data storage path (default: /nfs/containers/azerothcore) - `NETWORK_SUBNET`: Docker network subnet - `BACKUP_RETENTION_DAYS`: Backup retention period diff --git a/scripts/CLEANUP.md b/scripts/CLEANUP.md new file mode 100644 index 0000000..4092f8d --- /dev/null +++ b/scripts/CLEANUP.md @@ -0,0 +1,238 @@ +# AzerothCore Cleanup Script + +This script provides safe and comprehensive cleanup options for AzerothCore Docker resources with multiple levels of cleanup intensity. + +## Quick Reference + +```bash +cd scripts + +# Safe cleanup - stop containers only +./cleanup.sh --soft + +# Moderate cleanup - remove containers and networks (preserves data) +./cleanup.sh --hard + +# Complete cleanup - remove everything (DESTROYS ALL DATA) +./cleanup.sh --nuclear + +# See what would happen without doing it +./cleanup.sh --hard --dry-run +``` + +## Cleanup Levels + +### ๐ŸŸข **Soft Cleanup** (`--soft`) +- **What it does**: Stops all AzerothCore containers +- **What it preserves**: Everything (data, networks, images) +- **Use case**: Temporary shutdown, reboot, or switching between deployments +- **Recovery**: Quick restart with deployment script + +```bash +./cleanup.sh --soft +``` + +**After soft cleanup:** +- All your game data is safe +- Quick restart: `./deploy-and-check.sh --skip-deploy` + +### ๐ŸŸก **Hard Cleanup** (`--hard`) +- **What it does**: Removes containers and networks +- **What it preserves**: Data volumes and Docker images +- **Use case**: Clean slate deployment while keeping your data +- **Recovery**: Full deployment (but reuses existing data) + +```bash +./cleanup.sh --hard +``` + +**After hard cleanup:** +- Your database and game data is preserved +- Fresh deployment: `./deploy-and-check.sh` +- No need to re-download client data + +### ๐Ÿ”ด **Nuclear Cleanup** (`--nuclear`) +- **What it does**: Removes EVERYTHING +- **What it preserves**: Nothing +- **Use case**: Complete fresh start or when troubleshooting major issues +- **Recovery**: Full deployment with fresh downloads + +```bash +./cleanup.sh --nuclear +``` + +**โš ๏ธ WARNING: This permanently deletes ALL AzerothCore data including:** +- Database schemas and characters +- Client data (15GB+ will need re-download) +- Configuration files +- Logs and backups +- All containers and images + +## Command Options + +| Option | Description | +|--------|-------------| +| `--soft` | Stop containers only (safest) | +| `--hard` | Remove containers + networks (preserves data) | +| `--nuclear` | Complete removal (DESTROYS ALL DATA) | +| `--dry-run` | Show what would be done without actually doing it | +| `--force` | Skip confirmation prompts (useful for scripts) | +| `--help` | Show help message | + +## Examples + +### Safe Exploration +```bash +# See what would be removed with hard cleanup +./cleanup.sh --hard --dry-run + +# See what would be removed with nuclear cleanup +./cleanup.sh --nuclear --dry-run +``` + +### Automated Scripts +```bash +# Force cleanup without prompts (for CI/CD) +./cleanup.sh --hard --force + +# Dry run for validation +./cleanup.sh --nuclear --dry-run --force +``` + +### Interactive Cleanup +```bash +# Standard cleanup with confirmation +./cleanup.sh --hard + +# Will prompt: "Are you sure? (yes/no):" +``` + +## What Gets Cleaned + +### Resources Identified +The script automatically identifies and shows: +- **Containers**: All `ac-*` containers (running and stopped) +- **Networks**: `azerothcore` and related networks +- **Volumes**: AzerothCore data volumes (if any named volumes exist) +- **Images**: AzerothCore server images and related tools + +### Cleanup Actions by Level + +| Resource Type | Soft | Hard | Nuclear | +|---------------|------|------|---------| +| Containers | Stop | Remove | Remove | +| Networks | Keep | Remove | Remove | +| Volumes | Keep | Keep | **DELETE** | +| Images | Keep | Keep | **DELETE** | +| Local Data | Keep | Keep | **DELETE** | + +## Recovery After Cleanup + +### After Soft Cleanup +```bash +# Quick restart (containers only) +./deploy-and-check.sh --skip-deploy + +# Or restart specific layer +docker compose -f ../docker-compose-azerothcore-services.yml up -d +``` + +### After Hard Cleanup +```bash +# Full deployment (reuses existing data) +./deploy-and-check.sh +``` + +### After Nuclear Cleanup +```bash +# Complete fresh deployment +./deploy-and-check.sh + +# This will: +# - Download ~15GB client data again +# - Import fresh database schemas +# - Create new containers and networks +``` + +## Safety Features + +### Confirmation Prompts +- All destructive operations require confirmation +- Clear warnings about data loss +- Use `--force` to skip prompts for automation + +### Dry Run Mode +- See exactly what would be done +- No actual changes made +- Perfect for understanding impact + +### Resource Detection +- Shows current resources before cleanup +- Identifies exactly what will be affected +- Prevents unnecessary operations + +## Integration with Other Scripts + +### Combined Usage +```bash +# Complete refresh workflow +./cleanup.sh --hard --force +./deploy-and-check.sh + +# Troubleshooting workflow +./cleanup.sh --nuclear --dry-run # See what would be removed +./cleanup.sh --nuclear --force # If needed +./deploy-and-check.sh # Fresh start +``` + +### CI/CD Usage +```bash +# Automated cleanup in pipelines +./cleanup.sh --hard --force +./deploy-and-check.sh --skip-deploy || ./deploy-and-check.sh +``` + +## Troubleshooting + +### Common Issues + +**Cleanup hangs or fails:** +```bash +# Force remove stuck containers +docker kill $(docker ps -q --filter "name=ac-") +docker rm $(docker ps -aq --filter "name=ac-") +``` + +**Permission errors:** +```bash +# Some local directories might need sudo +sudo ./cleanup.sh --nuclear +``` + +**Resources not found:** +- This is normal if no AzerothCore deployment exists +- Script will show "No resources found" and exit safely + +### Manual Cleanup +If the script fails, you can manually clean up: + +```bash +# Manual container removal +docker ps -a --format '{{.Names}}' | grep '^ac-' | xargs docker rm -f + +# Manual network removal +docker network rm azerothcore + +# Manual volume removal (DESTROYS DATA) +docker volume ls --format '{{.Name}}' | grep 'ac_' | xargs docker volume rm + +# Manual image removal +docker images --format '{{.Repository}}:{{.Tag}}' | grep '^acore/' | xargs docker rmi +``` + +## Exit Codes + +- **0**: Cleanup completed successfully +- **1**: Error occurred or user cancelled operation + +Use these exit codes in scripts to handle cleanup results appropriately. \ No newline at end of file diff --git a/scripts/DEPLOYMENT.md b/scripts/DEPLOYMENT.md new file mode 100644 index 0000000..4216018 --- /dev/null +++ b/scripts/DEPLOYMENT.md @@ -0,0 +1,167 @@ +# AzerothCore Deployment & Health Check + +This document describes how to use the automated deployment and health check script for the AzerothCore Docker stack. + +## Quick Start + +The script is located in the `scripts/` directory and should be run from there: + +### Full Deployment and Health Check +```bash +cd scripts +./deploy-and-check.sh +``` + +### Health Check Only (Skip Deployment) +```bash +cd scripts +./deploy-and-check.sh --skip-deploy +``` + +### Quick Health Check (Basic Tests Only) +```bash +cd scripts +./deploy-and-check.sh --skip-deploy --quick-check +``` + +## Script Features + +### Deployment +- **Layered Deployment**: Deploys database โ†’ services โ†’ tools layers in correct order +- **Dependency Waiting**: Waits for each layer to be ready before proceeding +- **Error Handling**: Stops on errors with clear error messages +- **Progress Monitoring**: Shows deployment progress and status + +### Health Checks +- **Container Health**: Verifies all containers are running and healthy +- **Port Connectivity**: Tests all external ports are accessible +- **Web Service Verification**: Validates web interfaces are responding correctly +- **Database Validation**: Confirms database schemas and realm configuration +- **Comprehensive Reporting**: Color-coded status with detailed results + +## Command Line Options + +| Option | Description | +|--------|-------------| +| `--skip-deploy` | Skip the deployment phase, only run health checks | +| `--quick-check` | Run basic health checks only (faster, less comprehensive) | +| `--help` | Show usage information | + +## What Gets Checked + +### Container Health Status +- โœ… **ac-mysql**: Database server +- โœ… **ac-backup**: Automated backup service +- โœ… **ac-authserver**: Authentication server +- โœ… **ac-worldserver**: Game world server +- โœ… **ac-phpmyadmin**: Database management interface +- โœ… **ac-keira3**: Database editor +- โœ… **ac-grafana**: Monitoring dashboard +- โœ… **ac-influxdb**: Metrics database + +### Port Connectivity Tests +- **Database Layer**: MySQL (64306) +- **Services Layer**: Auth Server (3784), World Server (8215), SOAP API (7778) +- **Tools Layer**: PHPMyAdmin (8081), Keira3 (4201), Grafana (3001), InfluxDB (8087) + +### Web Service Health Checks (Full Mode Only) +- **PHPMyAdmin**: HTTP response and content verification +- **Keira3**: Health endpoint and content verification +- **Grafana**: API health check +- **InfluxDB**: Health endpoint validation + +### Database Validation (Full Mode Only) +- **Schema Verification**: Confirms all required databases exist +- **Realm Configuration**: Validates realm setup + +## Service URLs and Credentials + +### Web Interfaces +- ๐ŸŒ **PHPMyAdmin**: http://localhost:8081 +- ๐Ÿ› ๏ธ **Keira3**: http://localhost:4201 +- ๐Ÿ“Š **Grafana**: http://localhost:3001 +- ๐Ÿ“ˆ **InfluxDB**: http://localhost:8087 + +### Game Connections +- ๐ŸŽฎ **Game Server**: localhost:8215 +- ๐Ÿ” **Auth Server**: localhost:3784 +- ๐Ÿ”ง **SOAP API**: localhost:7778 +- ๐Ÿ—„๏ธ **MySQL**: localhost:64306 + +### Default Credentials +- **Grafana**: admin / acore123 +- **InfluxDB**: acore / acore123 +- **MySQL**: root / azerothcore123 + +## Deployment Process + +The script follows this deployment sequence: + +### 1. Database Layer +- Deploys MySQL database server +- Waits for MySQL to be ready +- Runs database initialization +- Imports AzerothCore schemas +- Starts backup service + +### 2. Services Layer +- Deploys authentication server +- Starts client data download/extraction (10-20 minutes) +- Deploys world server (waits for client data) +- Starts module management service + +### 3. Tools Layer +- Deploys PHPMyAdmin database interface +- Deploys Keira3 database editor +- Deploys Grafana monitoring +- Deploys InfluxDB metrics database + +## Troubleshooting + +### Common Issues + +**Port conflicts**: If ports are already in use, modify the environment files to use different external ports. + +**Slow client data download**: The initial download is ~15GB and may take 10-30 minutes depending on connection speed. + +**Container restart loops**: Check container logs with `docker logs ` for specific error messages. + +### Manual Checks + +```bash +# Check container status +docker ps | grep ac- + +# Check specific container logs +docker logs ac-worldserver --tail 50 + +# Test port connectivity manually +nc -z localhost 8215 + +# Check container health +docker inspect ac-mysql --format='{{.State.Health.Status}}' +``` + +### Recovery Commands + +```bash +# Restart specific layer +docker compose -f docker-compose-azerothcore-services.yml restart + +# Reset specific service +docker compose -f docker-compose-azerothcore-services.yml stop ac-worldserver +docker compose -f docker-compose-azerothcore-services.yml up -d ac-worldserver + +# Full reset (WARNING: destroys all data) +docker compose -f docker-compose-azerothcore-tools.yml down +docker compose -f docker-compose-azerothcore-services.yml down +docker compose -f docker-compose-azerothcore-database.yml down +docker volume prune -f +``` + +## Script Exit Codes + +- **0**: All health checks passed successfully +- **1**: Health check failures detected or deployment errors + +Use the exit code in CI/CD pipelines or automated deployment scripts to determine deployment success. \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..3856592 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,67 @@ +# Scripts Directory + +This directory contains deployment and validation scripts for the AzerothCore Docker deployment. + +## Contents + +- **`deploy-and-check.sh`** - Automated deployment and comprehensive health check script +- **`cleanup.sh`** - Resource cleanup script with multiple cleanup levels +- **`DEPLOYMENT.md`** - Complete documentation for the deployment script +- **`CLEANUP.md`** - Complete documentation for the cleanup script + +## Quick Usage + +### Run Health Check on Current Deployment +```bash +cd scripts +./deploy-and-check.sh --skip-deploy +``` + +### Full Deployment with Health Checks +```bash +cd scripts +./deploy-and-check.sh +``` + +### Quick Health Check (Basic Tests Only) +```bash +cd scripts +./deploy-and-check.sh --skip-deploy --quick-check +``` + +### Cleanup Resources +```bash +cd scripts + +# Stop containers only (safe) +./cleanup.sh --soft + +# Remove containers + networks (preserves data) +./cleanup.sh --hard + +# Complete removal (DESTROYS ALL DATA) +./cleanup.sh --nuclear + +# Dry run to see what would happen +./cleanup.sh --hard --dry-run +``` + +## Features + +โœ… **Container Health Validation**: Checks all 8 core containers +โœ… **Port Connectivity Tests**: Validates all external ports +โœ… **Web Service Verification**: HTTP response and content validation +โœ… **Database Validation**: Schema and realm configuration checks +โœ… **Automated Deployment**: Three-layer deployment (database โ†’ services โ†’ tools) +โœ… **Comprehensive Reporting**: Color-coded status with detailed results + +## Variable Names Verified + +The scripts validate the updated variable names: +- `MYSQL_EXTERNAL_PORT` (was `DOCKER_DB_EXTERNAL_PORT`) +- `AUTH_EXTERNAL_PORT` (was `DOCKER_AUTH_EXTERNAL_PORT`) +- `WORLD_EXTERNAL_PORT` (was `DOCKER_WORLD_EXTERNAL_PORT`) +- `SOAP_EXTERNAL_PORT` (was `DOCKER_SOAP_EXTERNAL_PORT`) +- `MYSQL_ROOT_PASSWORD` (was `DOCKER_DB_ROOT_PASSWORD`) + +For complete documentation, see `DEPLOYMENT.md`. \ No newline at end of file diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100755 index 0000000..66e3677 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,360 @@ +#!/bin/bash + +# ============================================== +# AzerothCore Docker Cleanup Script +# ============================================== +# This script provides various levels of cleanup for AzerothCore Docker resources +# Usage: ./cleanup.sh [--soft] [--hard] [--nuclear] [--dry-run] + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +MAGENTA='\033[0;35m' +NC='\033[0m' # No Color + +# Script options +CLEANUP_LEVEL="" +DRY_RUN=false +FORCE=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --soft) + CLEANUP_LEVEL="soft" + shift + ;; + --hard) + CLEANUP_LEVEL="hard" + shift + ;; + --nuclear) + CLEANUP_LEVEL="nuclear" + shift + ;; + --dry-run) + DRY_RUN=true + shift + ;; + --force) + FORCE=true + shift + ;; + -h|--help) + echo "AzerothCore Docker Cleanup Script" + echo "" + echo "Usage: $0 [CLEANUP_LEVEL] [OPTIONS]" + echo "" + echo "CLEANUP LEVELS:" + echo " --soft Stop containers only (preserves data)" + echo " --hard Stop containers + remove containers + networks (preserves volumes/data)" + echo " --nuclear Complete removal: containers + networks + volumes + images (DESTROYS ALL DATA)" + echo "" + echo "OPTIONS:" + echo " --dry-run Show what would be done without actually doing it" + echo " --force Skip confirmation prompts" + echo " --help Show this help message" + echo "" + echo "EXAMPLES:" + echo " $0 --soft # Stop all containers" + echo " $0 --hard --dry-run # Show what hard cleanup would do" + echo " $0 --nuclear --force # Complete removal without prompts" + exit 0 + ;; + *) + echo "Unknown option $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +# Function to print colored output +print_status() { + local status=$1 + local message=$2 + case $status in + "INFO") + echo -e "${BLUE}โ„น๏ธ ${message}${NC}" + ;; + "SUCCESS") + echo -e "${GREEN}โœ… ${message}${NC}" + ;; + "WARNING") + echo -e "${YELLOW}โš ๏ธ ${message}${NC}" + ;; + "ERROR") + echo -e "${RED}โŒ ${message}${NC}" + ;; + "DANGER") + echo -e "${RED}๐Ÿ’€ ${message}${NC}" + ;; + "HEADER") + echo -e "\n${MAGENTA}=== ${message} ===${NC}" + ;; + esac +} + +# Function to execute command with dry-run support +execute_command() { + local description=$1 + local command=$2 + + if [ "$DRY_RUN" = true ]; then + print_status "INFO" "[DRY RUN] Would execute: $description" + echo " Command: $command" + else + print_status "INFO" "Executing: $description" + if eval "$command"; then + print_status "SUCCESS" "Completed: $description" + else + print_status "WARNING" "Failed or no action needed: $description" + fi + fi +} + +# Function to get confirmation +get_confirmation() { + local message=$1 + + if [ "$FORCE" = true ]; then + print_status "INFO" "Force mode enabled, skipping confirmation" + return 0 + fi + + echo -e "${YELLOW}โš ๏ธ ${message}${NC}" + read -p "Are you sure? (yes/no): " response + case $response in + yes|YES|y|Y) + return 0 + ;; + *) + print_status "INFO" "Operation cancelled by user" + exit 0 + ;; + esac +} + +# Function to show current resources +show_current_resources() { + print_status "HEADER" "CURRENT AZEROTHCORE RESOURCES" + + echo -e "${BLUE}Containers:${NC}" + if docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Image}}" | grep -E "ac-|acore" | head -20; then + echo "" + else + echo " No AzerothCore containers found" + fi + + echo -e "${BLUE}Networks:${NC}" + if docker network ls --format "table {{.Name}}\t{{.Driver}}\t{{.Scope}}" | grep -E "azerothcore|acore"; then + echo "" + else + echo " No AzerothCore networks found" + fi + + echo -e "${BLUE}Volumes:${NC}" + if docker volume ls --format "table {{.Name}}\t{{.Driver}}" | grep -E "ac_|acore|azerothcore"; then + echo "" + else + echo " No AzerothCore volumes found" + fi + + echo -e "${BLUE}Images:${NC}" + if docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep -E "acore|azerothcore|phpmyadmin|grafana|influxdb|keira3" | head -10; then + echo "" + else + echo " No AzerothCore-related images found" + fi +} + +# Function to perform soft cleanup +soft_cleanup() { + print_status "HEADER" "SOFT CLEANUP - STOPPING CONTAINERS" + + get_confirmation "This will stop all AzerothCore containers but preserve all data." + + # Stop tools layer + execute_command "Stop tools layer" \ + "docker compose --env-file ../docker-compose-azerothcore-tools.env -f ../docker-compose-azerothcore-tools.yml down" + + # Stop services layer + execute_command "Stop services layer" \ + "docker compose --env-file ../docker-compose-azerothcore-services.env -f ../docker-compose-azerothcore-services.yml down" + + # Stop database layer + execute_command "Stop database layer" \ + "docker compose --env-file ../docker-compose-azerothcore-database.env -f ../docker-compose-azerothcore-database.yml down" + + print_status "SUCCESS" "Soft cleanup completed - all containers stopped" + print_status "INFO" "Data volumes and images are preserved" + print_status "INFO" "Use 'docker compose up -d' to restart services" +} + +# Function to perform hard cleanup +hard_cleanup() { + print_status "HEADER" "HARD CLEANUP - REMOVING CONTAINERS AND NETWORKS" + + get_confirmation "This will remove all containers and networks but preserve data volumes and images." + + # Remove containers and networks + execute_command "Remove tools layer (containers + networks)" \ + "docker compose --env-file ../docker-compose-azerothcore-tools.env -f ../docker-compose-azerothcore-tools.yml down --remove-orphans" + + execute_command "Remove services layer (containers + networks)" \ + "docker compose --env-file ../docker-compose-azerothcore-services.env -f ../docker-compose-azerothcore-services.yml down --remove-orphans" + + execute_command "Remove database layer (containers + networks)" \ + "docker compose --env-file ../docker-compose-azerothcore-database.env -f ../docker-compose-azerothcore-database.yml down --remove-orphans" + + # Clean up any remaining AzerothCore containers + execute_command "Remove any remaining AzerothCore containers" \ + "docker ps -a --format '{{.Names}}' | grep -E '^ac-' | xargs -r docker rm -f" + + # Clean up AzerothCore networks + execute_command "Remove AzerothCore networks" \ + "docker network ls --format '{{.Name}}' | grep -E 'azerothcore|acore' | xargs -r docker network rm" + + print_status "SUCCESS" "Hard cleanup completed - containers and networks removed" + print_status "INFO" "Data volumes and images are preserved" + print_status "INFO" "Run full deployment script to recreate the stack" +} + +# Function to perform nuclear cleanup +nuclear_cleanup() { + print_status "HEADER" "NUCLEAR CLEANUP - COMPLETE REMOVAL" + print_status "DANGER" "THIS WILL DESTROY ALL DATA AND REMOVE EVERYTHING!" + + get_confirmation "This will permanently delete ALL AzerothCore data, containers, networks, volumes, and images. This action CANNOT be undone!" + + # Stop and remove everything + execute_command "Stop and remove tools layer (with volumes)" \ + "docker compose --env-file ../docker-compose-azerothcore-tools.env -f ../docker-compose-azerothcore-tools.yml down --volumes --remove-orphans" + + execute_command "Stop and remove services layer (with volumes)" \ + "docker compose --env-file ../docker-compose-azerothcore-services.env -f ../docker-compose-azerothcore-services.yml down --volumes --remove-orphans" + + execute_command "Stop and remove database layer (with volumes)" \ + "docker compose --env-file ../docker-compose-azerothcore-database.env -f ../docker-compose-azerothcore-database.yml down --volumes --remove-orphans" + + # Remove any remaining containers + execute_command "Remove any remaining AzerothCore containers" \ + "docker ps -a --format '{{.Names}}' | grep -E '^ac-|acore' | xargs -r docker rm -f" + + # Remove networks + execute_command "Remove AzerothCore networks" \ + "docker network ls --format '{{.Name}}' | grep -E 'azerothcore|acore' | xargs -r docker network rm" + + # Remove volumes + execute_command "Remove AzerothCore volumes" \ + "docker volume ls --format '{{.Name}}' | grep -E '^ac_|acore|azerothcore' | xargs -r docker volume rm" + + # Remove images + execute_command "Remove AzerothCore server images" \ + "docker images --format '{{.Repository}}:{{.Tag}}' | grep -E '^acore/' | xargs -r docker rmi" + + execute_command "Remove related tool images" \ + "docker images --format '{{.Repository}}:{{.Tag}}' | grep -E 'phpmyadmin|grafana|influxdb|uprightbass360/keira3' | xargs -r docker rmi" + + # Clean up local data directories + execute_command "Remove local data directories" \ + "sudo rm -rf ../local-data-tools ../backups" + + # System cleanup + execute_command "Clean up unused Docker resources" \ + "docker system prune -af --volumes" + + print_status "SUCCESS" "Nuclear cleanup completed - everything removed" + print_status "DANGER" "ALL AZEROTHCORE DATA HAS BEEN PERMANENTLY DELETED" + print_status "INFO" "Run full deployment script to start fresh" +} + +# Function to show cleanup summary +show_cleanup_summary() { + local level=$1 + + print_status "HEADER" "CLEANUP SUMMARY" + + case $level in + "soft") + echo -e "${GREEN}โœ… Containers: Stopped${NC}" + echo -e "${BLUE}โ„น๏ธ Networks: Preserved${NC}" + echo -e "${BLUE}โ„น๏ธ Volumes: Preserved (data safe)${NC}" + echo -e "${BLUE}โ„น๏ธ Images: Preserved${NC}" + echo "" + echo -e "${GREEN}Next steps:${NC}" + echo " โ€ข To restart: cd scripts && ./deploy-and-check.sh --skip-deploy" + echo " โ€ข To deploy fresh: cd scripts && ./deploy-and-check.sh" + ;; + "hard") + echo -e "${GREEN}โœ… Containers: Removed${NC}" + echo -e "${GREEN}โœ… Networks: Removed${NC}" + echo -e "${BLUE}โ„น๏ธ Volumes: Preserved (data safe)${NC}" + echo -e "${BLUE}โ„น๏ธ Images: Preserved${NC}" + echo "" + echo -e "${GREEN}Next steps:${NC}" + echo " โ€ข To deploy: cd scripts && ./deploy-and-check.sh" + ;; + "nuclear") + echo -e "${RED}๐Ÿ’€ Containers: DESTROYED${NC}" + echo -e "${RED}๐Ÿ’€ Networks: DESTROYED${NC}" + echo -e "${RED}๐Ÿ’€ Volumes: DESTROYED${NC}" + echo -e "${RED}๐Ÿ’€ Images: DESTROYED${NC}" + echo -e "${RED}๐Ÿ’€ Data: PERMANENTLY DELETED${NC}" + echo "" + echo -e "${YELLOW}Next steps:${NC}" + echo " โ€ข To start fresh: cd scripts && ./deploy-and-check.sh" + echo " โ€ข This will re-download ~15GB of client data" + ;; + esac +} + +# Main execution +main() { + print_status "HEADER" "AZEROTHCORE CLEANUP SCRIPT" + + # Check if docker is available + if ! command -v docker &> /dev/null; then + print_status "ERROR" "Docker is not installed or not in PATH" + exit 1 + fi + + # Show help if no cleanup level specified + if [ -z "$CLEANUP_LEVEL" ]; then + echo "Please specify a cleanup level:" + echo " --soft Stop containers only (safe)" + echo " --hard Remove containers + networks (preserves data)" + echo " --nuclear Complete removal (DESTROYS ALL DATA)" + echo "" + echo "Use --help for more information" + exit 1 + fi + + # Show current resources + show_current_resources + + # Execute cleanup based on level + case $CLEANUP_LEVEL in + "soft") + soft_cleanup + ;; + "hard") + hard_cleanup + ;; + "nuclear") + nuclear_cleanup + ;; + esac + + # Show final summary + show_cleanup_summary "$CLEANUP_LEVEL" + + print_status "SUCCESS" "๐Ÿงน Cleanup completed successfully!" +} + +# Run main function +main "$@" \ No newline at end of file diff --git a/scripts/deploy-and-check.sh b/scripts/deploy-and-check.sh new file mode 100755 index 0000000..a0026da --- /dev/null +++ b/scripts/deploy-and-check.sh @@ -0,0 +1,344 @@ +#!/bin/bash + +# ============================================== +# AzerothCore Docker Deployment & Health Check Script +# ============================================== +# This script deploys the complete AzerothCore stack and performs comprehensive health checks +# Usage: ./deploy-and-check.sh [--skip-deploy] [--quick-check] + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Script options +SKIP_DEPLOY=false +QUICK_CHECK=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --skip-deploy) + SKIP_DEPLOY=true + shift + ;; + --quick-check) + QUICK_CHECK=true + shift + ;; + -h|--help) + echo "Usage: $0 [--skip-deploy] [--quick-check]" + echo " --skip-deploy Skip deployment, only run health checks" + echo " --quick-check Run basic health checks only" + exit 0 + ;; + *) + echo "Unknown option $1" + exit 1 + ;; + esac +done + +# Function to print colored output +print_status() { + local status=$1 + local message=$2 + case $status in + "INFO") + echo -e "${BLUE}โ„น๏ธ ${message}${NC}" + ;; + "SUCCESS") + echo -e "${GREEN}โœ… ${message}${NC}" + ;; + "WARNING") + echo -e "${YELLOW}โš ๏ธ ${message}${NC}" + ;; + "ERROR") + echo -e "${RED}โŒ ${message}${NC}" + ;; + "HEADER") + echo -e "\n${BLUE}=== ${message} ===${NC}" + ;; + esac +} + +# Function to check if a port is accessible +check_port() { + local port=$1 + local service_name=$2 + local timeout=${3:-5} + + if timeout $timeout bash -c "echo >/dev/tcp/localhost/$port" 2>/dev/null; then + print_status "SUCCESS" "$service_name (port $port): CONNECTED" + return 0 + else + print_status "ERROR" "$service_name (port $port): FAILED" + return 1 + fi +} + +# Function to wait for a service to be ready +wait_for_service() { + local service_name=$1 + local max_attempts=$2 + local check_command=$3 + + print_status "INFO" "Waiting for $service_name to be ready..." + + for i in $(seq 1 $max_attempts); do + if eval "$check_command" &>/dev/null; then + print_status "SUCCESS" "$service_name is ready!" + return 0 + fi + + if [ $i -eq $max_attempts ]; then + print_status "ERROR" "$service_name failed to start after $max_attempts attempts" + return 1 + fi + + echo -n "." + sleep 5 + done +} + +# Function to check container health +check_container_health() { + local container_name=$1 + local status=$(docker inspect --format='{{.State.Health.Status}}' $container_name 2>/dev/null || echo "no-health-check") + + if [ "$status" = "healthy" ]; then + print_status "SUCCESS" "$container_name: healthy" + return 0 + elif [ "$status" = "no-health-check" ] || [ "$status" = "" ]; then + # Check if container is running + if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then + print_status "SUCCESS" "$container_name: running (no health check)" + return 0 + else + print_status "ERROR" "$container_name: not running" + return 1 + fi + else + print_status "WARNING" "$container_name: $status" + return 1 + fi +} + +# Function to check web service health +check_web_service() { + local url=$1 + local service_name=$2 + local expected_pattern=$3 + + response=$(curl -s --max-time 10 "$url" 2>/dev/null || echo "") + + if [ -n "$expected_pattern" ]; then + if echo "$response" | grep -q "$expected_pattern"; then + print_status "SUCCESS" "$service_name: HTTP OK (content verified)" + return 0 + else + print_status "ERROR" "$service_name: HTTP OK but content verification failed" + return 1 + fi + else + if [ -n "$response" ]; then + print_status "SUCCESS" "$service_name: HTTP OK" + return 0 + else + print_status "ERROR" "$service_name: HTTP failed" + return 1 + fi + fi +} + +# Function to deploy the stack +deploy_stack() { + print_status "HEADER" "DEPLOYING AZEROTHCORE STACK" + + # Check if environment files exist (in parent directory) + for env_file in "../docker-compose-azerothcore-database.env" "../docker-compose-azerothcore-services.env" "../docker-compose-azerothcore-tools.env"; do + if [ ! -f "$env_file" ]; then + print_status "ERROR" "Environment file $env_file not found" + exit 1 + fi + done + + print_status "INFO" "Step 1: Deploying database layer..." + docker compose --env-file ../docker-compose-azerothcore-database.env -f ../docker-compose-azerothcore-database.yml up -d + + # Wait for database initialization + wait_for_service "MySQL" 24 "docker exec ac-mysql mysql -uroot -pazerothcore123 -e 'SELECT 1' >/dev/null 2>&1" + + # Wait for database import + wait_for_service "Database Import" 36 "docker logs ac-db-import 2>/dev/null | grep -q 'Database import complete'" + + print_status "INFO" "Step 2: Deploying services layer..." + docker compose --env-file ../docker-compose-azerothcore-services.env -f ../docker-compose-azerothcore-services.yml up -d + + # Wait for client data extraction + print_status "INFO" "Waiting for client data download and extraction (this may take 10-20 minutes)..." + wait_for_service "Client Data" 120 "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" + + print_status "INFO" "Step 3: Deploying tools layer..." + docker compose --env-file ../docker-compose-azerothcore-tools.env -f ../docker-compose-azerothcore-tools.yml up -d + + # Wait for tools to be ready + sleep 10 + + print_status "SUCCESS" "Deployment completed!" +} + +# Function to perform health checks +perform_health_checks() { + print_status "HEADER" "CONTAINER HEALTH STATUS" + + # Check all containers + local containers=("ac-mysql" "ac-backup" "ac-authserver" "ac-worldserver" "ac-phpmyadmin" "ac-keira3" "ac-grafana" "ac-influxdb") + local container_failures=0 + + for container in "${containers[@]}"; do + # Only check containers that actually exist + if docker ps -a --format '{{.Names}}' | grep -q "^${container}$"; then + if ! check_container_health "$container"; then + # Only count as failure if container is not running, not just missing health check + if ! docker ps --format '{{.Names}}' | grep -q "^${container}$"; then + ((container_failures++)) + fi + fi + fi + done + + print_status "HEADER" "PORT CONNECTIVITY TESTS" + + # Database Layer + print_status "INFO" "Database Layer:" + local port_failures=0 + if ! check_port 64306 "MySQL"; then ((port_failures++)); fi + + # Services Layer + print_status "INFO" "Services Layer:" + if ! check_port 3784 "Auth Server"; then ((port_failures++)); fi + if ! check_port 8215 "World Server"; then ((port_failures++)); fi + if ! check_port 7778 "SOAP API"; then ((port_failures++)); fi + + # Tools Layer + print_status "INFO" "Tools Layer:" + if ! check_port 8081 "PHPMyAdmin"; then ((port_failures++)); fi + if ! check_port 4201 "Keira3"; then ((port_failures++)); fi + if ! check_port 3001 "Grafana"; then ((port_failures++)); fi + if ! check_port 8087 "InfluxDB"; then ((port_failures++)); fi + + if [ "$QUICK_CHECK" = false ]; then + print_status "HEADER" "WEB SERVICE HEALTH CHECKS" + + local web_failures=0 + if ! check_web_service "http://localhost:8081/" "PHPMyAdmin" "phpMyAdmin"; then ((web_failures++)); fi + if ! check_web_service "http://localhost:4201/health" "Keira3" "healthy"; then ((web_failures++)); fi + if ! check_web_service "http://localhost:3001/api/health" "Grafana" "database.*ok"; then ((web_failures++)); fi + if ! check_web_service "http://localhost:8087/health" "InfluxDB" "ready for queries"; then ((web_failures++)); fi + + print_status "HEADER" "DATABASE CONNECTIVITY TEST" + + # Test database connectivity and verify schemas + if docker exec ac-mysql mysql -uroot -pazerothcore123 -e "SHOW DATABASES;" 2>/dev/null | grep -q "acore_auth"; then + print_status "SUCCESS" "Database schemas: verified" + else + print_status "ERROR" "Database schemas: verification failed" + ((web_failures++)) + fi + + # Test realm configuration + realm_count=$(docker exec ac-mysql mysql -uroot -pazerothcore123 -e "USE acore_auth; SELECT COUNT(*) FROM realmlist;" 2>/dev/null | tail -1) + if [ "$realm_count" -gt 0 ] 2>/dev/null; then + print_status "SUCCESS" "Realm configuration: $realm_count realm(s) configured" + else + print_status "ERROR" "Realm configuration: no realms found" + ((web_failures++)) + fi + fi + + print_status "HEADER" "DEPLOYMENT SUMMARY" + + # Summary + local total_failures=$((container_failures + port_failures + ${web_failures:-0})) + + if [ $total_failures -eq 0 ]; then + print_status "SUCCESS" "All services are healthy and operational!" + print_status "INFO" "Available services:" + echo " ๐ŸŒ PHPMyAdmin: http://localhost:8081" + echo " ๐Ÿ› ๏ธ Keira3: http://localhost:4201" + echo " ๐Ÿ“Š Grafana: http://localhost:3001" + echo " ๐Ÿ“ˆ InfluxDB: http://localhost:8087" + echo " ๐ŸŽฎ Game Server: localhost:8215" + echo " ๐Ÿ” Auth Server: localhost:3784" + echo " ๐Ÿ”ง SOAP API: localhost:7778" + echo " ๐Ÿ—„๏ธ MySQL: localhost:64306" + echo "" + print_status "INFO" "Default credentials:" + echo " ๐Ÿ“Š Grafana: admin / acore123" + echo " ๐Ÿ“ˆ InfluxDB: acore / acore123" + echo " ๐Ÿ—„๏ธ MySQL: root / azerothcore123" + return 0 + else + print_status "ERROR" "Health check failed with $total_failures issue(s)" + print_status "INFO" "Check container logs for details: docker logs " + return 1 + fi +} + +# Function to show container status +show_container_status() { + print_status "HEADER" "CONTAINER STATUS OVERVIEW" + + echo -e "${BLUE}Container Name\t\tStatus\t\t\tPorts${NC}" + echo "==================================================================" + docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep ac- | while read line; do + echo "$line" + done +} + +# Main execution +main() { + print_status "HEADER" "AZEROTHCORE DEPLOYMENT & HEALTH CHECK" + + # Check if docker is available + if ! command -v docker &> /dev/null; then + print_status "ERROR" "Docker is not installed or not in PATH" + exit 1 + fi + + # Check if docker compose is available + if ! docker compose version &> /dev/null; then + print_status "ERROR" "Docker Compose is not available" + exit 1 + fi + + # Deploy the stack unless skipped + if [ "$SKIP_DEPLOY" = false ]; then + deploy_stack + else + print_status "INFO" "Skipping deployment, running health checks only..." + fi + + # Show container status + show_container_status + + # Perform health checks + if perform_health_checks; then + print_status "SUCCESS" "๐ŸŽ‰ AzerothCore stack is fully operational!" + exit 0 + else + print_status "ERROR" "โŒ Health check failed - see issues above" + exit 1 + fi +} + +# Run main function +main "$@" \ No newline at end of file