Update 6_server-start.sh

This commit is contained in:
bashermens
2026-01-10 19:51:56 +01:00
committed by GitHub
parent dbce6dd149
commit fd7888f0db

View File

@@ -1,37 +1,48 @@
#!/bin/bash
##########################################################################################
# AzerothCore Server Start Script
# - Normal mode: runs via acore.sh (auto-restart, normal logs)
# - Debug mode: runs worldserver under GDB (no auto-restart, crash logs)
##########################################################################################
##########################################################################################
# ===============================
# Configuration
##########################################################################################
ROOT_DIR="$(pwd)"
# ===============================
ROOT_DIR="/home/dev/azerothcore_installer"
SERVER_ROOT="$ROOT_DIR/_server/azerothcore"
LOGS_PATH="/tmp/ac/logs"
CRASHES_PATH="/tmp/ac/crashes"
AUTHSERVER_SESSION="auth-session"
WORLDSERVER_SESSION="world-session"
LOGS_PATH="/tmp/ac/logs"
CRASHES_PATH="/tmp/ac/crashes"
mkdir -p "$LOGS_PATH" "$CRASHES_PATH"
# Timestamp for log files
NOW=$(date +"%Y%m%d_%H%M%S")
AUTH_LOG="$LOGS_PATH/authserver_$NOW.log"
WORLD_LOG="$LOGS_PATH/worldserver_$NOW.log"
GDB_LOG="$CRASHES_PATH/worldserver_gdb_$NOW.log"
# Check for debug mode
DEBUG_MODE=0
if [[ "$1" == "debug" ]]; then
DEBUG_MODE=1
echo "DEBUG MODE: worldserver will run under GDB"
fi
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
AUTH_LOG="$LOGS_PATH/authserver_$TIMESTAMP.log"
WORLD_LOG="$LOGS_PATH/worldserver_$TIMESTAMP.log"
##########################################################################################
# Helper function to start tmux session
##########################################################################################
# ===============================
# Helper: start tmux session
# ===============================
start_tmux_session() {
local session_name=$1
local command=$2
local log_file=$3
# Create session if it doesn't exist
if tmux has-session -t "$session_name" 2>/dev/null; then
echo "Tmux session '$session_name' already exists, sending command..."
echo "Tmux session '$session_name' already exists, attaching command..."
else
if tmux new-session -d -s "$session_name"; then
echo "Created tmux session: $session_name"
@@ -41,41 +52,43 @@ start_tmux_session() {
fi
fi
# Redirect output to log file (new file)
tmux send-keys -t "$session_name" "$command | tee $log_file" C-m
echo "Running '$command' in $session_name, logging to $log_file"
# Run the command in tmux, output redirected to log file (overwrite)
tmux send-keys -t "$session_name" "$command >$log_file 2>&1" C-m
echo "Running '$command' inside $session_name, logging to $log_file"
echo
}
##########################################################################################
# Start authserver (always normal)
##########################################################################################
start_tmux_session "$AUTHSERVER_SESSION" "$SERVER_ROOT/acore.sh run-authserver" "$AUTH_LOG"
# ===============================
# Start Authserver
# ===============================
AUTH_CMD="$SERVER_ROOT/acore.sh run-authserver"
start_tmux_session "$AUTHSERVER_SESSION" "$AUTH_CMD" "$AUTH_LOG"
##########################################################################################
# Start worldserver
##########################################################################################
# ===============================
# Start Worldserver
# ===============================
if [[ $DEBUG_MODE -eq 1 ]]; then
# Debug mode: run binary directly under GDB
GDB_LOG="$CRASHES_PATH/worldserver_gdb_$TIMESTAMP.log"
GDB_CMD="gdb -ex \"set logging file $GDB_LOG\" \
-ex \"set logging enabled on\" \
-ex \"run\" \
-ex \"bt full\" \
-ex \"quit\" \
WORLD_CMD="gdb -ex 'set logging file $GDB_LOG' \
-ex 'set logging enabled on' \
-ex 'run' \
-ex 'bt full' \
-ex 'quit' \
--args $SERVER_ROOT/env/dist/bin/worldserver"
start_tmux_session "$WORLDSERVER_SESSION" "$GDB_CMD" "$WORLD_LOG"
echo "DEBUG MODE: worldserver running under GDB, crash log: $GDB_LOG"
else
# Normal mode: use acore.sh for auto-restart
start_tmux_session "$WORLDSERVER_SESSION" "$SERVER_ROOT/acore.sh run-worldserver" "$WORLD_LOG"
WORLD_CMD="$SERVER_ROOT/acore.sh run-worldserver"
fi
##########################################################################################
# Optional: launch interactive menu
##########################################################################################
source "$ROOT_DIR/script/menu.sh"
start_tmux_session "$WORLDSERVER_SESSION" "$WORLD_CMD" "$WORLD_LOG"
# ===============================
# Launch menu
# ===============================
if [[ -f "$ROOT_DIR/script/menu.sh" ]]; then
source "$ROOT_DIR/script/menu.sh"
else
echo "WARNING: menu.sh not found at $ROOT_DIR/script/menu.sh"
fi
echo "Server start script finished."
[[ $DEBUG_MODE -eq 1 ]] && echo "DEBUG: worldserver GDB log: $GDB_LOG"