mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 09:07:20 +00:00
deployment process
This commit is contained in:
363
DEPLOYMENT-README.md
Normal file
363
DEPLOYMENT-README.md
Normal file
@@ -0,0 +1,363 @@
|
||||
# AzerothCore Automated Deployment System
|
||||
|
||||
## 🚀 Overview
|
||||
|
||||
This deployment system provides automated installation, monitoring, and management of AzerothCore World of Warcraft server on Debian systems with Docker. It features layered service deployment, comprehensive monitoring, and system service integration.
|
||||
|
||||
## 📋 Features
|
||||
|
||||
- **Layered Deployment**: Database → Services → Optional → Tools
|
||||
- **Real-time Monitoring**: Health checks, alerts, and web dashboard
|
||||
- **System Service**: Automatic startup on boot with systemd
|
||||
- **Resource Management**: CPU, memory, and disk monitoring
|
||||
- **Backup System**: Automated database backups with retention
|
||||
- **Security**: User isolation, firewall rules, and secure defaults
|
||||
- **Web Interface**: Real-time status at http://localhost:8080
|
||||
|
||||
## 🛠️ Prerequisites
|
||||
|
||||
### System Requirements
|
||||
- **OS**: Debian 10+ (Ubuntu 18.04+ compatible)
|
||||
- **RAM**: 4GB minimum, 8GB recommended
|
||||
- **Disk**: 20GB free space minimum
|
||||
- **Network**: Internet access for image downloads
|
||||
|
||||
### Software Requirements
|
||||
```bash
|
||||
# Install Docker
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
# Install Docker Compose
|
||||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
# Reboot to apply group changes
|
||||
sudo reboot
|
||||
```
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### 1. Test Installation
|
||||
```bash
|
||||
# Clone or download the AzerothCore deployment files
|
||||
cd /path/to/azerothcore-compose2
|
||||
|
||||
# Run comprehensive tests
|
||||
./test-deployment.sh all
|
||||
|
||||
# Expected output: "All tests passed! 🎉"
|
||||
```
|
||||
|
||||
### 2. Manual Deployment (Development)
|
||||
```bash
|
||||
# Start the stack manually
|
||||
./azerothcore-deploy.sh start
|
||||
|
||||
# Monitor status
|
||||
./azerothcore-deploy.sh status
|
||||
|
||||
# View logs
|
||||
./azerothcore-deploy.sh logs ac-worldserver
|
||||
|
||||
# Stop the stack
|
||||
./azerothcore-deploy.sh stop
|
||||
```
|
||||
|
||||
### 3. System Service Installation (Production)
|
||||
```bash
|
||||
# Install as system service
|
||||
sudo ./install-system-service.sh install
|
||||
|
||||
# Start services
|
||||
sudo systemctl start azerothcore
|
||||
|
||||
# Check status
|
||||
sudo systemctl status azerothcore
|
||||
|
||||
# Enable auto-start on boot (already enabled by installer)
|
||||
sudo systemctl enable azerothcore
|
||||
```
|
||||
|
||||
## 📊 Monitoring & Management
|
||||
|
||||
### Web Dashboard
|
||||
- **URL**: http://localhost:8080
|
||||
- **Features**: Real-time service status, resource usage, recent alerts
|
||||
- **Auto-refresh**: Updates every 30 seconds
|
||||
|
||||
### Command Line Monitoring
|
||||
```bash
|
||||
# Real-time monitoring
|
||||
./azerothcore-monitor.sh monitor
|
||||
|
||||
# Generate status page
|
||||
./azerothcore-monitor.sh status
|
||||
|
||||
# View alerts
|
||||
./azerothcore-monitor.sh alerts
|
||||
|
||||
# View metrics
|
||||
./azerothcore-monitor.sh metrics
|
||||
```
|
||||
|
||||
### System Service Management
|
||||
```bash
|
||||
# Start services
|
||||
sudo systemctl start azerothcore
|
||||
|
||||
# Stop services
|
||||
sudo systemctl stop azerothcore
|
||||
|
||||
# Restart services
|
||||
sudo systemctl restart azerothcore
|
||||
|
||||
# Check status
|
||||
sudo systemctl status azerothcore
|
||||
|
||||
# View logs
|
||||
sudo journalctl -u azerothcore -f
|
||||
|
||||
# Check monitoring service
|
||||
sudo systemctl status azerothcore-monitor
|
||||
|
||||
# Check web service
|
||||
sudo systemctl status azerothcore-web
|
||||
```
|
||||
|
||||
## 🔧 Configuration
|
||||
|
||||
### Environment Files
|
||||
- `.env-database-local`: Local development settings
|
||||
- `.env-production`: Production optimized settings (auto-created during system install)
|
||||
|
||||
### Key Configuration Options
|
||||
```bash
|
||||
# Database settings
|
||||
MYSQL_ROOT_PASSWORD=azerothcore123
|
||||
DB_WAIT_RETRIES=60
|
||||
DB_WAIT_SLEEP=10
|
||||
|
||||
# Performance settings
|
||||
MYSQL_MAX_CONNECTIONS=200
|
||||
MYSQL_INNODB_BUFFER_POOL_SIZE=512M
|
||||
PLAYERBOT_MAX_BOTS=20
|
||||
|
||||
# Storage paths
|
||||
STORAGE_PATH=./local-data # or /opt/azerothcore/data for system install
|
||||
```
|
||||
|
||||
## 🗂️ Directory Structure
|
||||
|
||||
```
|
||||
azerothcore-compose2/
|
||||
├── azerothcore-deploy.sh # Main deployment script
|
||||
├── azerothcore-monitor.sh # Monitoring script
|
||||
├── install-system-service.sh # System service installer
|
||||
├── test-deployment.sh # Test suite
|
||||
├── docker-compose-*.yml # Service layer definitions
|
||||
├── .env-* # Environment configurations
|
||||
├── deployment-logs/ # Deployment logs
|
||||
├── monitoring-logs/ # Monitoring logs
|
||||
├── monitoring-web/ # Web dashboard files
|
||||
├── local-data/ # Application data
|
||||
├── backups/ # Database backups
|
||||
└── backup-scripts/ # Backup scripts
|
||||
```
|
||||
|
||||
## 🚀 Deployment Layers
|
||||
|
||||
### 1. Database Layer
|
||||
- **Services**: MySQL, DB Init, DB Import, Backup, Persistence
|
||||
- **Purpose**: Core database infrastructure
|
||||
- **Startup Time**: 2-5 minutes
|
||||
|
||||
### 2. Services Layer
|
||||
- **Services**: Auth Server, World Server, Client Data
|
||||
- **Purpose**: Core game servers
|
||||
- **Startup Time**: 5-15 minutes (includes 15GB client data download)
|
||||
|
||||
### 3. Optional Layer
|
||||
- **Services**: Eluna, Modules, Playerbots
|
||||
- **Purpose**: Enhanced features and scripting
|
||||
- **Startup Time**: 1-2 minutes
|
||||
|
||||
### 4. Tools Layer
|
||||
- **Services**: PHPMyAdmin, Keira3, Grafana, InfluxDB
|
||||
- **Purpose**: Management and monitoring interfaces
|
||||
- **Startup Time**: 2-3 minutes
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### Services Not Starting
|
||||
```bash
|
||||
# Check Docker daemon
|
||||
sudo systemctl status docker
|
||||
|
||||
# Check logs
|
||||
./azerothcore-deploy.sh logs [service-name]
|
||||
|
||||
# Check resource usage
|
||||
docker stats
|
||||
|
||||
# Restart specific layer
|
||||
docker-compose -f docker-compose-azerothcore-database.yml restart
|
||||
```
|
||||
|
||||
#### Database Connection Issues
|
||||
```bash
|
||||
# Test database connectivity
|
||||
docker exec ac-mysql mysql -uroot -pazerothcore123 -e "SELECT 1;"
|
||||
|
||||
# Check database logs
|
||||
docker logs ac-mysql
|
||||
|
||||
# Verify network
|
||||
docker network ls | grep azerothcore
|
||||
```
|
||||
|
||||
#### Web Dashboard Not Accessible
|
||||
```bash
|
||||
# Check web service
|
||||
sudo systemctl status azerothcore-web
|
||||
|
||||
# Check port availability
|
||||
sudo netstat -tlnp | grep 8080
|
||||
|
||||
# Restart web service
|
||||
sudo systemctl restart azerothcore-web
|
||||
```
|
||||
|
||||
#### High Resource Usage
|
||||
```bash
|
||||
# Check container stats
|
||||
docker stats
|
||||
|
||||
# Reduce playerbot count
|
||||
# Edit .env: PLAYERBOT_MAX_BOTS=5
|
||||
|
||||
# Reduce MySQL buffer size
|
||||
# Edit .env: MYSQL_INNODB_BUFFER_POOL_SIZE=256M
|
||||
```
|
||||
|
||||
### Log Locations
|
||||
|
||||
#### Manual Deployment
|
||||
- **Deployment Logs**: `./deployment-logs/`
|
||||
- **Monitoring Logs**: `./monitoring-logs/`
|
||||
- **Container Logs**: `docker logs [container-name]`
|
||||
|
||||
#### System Service
|
||||
- **System Logs**: `sudo journalctl -u azerothcore`
|
||||
- **Application Logs**: `/opt/azerothcore/deployment-logs/`
|
||||
- **Monitoring Logs**: `/opt/azerothcore/monitoring-logs/`
|
||||
|
||||
## 🔐 Security Considerations
|
||||
|
||||
### Default Security Features
|
||||
- Dedicated service user (`azerothcore`)
|
||||
- Firewall rules for game ports only
|
||||
- Database access restricted to localhost
|
||||
- Non-root container execution where possible
|
||||
- Secure systemd service configuration
|
||||
|
||||
### Additional Security Recommendations
|
||||
```bash
|
||||
# Configure UFW firewall
|
||||
sudo ufw enable
|
||||
sudo ufw default deny incoming
|
||||
sudo ufw allow ssh
|
||||
|
||||
# Update system regularly
|
||||
sudo apt update && sudo apt upgrade
|
||||
|
||||
# Monitor logs for suspicious activity
|
||||
sudo journalctl -u azerothcore | grep -i error
|
||||
|
||||
# Change default passwords
|
||||
# Edit .env: MYSQL_ROOT_PASSWORD=your-secure-password
|
||||
```
|
||||
|
||||
## 🔄 Backup & Recovery
|
||||
|
||||
### Automated Backups
|
||||
- **Schedule**: Daily at 3:00 AM (configurable)
|
||||
- **Location**: `./backups/` or `/opt/azerothcore/backups/`
|
||||
- **Retention**: 7 days (configurable)
|
||||
- **Format**: SQL dumps with timestamp
|
||||
|
||||
### Manual Backup
|
||||
```bash
|
||||
# Create immediate backup
|
||||
docker exec ac-mysql mysqldump -uroot -pazerothcore123 --all-databases > backup-$(date +%Y%m%d).sql
|
||||
|
||||
# Backup with backup script
|
||||
./backup-scripts/backup.sh
|
||||
```
|
||||
|
||||
### Recovery
|
||||
```bash
|
||||
# Stop services
|
||||
./azerothcore-deploy.sh stop
|
||||
|
||||
# Restore from backup
|
||||
docker run --rm -v $(pwd)/backups:/backups -v azerothcore_mysql_data:/var/lib/mysql mysql:8.0 \
|
||||
sh -c "mysql -uroot -pazerothcore123 < /backups/your-backup.sql"
|
||||
|
||||
# Restart services
|
||||
./azerothcore-deploy.sh start
|
||||
```
|
||||
|
||||
## 🗑️ Uninstallation
|
||||
|
||||
### Manual Deployment
|
||||
```bash
|
||||
# Stop and remove containers
|
||||
./azerothcore-deploy.sh stop
|
||||
docker system prune -a --volumes
|
||||
|
||||
# Remove data (optional)
|
||||
rm -rf local-data backups deployment-logs monitoring-logs
|
||||
```
|
||||
|
||||
### System Service
|
||||
```bash
|
||||
# Run uninstaller
|
||||
sudo /opt/azerothcore/uninstall.sh
|
||||
|
||||
# Follow prompts to remove data directories
|
||||
```
|
||||
|
||||
## 📞 Support
|
||||
|
||||
### Documentation
|
||||
- [AzerothCore Wiki](https://www.azerothcore.org/wiki/)
|
||||
- [Docker Documentation](https://docs.docker.com/)
|
||||
- [Docker Compose Reference](https://docs.docker.com/compose/)
|
||||
|
||||
### Getting Help
|
||||
1. Check logs for error messages
|
||||
2. Run diagnostic tests: `./test-deployment.sh all`
|
||||
3. Search [AzerothCore Discord](https://discord.gg/azerothcore)
|
||||
4. Review [GitHub Issues](https://github.com/azerothcore/azerothcore-wotlk/issues)
|
||||
|
||||
### Performance Tuning
|
||||
- Adjust `PLAYERBOT_MAX_BOTS` based on server capacity
|
||||
- Tune MySQL settings for your hardware
|
||||
- Monitor resource usage and scale accordingly
|
||||
- Consider SSD storage for better I/O performance
|
||||
|
||||
---
|
||||
|
||||
## 🎉 Enjoy Your AzerothCore Server!
|
||||
|
||||
Your World of Warcraft server is now ready to accept connections:
|
||||
|
||||
- **Auth Server**: `localhost:3784`
|
||||
- **World Server**: `localhost:8215`
|
||||
- **Web Dashboard**: `http://localhost:8080`
|
||||
- **Database**: `localhost:64306` (internal use)
|
||||
|
||||
Happy gaming! 🏰⚔️🛡️
|
||||
456
azerothcore-deploy.sh
Executable file
456
azerothcore-deploy.sh
Executable file
@@ -0,0 +1,456 @@
|
||||
#!/bin/bash
|
||||
# ==============================================
|
||||
# AzerothCore Complete Stack Deployment Script
|
||||
# ==============================================
|
||||
# Deploys AzerothCore services in proper order with monitoring
|
||||
# Designed for Debian systems with Docker/Docker Compose
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
LOG_DIR="$SCRIPT_DIR/deployment-logs"
|
||||
LOG_FILE="$LOG_DIR/deployment-$(date +%Y%m%d_%H%M%S).log"
|
||||
PID_FILE="/var/run/azerothcore-deploy.pid"
|
||||
|
||||
# Ensure log directory exists
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Deployment layers in order
|
||||
COMPOSE_LAYERS=(
|
||||
"database"
|
||||
"services"
|
||||
"optional"
|
||||
"tools"
|
||||
)
|
||||
|
||||
# Service monitoring timeouts (seconds)
|
||||
declare -A SERVICE_TIMEOUTS=(
|
||||
["ac-mysql"]=120
|
||||
["ac-db-init"]=60
|
||||
["ac-db-import"]=1800
|
||||
["ac-client-data"]=2400
|
||||
["ac-authserver"]=180
|
||||
["ac-worldserver"]=300
|
||||
["ac-backup"]=60
|
||||
["ac-mysql-persist"]=60
|
||||
)
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
PURPLE='\033[0;35m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log() {
|
||||
local level="$1"
|
||||
shift
|
||||
local message="$*"
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
case "$level" in
|
||||
"INFO") echo -e "${CYAN}[INFO]${NC} $message" ;;
|
||||
"WARN") echo -e "${YELLOW}[WARN]${NC} $message" ;;
|
||||
"ERROR") echo -e "${RED}[ERROR]${NC} $message" ;;
|
||||
"SUCCESS") echo -e "${GREEN}[SUCCESS]${NC} $message" ;;
|
||||
"DEBUG") echo -e "${PURPLE}[DEBUG]${NC} $message" ;;
|
||||
esac
|
||||
|
||||
echo "[$timestamp] [$level] $message" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Error handling
|
||||
cleanup() {
|
||||
log "INFO" "Cleaning up..."
|
||||
rm -f "$PID_FILE"
|
||||
if [[ ${#BACKGROUND_PIDS[@]} -gt 0 ]]; then
|
||||
log "INFO" "Stopping background monitoring processes..."
|
||||
for pid in "${BACKGROUND_PIDS[@]}"; do
|
||||
kill "$pid" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
error_exit() {
|
||||
log "ERROR" "$1"
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Array to track background processes
|
||||
BACKGROUND_PIDS=()
|
||||
|
||||
# Check prerequisites
|
||||
check_prerequisites() {
|
||||
log "INFO" "Checking prerequisites..."
|
||||
|
||||
# Check if running as root for system service setup
|
||||
if [[ "$DEPLOY_MODE" == "system" ]] && [[ $EUID -ne 0 ]]; then
|
||||
error_exit "System deployment mode requires root privileges"
|
||||
fi
|
||||
|
||||
# Check Docker
|
||||
if ! command -v docker &> /dev/null; then
|
||||
error_exit "Docker is not installed"
|
||||
fi
|
||||
|
||||
if ! docker info &> /dev/null; then
|
||||
error_exit "Docker daemon is not running"
|
||||
fi
|
||||
|
||||
# Check Docker Compose
|
||||
if ! command -v docker-compose &> /dev/null; then
|
||||
error_exit "Docker Compose is not installed"
|
||||
fi
|
||||
|
||||
# Check compose files exist
|
||||
for layer in "${COMPOSE_LAYERS[@]}"; do
|
||||
local compose_file="docker-compose-azerothcore-${layer}.yml"
|
||||
if [[ ! -f "$SCRIPT_DIR/$compose_file" ]]; then
|
||||
error_exit "Missing compose file: $compose_file"
|
||||
fi
|
||||
done
|
||||
|
||||
log "SUCCESS" "Prerequisites check passed"
|
||||
}
|
||||
|
||||
# Setup environment
|
||||
setup_environment() {
|
||||
log "INFO" "Setting up deployment environment..."
|
||||
|
||||
# Create log directory
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Create data directories
|
||||
mkdir -p "$SCRIPT_DIR/local-data/mysql-data"
|
||||
mkdir -p "$SCRIPT_DIR/local-data/config"
|
||||
mkdir -p "$SCRIPT_DIR/backups"
|
||||
|
||||
# Set up environment file
|
||||
if [[ ! -f "$SCRIPT_DIR/.env" ]]; then
|
||||
if [[ -f "$SCRIPT_DIR/.env-database-local" ]]; then
|
||||
log "INFO" "Using local database environment configuration"
|
||||
cp "$SCRIPT_DIR/.env-database-local" "$SCRIPT_DIR/.env"
|
||||
else
|
||||
error_exit "No environment configuration found"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Store PID for system service management
|
||||
echo $$ > "$PID_FILE"
|
||||
|
||||
log "SUCCESS" "Environment setup complete"
|
||||
}
|
||||
|
||||
# Monitor container health
|
||||
monitor_container() {
|
||||
local container_name="$1"
|
||||
local timeout="${2:-300}"
|
||||
local start_time=$(date +%s)
|
||||
|
||||
log "INFO" "Monitoring $container_name (timeout: ${timeout}s)..."
|
||||
|
||||
while [[ $(($(date +%s) - start_time)) -lt $timeout ]]; do
|
||||
if docker ps --filter "name=$container_name" --format "{{.Names}}" | grep -q "^${container_name}$"; then
|
||||
local status=$(docker ps --filter "name=$container_name" --format "{{.Status}}")
|
||||
|
||||
# Check if container is healthy
|
||||
if echo "$status" | grep -q "healthy"; then
|
||||
log "SUCCESS" "$container_name is healthy"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check if container exited
|
||||
if echo "$status" | grep -q "Exited"; then
|
||||
local exit_code=$(docker ps -a --filter "name=$container_name" --format "{{.Status}}" | grep -o "Exited ([0-9]*)" | grep -o "[0-9]*")
|
||||
if [[ "$exit_code" == "0" ]]; then
|
||||
log "SUCCESS" "$container_name completed successfully"
|
||||
return 0
|
||||
else
|
||||
log "ERROR" "$container_name failed (exit code: $exit_code)"
|
||||
log "DEBUG" "Container logs:"
|
||||
docker logs "$container_name" 2>&1 | tail -20 | while read line; do
|
||||
log "DEBUG" " $line"
|
||||
done
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Show periodic status updates
|
||||
if [[ $(( ($(date +%s) - start_time) % 30 )) -eq 0 ]]; then
|
||||
log "INFO" "$container_name status: $status"
|
||||
# Show last few log lines
|
||||
docker logs "$container_name" --tail 3 2>&1 | while read line; do
|
||||
log "DEBUG" " [$container_name] $line"
|
||||
done
|
||||
fi
|
||||
else
|
||||
log "WARN" "Waiting for $container_name to start..."
|
||||
fi
|
||||
|
||||
sleep 5
|
||||
done
|
||||
|
||||
log "ERROR" "Timeout waiting for $container_name after ${timeout}s"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Deploy a specific layer
|
||||
deploy_layer() {
|
||||
local layer="$1"
|
||||
local compose_file="docker-compose-azerothcore-${layer}.yml"
|
||||
|
||||
log "INFO" "Deploying layer: $layer"
|
||||
|
||||
# Start the layer
|
||||
if ! docker-compose -f "$compose_file" up -d; then
|
||||
error_exit "Failed to start $layer layer"
|
||||
fi
|
||||
|
||||
# Get services in this layer
|
||||
local services=$(docker-compose -f "$compose_file" config --services)
|
||||
|
||||
# Monitor each service
|
||||
for service in $services; do
|
||||
local container_name="$service"
|
||||
local timeout="${SERVICE_TIMEOUTS[$container_name]:-300}"
|
||||
|
||||
if ! monitor_container "$container_name" "$timeout"; then
|
||||
error_exit "Service $container_name failed to start properly"
|
||||
fi
|
||||
done
|
||||
|
||||
log "SUCCESS" "Layer $layer deployed successfully"
|
||||
}
|
||||
|
||||
# Monitor running services
|
||||
monitor_services() {
|
||||
log "INFO" "Starting continuous service monitoring..."
|
||||
|
||||
while true; do
|
||||
local unhealthy_services=()
|
||||
|
||||
# Check all running containers
|
||||
for container in $(docker ps --format "{{.Names}}" | grep "^ac-"); do
|
||||
local status=$(docker ps --filter "name=$container" --format "{{.Status}}")
|
||||
|
||||
if echo "$status" | grep -q "unhealthy\|Restarting\|Exited"; then
|
||||
unhealthy_services+=("$container")
|
||||
log "WARN" "Unhealthy service detected: $container ($status)"
|
||||
fi
|
||||
done
|
||||
|
||||
# Report status
|
||||
if [[ ${#unhealthy_services[@]} -eq 0 ]]; then
|
||||
log "INFO" "All services healthy ($(docker ps --filter "name=ac-" --format "{{.Names}}" | wc -l) running)"
|
||||
else
|
||||
log "WARN" "Unhealthy services: ${unhealthy_services[*]}"
|
||||
fi
|
||||
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
# Get deployment status
|
||||
get_status() {
|
||||
log "INFO" "Current deployment status:"
|
||||
|
||||
for layer in "${COMPOSE_LAYERS[@]}"; do
|
||||
local compose_file="docker-compose-azerothcore-${layer}.yml"
|
||||
if [[ -f "$compose_file" ]]; then
|
||||
echo -e "\n${BLUE}=== $layer Layer ===${NC}"
|
||||
docker-compose -f "$compose_file" ps 2>/dev/null || echo "Layer not deployed"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "\n${BLUE}=== Resource Usage ===${NC}"
|
||||
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}" $(docker ps --filter "name=ac-" --format "{{.Names}}" 2>/dev/null || echo "none") 2>/dev/null || echo "No containers running"
|
||||
}
|
||||
|
||||
# Stop all services
|
||||
stop_all() {
|
||||
log "INFO" "Stopping all AzerothCore services..."
|
||||
|
||||
# Stop in reverse order
|
||||
for ((i=${#COMPOSE_LAYERS[@]}-1; i>=0; i--)); do
|
||||
local layer="${COMPOSE_LAYERS[i]}"
|
||||
local compose_file="docker-compose-azerothcore-${layer}.yml"
|
||||
|
||||
if [[ -f "$compose_file" ]]; then
|
||||
log "INFO" "Stopping $layer layer..."
|
||||
docker-compose -f "$compose_file" down 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
log "SUCCESS" "All services stopped"
|
||||
}
|
||||
|
||||
# Install system service
|
||||
install_system_service() {
|
||||
log "INFO" "Installing AzerothCore as system service..."
|
||||
|
||||
cat > /etc/systemd/system/azerothcore.service << EOF
|
||||
[Unit]
|
||||
Description=AzerothCore WoW Server
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=root
|
||||
WorkingDirectory=$SCRIPT_DIR
|
||||
ExecStart=$SCRIPT_DIR/azerothcore-deploy.sh start
|
||||
ExecStop=$SCRIPT_DIR/azerothcore-deploy.sh stop
|
||||
ExecReload=$SCRIPT_DIR/azerothcore-deploy.sh restart
|
||||
PIDFile=$PID_FILE
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
TimeoutStartSec=1800
|
||||
TimeoutStopSec=300
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable azerothcore
|
||||
|
||||
log "SUCCESS" "AzerothCore system service installed"
|
||||
log "INFO" "Use 'systemctl start azerothcore' to start the service"
|
||||
log "INFO" "Use 'systemctl status azerothcore' to check status"
|
||||
}
|
||||
|
||||
# Main deployment function
|
||||
main_deploy() {
|
||||
log "INFO" "Starting AzerothCore deployment..."
|
||||
|
||||
check_prerequisites
|
||||
setup_environment
|
||||
|
||||
# Deploy each layer in sequence
|
||||
for layer in "${COMPOSE_LAYERS[@]}"; do
|
||||
deploy_layer "$layer"
|
||||
|
||||
# Brief pause between layers
|
||||
sleep 10
|
||||
done
|
||||
|
||||
log "SUCCESS" "AzerothCore deployment completed successfully!"
|
||||
|
||||
# Show final status
|
||||
get_status
|
||||
|
||||
# Start background monitoring if not in daemon mode
|
||||
if [[ "$MONITOR_MODE" == "continuous" ]]; then
|
||||
monitor_services &
|
||||
BACKGROUND_PIDS+=($!)
|
||||
log "INFO" "Background monitoring started (PID: $!)"
|
||||
|
||||
# Keep script running
|
||||
wait
|
||||
fi
|
||||
}
|
||||
|
||||
# Usage information
|
||||
usage() {
|
||||
cat << EOF
|
||||
Usage: $0 [COMMAND] [OPTIONS]
|
||||
|
||||
COMMANDS:
|
||||
start Deploy AzerothCore stack
|
||||
stop Stop all AzerothCore services
|
||||
restart Restart AzerothCore stack
|
||||
status Show current deployment status
|
||||
logs [service] Show logs for service (or all services)
|
||||
install-service Install as system service (requires root)
|
||||
|
||||
OPTIONS:
|
||||
--monitor Enable continuous monitoring
|
||||
--system System deployment mode (requires root)
|
||||
--help Show this help message
|
||||
|
||||
Examples:
|
||||
$0 start --monitor # Deploy with continuous monitoring
|
||||
$0 status # Show current status
|
||||
$0 logs ac-worldserver # Show worldserver logs
|
||||
$0 install-service # Install as system service
|
||||
|
||||
Environment Variables:
|
||||
DEPLOY_MODE=system # Enable system mode
|
||||
MONITOR_MODE=continuous # Enable monitoring
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
COMMAND="${1:-start}"
|
||||
DEPLOY_MODE="${DEPLOY_MODE:-local}"
|
||||
MONITOR_MODE="${MONITOR_MODE:-single}"
|
||||
|
||||
shift || true
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--monitor)
|
||||
MONITOR_MODE="continuous"
|
||||
shift
|
||||
;;
|
||||
--system)
|
||||
DEPLOY_MODE="system"
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Execute command
|
||||
case "$COMMAND" in
|
||||
"start")
|
||||
main_deploy
|
||||
;;
|
||||
"stop")
|
||||
stop_all
|
||||
;;
|
||||
"restart")
|
||||
stop_all
|
||||
sleep 5
|
||||
main_deploy
|
||||
;;
|
||||
"status")
|
||||
get_status
|
||||
;;
|
||||
"logs")
|
||||
service_name="${1:-}"
|
||||
if [[ -n "$service_name" ]]; then
|
||||
docker logs "$service_name" --follow
|
||||
else
|
||||
log "INFO" "Available services:"
|
||||
docker ps --filter "name=ac-" --format "{{.Names}}" || echo "No services running"
|
||||
fi
|
||||
;;
|
||||
"install-service")
|
||||
install_system_service
|
||||
;;
|
||||
"help"|"--help")
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $COMMAND"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
330
azerothcore-monitor.sh
Executable file
330
azerothcore-monitor.sh
Executable file
@@ -0,0 +1,330 @@
|
||||
#!/bin/bash
|
||||
# ==============================================
|
||||
# AzerothCore Advanced Monitoring Script
|
||||
# ==============================================
|
||||
# Real-time monitoring with alerts and health checks
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
LOG_DIR="$SCRIPT_DIR/monitoring-logs"
|
||||
ALERT_LOG="$LOG_DIR/alerts-$(date +%Y%m%d).log"
|
||||
METRICS_LOG="$LOG_DIR/metrics-$(date +%Y%m%d).log"
|
||||
WEB_DIR="$SCRIPT_DIR/monitoring-web"
|
||||
|
||||
# Create directories
|
||||
mkdir -p "$LOG_DIR" "$WEB_DIR"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Monitoring configuration
|
||||
declare -A EXPECTED_SERVICES=(
|
||||
["ac-mysql"]="MySQL Database"
|
||||
["ac-authserver"]="Authentication Server"
|
||||
["ac-worldserver"]="World Server"
|
||||
["ac-backup"]="Backup Service"
|
||||
)
|
||||
|
||||
declare -A HEALTH_THRESHOLDS=(
|
||||
["cpu_warn"]=80
|
||||
["cpu_critical"]=95
|
||||
["memory_warn"]=80
|
||||
["memory_critical"]=95
|
||||
["disk_warn"]=85
|
||||
["disk_critical"]=95
|
||||
)
|
||||
|
||||
# Alert functions
|
||||
send_alert() {
|
||||
local level="$1"
|
||||
local service="$2"
|
||||
local message="$3"
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
case "$level" in
|
||||
"CRITICAL") echo -e "${RED}[CRITICAL]${NC} $service: $message" ;;
|
||||
"WARNING") echo -e "${YELLOW}[WARNING]${NC} $service: $message" ;;
|
||||
"INFO") echo -e "${BLUE}[INFO]${NC} $service: $message" ;;
|
||||
"OK") echo -e "${GREEN}[OK]${NC} $service: $message" ;;
|
||||
esac
|
||||
|
||||
echo "[$timestamp] [$level] $service: $message" >> "$ALERT_LOG"
|
||||
}
|
||||
|
||||
# Get container stats
|
||||
get_container_stats() {
|
||||
local container="$1"
|
||||
|
||||
if ! docker ps --filter "name=$container" --format "{{.Names}}" | grep -q "^${container}$"; then
|
||||
echo "status=missing"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local stats=$(docker stats --no-stream --format "{{.CPUPerc}},{{.MemPerc}},{{.MemUsage}},{{.NetIO}},{{.BlockIO}}" "$container" 2>/dev/null || echo "0.00%,0.00%,0B / 0B,0B / 0B,0B / 0B")
|
||||
|
||||
echo "status=running,$stats"
|
||||
}
|
||||
|
||||
# Monitor service health
|
||||
check_service_health() {
|
||||
local service="$1"
|
||||
local description="${EXPECTED_SERVICES[$service]}"
|
||||
|
||||
local stats=$(get_container_stats "$service")
|
||||
|
||||
if [[ "$stats" == "status=missing" ]]; then
|
||||
send_alert "CRITICAL" "$service" "$description is not running"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Parse stats
|
||||
IFS=',' read -r status cpu_percent mem_percent mem_usage net_io block_io <<< "$stats"
|
||||
|
||||
# Remove % signs for comparison
|
||||
local cpu_num=$(echo "$cpu_percent" | sed 's/%//')
|
||||
local mem_num=$(echo "$mem_percent" | sed 's/%//')
|
||||
|
||||
# Convert to integers for comparison
|
||||
cpu_num=$(printf "%.0f" "$cpu_num" 2>/dev/null || echo "0")
|
||||
mem_num=$(printf "%.0f" "$mem_num" 2>/dev/null || echo "0")
|
||||
|
||||
# Check thresholds
|
||||
if [[ $cpu_num -gt ${HEALTH_THRESHOLDS["cpu_critical"]} ]]; then
|
||||
send_alert "CRITICAL" "$service" "CPU usage critical: ${cpu_percent}"
|
||||
elif [[ $cpu_num -gt ${HEALTH_THRESHOLDS["cpu_warn"]} ]]; then
|
||||
send_alert "WARNING" "$service" "CPU usage high: ${cpu_percent}"
|
||||
fi
|
||||
|
||||
if [[ $mem_num -gt ${HEALTH_THRESHOLDS["memory_critical"]} ]]; then
|
||||
send_alert "CRITICAL" "$service" "Memory usage critical: ${mem_percent}"
|
||||
elif [[ $mem_num -gt ${HEALTH_THRESHOLDS["memory_warn"]} ]]; then
|
||||
send_alert "WARNING" "$service" "Memory usage high: ${mem_percent}"
|
||||
fi
|
||||
|
||||
# Log metrics
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
echo "$timestamp,$service,$cpu_percent,$mem_percent,$mem_usage,$net_io,$block_io" >> "$METRICS_LOG"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check database connectivity
|
||||
check_database_health() {
|
||||
if docker run --rm --network azerothcore mysql:8.0 \
|
||||
mysql -h ac-mysql -uroot -p"${MYSQL_ROOT_PASSWORD:-azerothcore123}" \
|
||||
-e "SELECT 1;" &>/dev/null; then
|
||||
send_alert "OK" "database" "Database connectivity verified"
|
||||
return 0
|
||||
else
|
||||
send_alert "CRITICAL" "database" "Database connectivity failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check game server ports
|
||||
check_game_ports() {
|
||||
local auth_port="3784"
|
||||
local world_port="8215"
|
||||
|
||||
# Check auth server port
|
||||
if timeout 5 bash -c "</dev/tcp/localhost/$auth_port" 2>/dev/null; then
|
||||
send_alert "OK" "authserver" "Port $auth_port responding"
|
||||
else
|
||||
send_alert "WARNING" "authserver" "Port $auth_port not responding"
|
||||
fi
|
||||
|
||||
# Check world server port
|
||||
if timeout 5 bash -c "</dev/tcp/localhost/$world_port" 2>/dev/null; then
|
||||
send_alert "OK" "worldserver" "Port $world_port responding"
|
||||
else
|
||||
send_alert "WARNING" "worldserver" "Port $world_port not responding"
|
||||
fi
|
||||
}
|
||||
|
||||
# Generate HTML status page
|
||||
generate_web_status() {
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
local uptime=$(uptime -p 2>/dev/null || echo "Unknown")
|
||||
|
||||
cat > "$WEB_DIR/index.html" << EOF
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>AzerothCore Status</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="refresh" content="30">
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
|
||||
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
||||
.header { text-align: center; margin-bottom: 30px; }
|
||||
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
|
||||
.service-card { border: 1px solid #ddd; border-radius: 8px; padding: 15px; }
|
||||
.service-running { border-left: 4px solid #4CAF50; }
|
||||
.service-warning { border-left: 4px solid #FF9800; }
|
||||
.service-critical { border-left: 4px solid #F44336; }
|
||||
.service-missing { border-left: 4px solid #9E9E9E; }
|
||||
.metric { display: flex; justify-content: space-between; margin: 5px 0; }
|
||||
.timestamp { text-align: center; color: #666; margin-top: 20px; }
|
||||
table { width: 100%; border-collapse: collapse; margin: 10px 0; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||
th { background-color: #f2f2f2; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🏰 AzerothCore Server Status</h1>
|
||||
<p>System Uptime: $uptime</p>
|
||||
</div>
|
||||
|
||||
<div class="status-grid">
|
||||
EOF
|
||||
|
||||
# Add service status cards
|
||||
for service in "${!EXPECTED_SERVICES[@]}"; do
|
||||
local description="${EXPECTED_SERVICES[$service]}"
|
||||
local stats=$(get_container_stats "$service")
|
||||
local css_class="service-missing"
|
||||
local status_text="Not Running"
|
||||
|
||||
if [[ "$stats" != "status=missing" ]]; then
|
||||
IFS=',' read -r status cpu_percent mem_percent mem_usage net_io block_io <<< "$stats"
|
||||
css_class="service-running"
|
||||
status_text="Running"
|
||||
|
||||
# Check for warnings
|
||||
local cpu_num=$(echo "$cpu_percent" | sed 's/%//' | cut -d. -f1)
|
||||
local mem_num=$(echo "$mem_percent" | sed 's/%//' | cut -d. -f1)
|
||||
|
||||
if [[ ${cpu_num:-0} -gt ${HEALTH_THRESHOLDS["cpu_warn"]} ]] || [[ ${mem_num:-0} -gt ${HEALTH_THRESHOLDS["memory_warn"]} ]]; then
|
||||
css_class="service-warning"
|
||||
status_text="Warning"
|
||||
fi
|
||||
fi
|
||||
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
<div class="service-card $css_class">
|
||||
<h3>$description</h3>
|
||||
<div class="metric"><strong>Service:</strong> <span>$service</span></div>
|
||||
<div class="metric"><strong>Status:</strong> <span>$status_text</span></div>
|
||||
EOF
|
||||
|
||||
if [[ "$stats" != "status=missing" ]]; then
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
<div class="metric"><strong>CPU:</strong> <span>$cpu_percent</span></div>
|
||||
<div class="metric"><strong>Memory:</strong> <span>$mem_percent</span></div>
|
||||
<div class="metric"><strong>Memory Usage:</strong> <span>$mem_usage</span></div>
|
||||
<div class="metric"><strong>Network I/O:</strong> <span>$net_io</span></div>
|
||||
EOF
|
||||
fi
|
||||
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
</div>
|
||||
EOF
|
||||
done
|
||||
|
||||
# Add recent alerts
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
</div>
|
||||
|
||||
<h2>Recent Alerts</h2>
|
||||
<table>
|
||||
<tr><th>Time</th><th>Level</th><th>Service</th><th>Message</th></tr>
|
||||
EOF
|
||||
|
||||
if [[ -f "$ALERT_LOG" ]]; then
|
||||
tail -10 "$ALERT_LOG" | while IFS= read -r line; do
|
||||
if [[ -n "$line" ]]; then
|
||||
# Parse log line: [timestamp] [level] service: message
|
||||
local timestamp=$(echo "$line" | sed -n 's/\[\([^]]*\)\].*/\1/p')
|
||||
local level=$(echo "$line" | sed -n 's/.*\[\([^]]*\)\] [^:]*:.*/\1/p')
|
||||
local service=$(echo "$line" | sed -n 's/.*\] \([^:]*\):.*/\1/p')
|
||||
local message=$(echo "$line" | sed -n 's/.*: \(.*\)/\1/p')
|
||||
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
<tr><td>$timestamp</td><td>$level</td><td>$service</td><td>$message</td></tr>
|
||||
EOF
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
cat >> "$WEB_DIR/index.html" << EOF
|
||||
</table>
|
||||
|
||||
<div class="timestamp">
|
||||
Last updated: $timestamp
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
}
|
||||
|
||||
# Main monitoring loop
|
||||
main_monitor() {
|
||||
echo "Starting AzerothCore monitoring..."
|
||||
echo "Logs: $LOG_DIR"
|
||||
echo "Web status: $WEB_DIR/index.html"
|
||||
echo "Press Ctrl+C to stop"
|
||||
|
||||
while true; do
|
||||
echo -e "\n$(date '+%Y-%m-%d %H:%M:%S') - Running health checks..."
|
||||
|
||||
# Check each service
|
||||
for service in "${!EXPECTED_SERVICES[@]}"; do
|
||||
check_service_health "$service"
|
||||
done
|
||||
|
||||
# Additional health checks
|
||||
check_database_health
|
||||
check_game_ports
|
||||
|
||||
# Generate web status
|
||||
generate_web_status
|
||||
|
||||
# System resource check
|
||||
local disk_usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
|
||||
if [[ ${disk_usage:-0} -gt ${HEALTH_THRESHOLDS["disk_critical"]} ]]; then
|
||||
send_alert "CRITICAL" "system" "Disk usage critical: ${disk_usage}%"
|
||||
elif [[ ${disk_usage:-0} -gt ${HEALTH_THRESHOLDS["disk_warn"]} ]]; then
|
||||
send_alert "WARNING" "system" "Disk usage high: ${disk_usage}%"
|
||||
fi
|
||||
|
||||
sleep 30
|
||||
done
|
||||
}
|
||||
|
||||
# Command handling
|
||||
case "${1:-monitor}" in
|
||||
"monitor")
|
||||
main_monitor
|
||||
;;
|
||||
"status")
|
||||
generate_web_status
|
||||
echo "Status page generated: $WEB_DIR/index.html"
|
||||
;;
|
||||
"alerts")
|
||||
if [[ -f "$ALERT_LOG" ]]; then
|
||||
tail -n 20 "$ALERT_LOG"
|
||||
else
|
||||
echo "No alerts found"
|
||||
fi
|
||||
;;
|
||||
"metrics")
|
||||
if [[ -f "$METRICS_LOG" ]]; then
|
||||
tail -n 20 "$METRICS_LOG"
|
||||
else
|
||||
echo "No metrics found"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [monitor|status|alerts|metrics]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
1
deployment-logs/deployment-20250929_221335.log
Normal file
1
deployment-logs/deployment-20250929_221335.log
Normal file
@@ -0,0 +1 @@
|
||||
[2025-09-29 22:13:35] [INFO] Cleaning up...
|
||||
3
deployment-logs/deployment-20250929_221348.log
Normal file
3
deployment-logs/deployment-20250929_221348.log
Normal file
@@ -0,0 +1,3 @@
|
||||
[2025-09-29 22:13:48] [INFO] Cleaning up...
|
||||
[2025-09-29 22:13:48] [INFO] Current deployment status:
|
||||
[2025-09-29 22:13:49] [INFO] Cleaning up...
|
||||
442
install-system-service.sh
Executable file
442
install-system-service.sh
Executable file
@@ -0,0 +1,442 @@
|
||||
#!/bin/bash
|
||||
# ==============================================
|
||||
# AzerothCore System Service Installer
|
||||
# ==============================================
|
||||
# Configures AzerothCore to start automatically on Debian systems
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
SERVICE_USER="${SERVICE_USER:-azerothcore}"
|
||||
INSTALL_DIR="${INSTALL_DIR:-/opt/azerothcore}"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() {
|
||||
local level="$1"
|
||||
shift
|
||||
local message="$*"
|
||||
|
||||
case "$level" in
|
||||
"INFO") echo -e "${BLUE}[INFO]${NC} $message" ;;
|
||||
"WARN") echo -e "${YELLOW}[WARN]${NC} $message" ;;
|
||||
"ERROR") echo -e "${RED}[ERROR]${NC} $message" ;;
|
||||
"SUCCESS") echo -e "${GREEN}[SUCCESS]${NC} $message" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
error_exit() {
|
||||
log "ERROR" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
check_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
error_exit "This script must be run as root. Use: sudo $0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check prerequisites
|
||||
check_prerequisites() {
|
||||
log "INFO" "Checking prerequisites..."
|
||||
|
||||
# Check if Docker is installed
|
||||
if ! command -v docker &> /dev/null; then
|
||||
error_exit "Docker is not installed. Please install Docker first."
|
||||
fi
|
||||
|
||||
# Check if Docker Compose is installed
|
||||
if ! command -v docker-compose &> /dev/null; then
|
||||
error_exit "Docker Compose is not installed. Please install Docker Compose first."
|
||||
fi
|
||||
|
||||
# Check if systemd is available
|
||||
if ! command -v systemctl &> /dev/null; then
|
||||
error_exit "systemd is not available on this system"
|
||||
fi
|
||||
|
||||
log "SUCCESS" "Prerequisites check passed"
|
||||
}
|
||||
|
||||
# Create service user
|
||||
create_service_user() {
|
||||
log "INFO" "Creating service user: $SERVICE_USER"
|
||||
|
||||
if id "$SERVICE_USER" &>/dev/null; then
|
||||
log "INFO" "User $SERVICE_USER already exists"
|
||||
else
|
||||
useradd --system --no-create-home --shell /bin/false --group docker "$SERVICE_USER"
|
||||
log "SUCCESS" "Created user: $SERVICE_USER"
|
||||
fi
|
||||
|
||||
# Add user to docker group
|
||||
usermod -aG docker "$SERVICE_USER" || true
|
||||
}
|
||||
|
||||
# Install application
|
||||
install_application() {
|
||||
log "INFO" "Installing AzerothCore to $INSTALL_DIR"
|
||||
|
||||
# Create install directory
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
|
||||
# Copy application files
|
||||
cp -r "$SCRIPT_DIR"/* "$INSTALL_DIR/"
|
||||
|
||||
# Set ownership
|
||||
chown -R "$SERVICE_USER:$SERVICE_USER" "$INSTALL_DIR"
|
||||
|
||||
# Set permissions
|
||||
chmod +x "$INSTALL_DIR"/*.sh
|
||||
|
||||
log "SUCCESS" "Application installed to $INSTALL_DIR"
|
||||
}
|
||||
|
||||
# Create systemd service files
|
||||
create_systemd_services() {
|
||||
log "INFO" "Creating systemd service files..."
|
||||
|
||||
# Main AzerothCore service
|
||||
cat > /etc/systemd/system/azerothcore.service << EOF
|
||||
[Unit]
|
||||
Description=AzerothCore World of Warcraft Server
|
||||
Documentation=https://www.azerothcore.org/
|
||||
After=docker.service network.target
|
||||
Requires=docker.service
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=$SERVICE_USER
|
||||
Group=$SERVICE_USER
|
||||
WorkingDirectory=$INSTALL_DIR
|
||||
Environment=DEPLOY_MODE=system
|
||||
Environment=MONITOR_MODE=single
|
||||
ExecStartPre=/usr/bin/docker system prune -f --volumes
|
||||
ExecStart=$INSTALL_DIR/azerothcore-deploy.sh start
|
||||
ExecStop=$INSTALL_DIR/azerothcore-deploy.sh stop
|
||||
ExecReload=/bin/kill -HUP \$MAINPID
|
||||
PIDFile=/var/run/azerothcore-deploy.pid
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
TimeoutStartSec=1800
|
||||
TimeoutStopSec=300
|
||||
KillMode=mixed
|
||||
KillSignal=SIGTERM
|
||||
|
||||
# Resource limits
|
||||
LimitNOFILE=65536
|
||||
LimitMEMLOCK=infinity
|
||||
|
||||
# Security settings
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ReadWritePaths=$INSTALL_DIR /var/run /tmp
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# AzerothCore monitoring service
|
||||
cat > /etc/systemd/system/azerothcore-monitor.service << EOF
|
||||
[Unit]
|
||||
Description=AzerothCore Monitoring Service
|
||||
After=azerothcore.service
|
||||
Requires=azerothcore.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$SERVICE_USER
|
||||
Group=$SERVICE_USER
|
||||
WorkingDirectory=$INSTALL_DIR
|
||||
Environment=MYSQL_ROOT_PASSWORD=azerothcore123
|
||||
ExecStart=$INSTALL_DIR/azerothcore-monitor.sh monitor
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
# Security settings
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ReadWritePaths=$INSTALL_DIR
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Web status service (simple HTTP server)
|
||||
cat > /etc/systemd/system/azerothcore-web.service << EOF
|
||||
[Unit]
|
||||
Description=AzerothCore Web Status Server
|
||||
After=azerothcore-monitor.service
|
||||
Requires=azerothcore-monitor.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$SERVICE_USER
|
||||
Group=$SERVICE_USER
|
||||
WorkingDirectory=$INSTALL_DIR/monitoring-web
|
||||
ExecStart=/usr/bin/python3 -m http.server 8080
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
# Security settings
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ReadWritePaths=$INSTALL_DIR/monitoring-web
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
log "SUCCESS" "Systemd service files created"
|
||||
}
|
||||
|
||||
# Create startup configuration
|
||||
create_startup_config() {
|
||||
log "INFO" "Creating startup configuration..."
|
||||
|
||||
# Create environment file
|
||||
cat > "$INSTALL_DIR/.env-production" << EOF
|
||||
# Production Environment Configuration
|
||||
DEPLOYMENT_MODE=production
|
||||
STORAGE_PATH=$INSTALL_DIR/data
|
||||
HOST_BACKUP_PATH=$INSTALL_DIR/backups
|
||||
HOST_BACKUP_SCRIPTS_PATH=$INSTALL_DIR/backup-scripts
|
||||
|
||||
# Database configuration
|
||||
MYSQL_ROOT_PASSWORD=azerothcore123
|
||||
DB_WAIT_RETRIES=60
|
||||
DB_WAIT_SLEEP=10
|
||||
|
||||
# MySQL health check settings (for slower systems)
|
||||
MYSQL_HEALTHCHECK_INTERVAL=20s
|
||||
MYSQL_HEALTHCHECK_TIMEOUT=15s
|
||||
MYSQL_HEALTHCHECK_RETRIES=25
|
||||
MYSQL_HEALTHCHECK_START_PERIOD=120s
|
||||
|
||||
# Performance settings
|
||||
MYSQL_MAX_CONNECTIONS=200
|
||||
MYSQL_INNODB_BUFFER_POOL_SIZE=512M
|
||||
MYSQL_INNODB_LOG_FILE_SIZE=128M
|
||||
|
||||
# Security settings
|
||||
PLAYERBOT_MAX_BOTS=20
|
||||
MODULE_PLAYERBOTS=1
|
||||
EOF
|
||||
|
||||
# Set default environment
|
||||
if [[ ! -f "$INSTALL_DIR/.env" ]]; then
|
||||
cp "$INSTALL_DIR/.env-production" "$INSTALL_DIR/.env"
|
||||
fi
|
||||
|
||||
# Create data directories
|
||||
mkdir -p "$INSTALL_DIR/data/mysql-data"
|
||||
mkdir -p "$INSTALL_DIR/data/config"
|
||||
mkdir -p "$INSTALL_DIR/backups"
|
||||
mkdir -p "$INSTALL_DIR/monitoring-logs"
|
||||
mkdir -p "$INSTALL_DIR/deployment-logs"
|
||||
|
||||
# Set ownership
|
||||
chown -R "$SERVICE_USER:$SERVICE_USER" "$INSTALL_DIR"
|
||||
|
||||
log "SUCCESS" "Startup configuration created"
|
||||
}
|
||||
|
||||
# Configure logrotate
|
||||
configure_logrotate() {
|
||||
log "INFO" "Configuring log rotation..."
|
||||
|
||||
cat > /etc/logrotate.d/azerothcore << EOF
|
||||
$INSTALL_DIR/deployment-logs/*.log {
|
||||
daily
|
||||
rotate 7
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
su $SERVICE_USER $SERVICE_USER
|
||||
}
|
||||
|
||||
$INSTALL_DIR/monitoring-logs/*.log {
|
||||
daily
|
||||
rotate 14
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
su $SERVICE_USER $SERVICE_USER
|
||||
}
|
||||
EOF
|
||||
|
||||
log "SUCCESS" "Log rotation configured"
|
||||
}
|
||||
|
||||
# Configure firewall (if ufw is available)
|
||||
configure_firewall() {
|
||||
if command -v ufw &> /dev/null; then
|
||||
log "INFO" "Configuring firewall rules..."
|
||||
|
||||
# Game server ports
|
||||
ufw allow 3784/tcp comment "AzerothCore Auth Server"
|
||||
ufw allow 8215/tcp comment "AzerothCore World Server"
|
||||
ufw allow 7778/tcp comment "AzerothCore SOAP"
|
||||
|
||||
# Database port (only from localhost)
|
||||
ufw allow from 127.0.0.1 to any port 64306 comment "AzerothCore MySQL"
|
||||
|
||||
# Web status (optional, adjust as needed)
|
||||
ufw allow 8080/tcp comment "AzerothCore Web Status"
|
||||
|
||||
log "SUCCESS" "Firewall rules configured"
|
||||
else
|
||||
log "WARN" "UFW not available, skipping firewall configuration"
|
||||
fi
|
||||
}
|
||||
|
||||
# Enable and start services
|
||||
enable_services() {
|
||||
log "INFO" "Enabling and starting services..."
|
||||
|
||||
# Reload systemd
|
||||
systemctl daemon-reload
|
||||
|
||||
# Enable services
|
||||
systemctl enable azerothcore.service
|
||||
systemctl enable azerothcore-monitor.service
|
||||
systemctl enable azerothcore-web.service
|
||||
|
||||
log "SUCCESS" "Services enabled"
|
||||
log "INFO" "To start services: systemctl start azerothcore"
|
||||
log "INFO" "To check status: systemctl status azerothcore"
|
||||
}
|
||||
|
||||
# Create uninstall script
|
||||
create_uninstall_script() {
|
||||
cat > "$INSTALL_DIR/uninstall.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
# Uninstall AzerothCore system service
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Stopping services..."
|
||||
systemctl stop azerothcore-web azerothcore-monitor azerothcore 2>/dev/null || true
|
||||
|
||||
echo "Disabling services..."
|
||||
systemctl disable azerothcore-web azerothcore-monitor azerothcore 2>/dev/null || true
|
||||
|
||||
echo "Removing service files..."
|
||||
rm -f /etc/systemd/system/azerothcore*.service
|
||||
rm -f /etc/logrotate.d/azerothcore
|
||||
|
||||
echo "Reloading systemd..."
|
||||
systemctl daemon-reload
|
||||
|
||||
echo "Removing installation directory..."
|
||||
read -p "Remove $INSTALL_DIR? [y/N] " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
rm -rf "$INSTALL_DIR"
|
||||
echo "Installation directory removed"
|
||||
fi
|
||||
|
||||
echo "AzerothCore system service uninstalled"
|
||||
EOF
|
||||
|
||||
chmod +x "$INSTALL_DIR/uninstall.sh"
|
||||
chown "$SERVICE_USER:$SERVICE_USER" "$INSTALL_DIR/uninstall.sh"
|
||||
}
|
||||
|
||||
# Display installation summary
|
||||
show_summary() {
|
||||
log "SUCCESS" "AzerothCore system service installation completed!"
|
||||
echo
|
||||
echo "📋 Installation Summary:"
|
||||
echo " • Install Directory: $INSTALL_DIR"
|
||||
echo " • Service User: $SERVICE_USER"
|
||||
echo " • Services: azerothcore, azerothcore-monitor, azerothcore-web"
|
||||
echo
|
||||
echo "🚀 Quick Start:"
|
||||
echo " • Start services: systemctl start azerothcore"
|
||||
echo " • Check status: systemctl status azerothcore"
|
||||
echo " • View logs: journalctl -u azerothcore -f"
|
||||
echo " • Web status: http://localhost:8080"
|
||||
echo
|
||||
echo "🔧 Management:"
|
||||
echo " • Stop services: systemctl stop azerothcore"
|
||||
echo " • Restart services: systemctl restart azerothcore"
|
||||
echo " • Disable services: systemctl disable azerothcore"
|
||||
echo " • Uninstall: $INSTALL_DIR/uninstall.sh"
|
||||
echo
|
||||
echo "📁 Important Paths:"
|
||||
echo " • Configuration: $INSTALL_DIR/.env"
|
||||
echo " • Data: $INSTALL_DIR/data/"
|
||||
echo " • Backups: $INSTALL_DIR/backups/"
|
||||
echo " • Logs: $INSTALL_DIR/deployment-logs/"
|
||||
echo " • Monitoring: $INSTALL_DIR/monitoring-logs/"
|
||||
echo
|
||||
}
|
||||
|
||||
# Main installation function
|
||||
main_install() {
|
||||
log "INFO" "Starting AzerothCore system service installation..."
|
||||
|
||||
check_root
|
||||
check_prerequisites
|
||||
create_service_user
|
||||
install_application
|
||||
create_systemd_services
|
||||
create_startup_config
|
||||
configure_logrotate
|
||||
configure_firewall
|
||||
enable_services
|
||||
create_uninstall_script
|
||||
show_summary
|
||||
}
|
||||
|
||||
# Command handling
|
||||
case "${1:-install}" in
|
||||
"install")
|
||||
main_install
|
||||
;;
|
||||
"uninstall")
|
||||
if [[ -f "$INSTALL_DIR/uninstall.sh" ]]; then
|
||||
"$INSTALL_DIR/uninstall.sh"
|
||||
else
|
||||
error_exit "Uninstall script not found. Manual removal required."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [install|uninstall]"
|
||||
echo
|
||||
echo "Environment Variables:"
|
||||
echo " SERVICE_USER=username # Service user (default: azerothcore)"
|
||||
echo " INSTALL_DIR=path # Install directory (default: /opt/azerothcore)"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " sudo $0 install # Standard installation"
|
||||
echo " sudo SERVICE_USER=wow $0 install # Custom user"
|
||||
echo " sudo $0 uninstall # Remove installation"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
65
monitoring-web/index.html
Normal file
65
monitoring-web/index.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>AzerothCore Status</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="refresh" content="30">
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
|
||||
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
||||
.header { text-align: center; margin-bottom: 30px; }
|
||||
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
|
||||
.service-card { border: 1px solid #ddd; border-radius: 8px; padding: 15px; }
|
||||
.service-running { border-left: 4px solid #4CAF50; }
|
||||
.service-warning { border-left: 4px solid #FF9800; }
|
||||
.service-critical { border-left: 4px solid #F44336; }
|
||||
.service-missing { border-left: 4px solid #9E9E9E; }
|
||||
.metric { display: flex; justify-content: space-between; margin: 5px 0; }
|
||||
.timestamp { text-align: center; color: #666; margin-top: 20px; }
|
||||
table { width: 100%; border-collapse: collapse; margin: 10px 0; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||
th { background-color: #f2f2f2; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🏰 AzerothCore Server Status</h1>
|
||||
<p>System Uptime: up 1 day, 9 hours, 22 minutes</p>
|
||||
</div>
|
||||
|
||||
<div class="status-grid">
|
||||
<div class="service-card service-missing">
|
||||
<h3>Authentication Server</h3>
|
||||
<div class="metric"><strong>Service:</strong> <span>ac-authserver</span></div>
|
||||
<div class="metric"><strong>Status:</strong> <span>Not Running</span></div>
|
||||
</div>
|
||||
<div class="service-card service-missing">
|
||||
<h3>MySQL Database</h3>
|
||||
<div class="metric"><strong>Service:</strong> <span>ac-mysql</span></div>
|
||||
<div class="metric"><strong>Status:</strong> <span>Not Running</span></div>
|
||||
</div>
|
||||
<div class="service-card service-missing">
|
||||
<h3>Backup Service</h3>
|
||||
<div class="metric"><strong>Service:</strong> <span>ac-backup</span></div>
|
||||
<div class="metric"><strong>Status:</strong> <span>Not Running</span></div>
|
||||
</div>
|
||||
<div class="service-card service-missing">
|
||||
<h3>World Server</h3>
|
||||
<div class="metric"><strong>Service:</strong> <span>ac-worldserver</span></div>
|
||||
<div class="metric"><strong>Status:</strong> <span>Not Running</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Recent Alerts</h2>
|
||||
<table>
|
||||
<tr><th>Time</th><th>Level</th><th>Service</th><th>Message</th></tr>
|
||||
</table>
|
||||
|
||||
<div class="timestamp">
|
||||
Last updated: 2025-09-29 22:13:56
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
286
test-deployment.sh
Executable file
286
test-deployment.sh
Executable file
@@ -0,0 +1,286 @@
|
||||
#!/bin/bash
|
||||
# ==============================================
|
||||
# AzerothCore Deployment Test Script
|
||||
# ==============================================
|
||||
# Tests the deployment script functionality
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() {
|
||||
local level="$1"
|
||||
shift
|
||||
local message="$*"
|
||||
|
||||
case "$level" in
|
||||
"INFO") echo -e "${BLUE}[INFO]${NC} $message" ;;
|
||||
"WARN") echo -e "${YELLOW}[WARN]${NC} $message" ;;
|
||||
"ERROR") echo -e "${RED}[ERROR]${NC} $message" ;;
|
||||
"SUCCESS") echo -e "${GREEN}[SUCCESS]${NC} $message" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Test deployment script
|
||||
test_deployment_script() {
|
||||
log "INFO" "Testing deployment script functionality..."
|
||||
|
||||
# Test help command
|
||||
if ./azerothcore-deploy.sh --help >/dev/null 2>&1; then
|
||||
log "SUCCESS" "Help command works"
|
||||
else
|
||||
log "ERROR" "Help command failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test configuration validation
|
||||
if ./azerothcore-deploy.sh status >/dev/null 2>&1; then
|
||||
log "SUCCESS" "Status command works"
|
||||
else
|
||||
log "WARN" "Status command failed (expected if no services running)"
|
||||
fi
|
||||
|
||||
log "SUCCESS" "Deployment script tests passed"
|
||||
}
|
||||
|
||||
# Test monitoring script
|
||||
test_monitoring_script() {
|
||||
log "INFO" "Testing monitoring script functionality..."
|
||||
|
||||
# Test status generation
|
||||
if ./azerothcore-monitor.sh status >/dev/null 2>&1; then
|
||||
log "SUCCESS" "Monitoring status generation works"
|
||||
else
|
||||
log "ERROR" "Monitoring status generation failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if web directory was created
|
||||
if [[ -d "monitoring-web" ]] && [[ -f "monitoring-web/index.html" ]]; then
|
||||
log "SUCCESS" "Web status page generated"
|
||||
else
|
||||
log "ERROR" "Web status page not generated"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "SUCCESS" "Monitoring script tests passed"
|
||||
}
|
||||
|
||||
# Test database layer deployment
|
||||
test_database_layer() {
|
||||
log "INFO" "Testing database layer deployment..."
|
||||
|
||||
# Ensure clean state
|
||||
docker-compose -f docker-compose-azerothcore-database.yml down 2>/dev/null || true
|
||||
|
||||
# Test database deployment
|
||||
log "INFO" "Starting database layer..."
|
||||
if docker-compose -f docker-compose-azerothcore-database.yml up -d ac-mysql; then
|
||||
log "SUCCESS" "MySQL started successfully"
|
||||
|
||||
# Wait for health check
|
||||
local timeout=60
|
||||
local start_time=$(date +%s)
|
||||
|
||||
while [[ $(($(date +%s) - start_time)) -lt $timeout ]]; do
|
||||
if docker ps --filter "name=ac-mysql" --format "{{.Status}}" | grep -q "healthy"; then
|
||||
log "SUCCESS" "MySQL is healthy"
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Test database connection
|
||||
if docker run --rm --network azerothcore mysql:8.0 \
|
||||
mysql -h ac-mysql -uroot -pazerothcore123 -e "SELECT 1;" &>/dev/null; then
|
||||
log "SUCCESS" "Database connectivity test passed"
|
||||
else
|
||||
log "ERROR" "Database connectivity test failed"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
docker-compose -f docker-compose-azerothcore-database.yml down
|
||||
log "INFO" "Database layer test cleanup completed"
|
||||
|
||||
else
|
||||
log "ERROR" "MySQL failed to start"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "SUCCESS" "Database layer tests passed"
|
||||
}
|
||||
|
||||
# Test environment setup
|
||||
test_environment() {
|
||||
log "INFO" "Testing environment setup..."
|
||||
|
||||
# Check required files
|
||||
local required_files=(
|
||||
"azerothcore-deploy.sh"
|
||||
"azerothcore-monitor.sh"
|
||||
"install-system-service.sh"
|
||||
".env-database-local"
|
||||
"docker-compose-azerothcore-database.yml"
|
||||
)
|
||||
|
||||
for file in "${required_files[@]}"; do
|
||||
if [[ -f "$file" ]]; then
|
||||
log "SUCCESS" "$file exists"
|
||||
else
|
||||
log "ERROR" "$file missing"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if scripts are executable
|
||||
for script in azerothcore-deploy.sh azerothcore-monitor.sh install-system-service.sh; do
|
||||
if [[ -x "$script" ]]; then
|
||||
log "SUCCESS" "$script is executable"
|
||||
else
|
||||
log "ERROR" "$script is not executable"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
log "SUCCESS" "Environment tests passed"
|
||||
}
|
||||
|
||||
# Test Docker requirements
|
||||
test_docker() {
|
||||
log "INFO" "Testing Docker requirements..."
|
||||
|
||||
# Check Docker
|
||||
if command -v docker &> /dev/null; then
|
||||
log "SUCCESS" "Docker is installed"
|
||||
else
|
||||
log "ERROR" "Docker is not installed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check Docker daemon
|
||||
if docker info &> /dev/null; then
|
||||
log "SUCCESS" "Docker daemon is running"
|
||||
else
|
||||
log "ERROR" "Docker daemon is not running"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check Docker Compose
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
log "SUCCESS" "Docker Compose is installed"
|
||||
else
|
||||
log "ERROR" "Docker Compose is not installed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "SUCCESS" "Docker tests passed"
|
||||
}
|
||||
|
||||
# Test system service installer (dry run)
|
||||
test_system_service_installer() {
|
||||
log "INFO" "Testing system service installer (validation only)..."
|
||||
|
||||
# Test script syntax
|
||||
if bash -n install-system-service.sh; then
|
||||
log "SUCCESS" "System service installer syntax is valid"
|
||||
else
|
||||
log "ERROR" "System service installer has syntax errors"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test help command
|
||||
if ./install-system-service.sh 2>&1 | grep -q "Usage:"; then
|
||||
log "SUCCESS" "System service installer help works"
|
||||
else
|
||||
log "ERROR" "System service installer help failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "SUCCESS" "System service installer tests passed"
|
||||
}
|
||||
|
||||
# Run all tests
|
||||
run_all_tests() {
|
||||
log "INFO" "Starting comprehensive deployment tests..."
|
||||
echo
|
||||
|
||||
local tests=(
|
||||
"test_environment"
|
||||
"test_docker"
|
||||
"test_deployment_script"
|
||||
"test_monitoring_script"
|
||||
"test_system_service_installer"
|
||||
"test_database_layer"
|
||||
)
|
||||
|
||||
local passed=0
|
||||
local total=${#tests[@]}
|
||||
|
||||
for test in "${tests[@]}"; do
|
||||
echo "----------------------------------------"
|
||||
if $test; then
|
||||
((passed++))
|
||||
else
|
||||
log "ERROR" "Test $test failed"
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
echo "========================================"
|
||||
log "INFO" "Test Results: $passed/$total tests passed"
|
||||
|
||||
if [[ $passed -eq $total ]]; then
|
||||
log "SUCCESS" "All tests passed! 🎉"
|
||||
log "INFO" "Your AzerothCore deployment is ready"
|
||||
return 0
|
||||
else
|
||||
log "ERROR" "Some tests failed. Please fix issues before deployment."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Command handling
|
||||
case "${1:-all}" in
|
||||
"all")
|
||||
run_all_tests
|
||||
;;
|
||||
"environment")
|
||||
test_environment
|
||||
;;
|
||||
"docker")
|
||||
test_docker
|
||||
;;
|
||||
"deployment")
|
||||
test_deployment_script
|
||||
;;
|
||||
"monitoring")
|
||||
test_monitoring_script
|
||||
;;
|
||||
"database")
|
||||
test_database_layer
|
||||
;;
|
||||
"installer")
|
||||
test_system_service_installer
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [all|environment|docker|deployment|monitoring|database|installer]"
|
||||
echo
|
||||
echo "Tests:"
|
||||
echo " all Run all tests (default)"
|
||||
echo " environment Test file structure and permissions"
|
||||
echo " docker Test Docker installation and daemon"
|
||||
echo " deployment Test deployment script functionality"
|
||||
echo " monitoring Test monitoring script functionality"
|
||||
echo " database Test database layer deployment"
|
||||
echo " installer Test system service installer"
|
||||
echo
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user