mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
feat(bash): startup-scripts reworked + bash scripts workflow integration (#22401)
This commit is contained in:
1
apps/startup-scripts/src/.gitignore
vendored
Normal file
1
apps/startup-scripts/src/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
logs
|
||||
57
apps/startup-scripts/src/conf.sh.dist
Normal file
57
apps/startup-scripts/src/conf.sh.dist
Normal file
@@ -0,0 +1,57 @@
|
||||
# AzerothCore Run Engine Default Configuration
|
||||
# This file contains default values that can be overridden by environment variables
|
||||
# Priority order: conf.sh > environment variables > conf.sh.dist (this file)
|
||||
|
||||
# Enable/disable GDB execution
|
||||
export GDB_ENABLED="${RUN_ENGINE_GDB_ENABLED:-0}"
|
||||
|
||||
# [optional] GDB configuration file
|
||||
# default: gdb.conf
|
||||
export GDB="${RUN_ENGINE_GDB:-}"
|
||||
|
||||
# Directory where binaries are stored
|
||||
export BINPATH="${RUN_ENGINE_BINPATH:-}"
|
||||
|
||||
# Server binary name (e.g., worldserver, authserver)
|
||||
export SERVERBIN="${RUN_ENGINE_SERVERBIN:-}"
|
||||
|
||||
# Path to server configuration file (including the file name)
|
||||
# ex: /home/user/azerothcore/etc/worldserver.conf
|
||||
export CONFIG="${RUN_ENGINE_CONFIG:-}"
|
||||
|
||||
# Session manager to use: none|auto|tmux|screen
|
||||
# auto will detect the best available option
|
||||
export SESSION_MANAGER="${RUN_ENGINE_SESSION_MANAGER:-none}"
|
||||
|
||||
# Default session manager (fallback when SESSION_MANAGER is not set)
|
||||
export DEFAULT_SESSION_MANAGER="${RUN_ENGINE_DEFAULT_SESSION_MANAGER:-none}"
|
||||
|
||||
# Path of the crashes directory
|
||||
# If not specified, it will be created in the same directory as logs named "crashes"
|
||||
export CRASHES_PATH="${RUN_ENGINE_CRASHES_PATH:-}"
|
||||
|
||||
# Path of log files directory
|
||||
export LOGS_PATH="${RUN_ENGINE_LOGS_PATH:-}"
|
||||
|
||||
# Prefix name for log files to avoid collision with other instances
|
||||
export LOG_PREFIX_NAME="${RUN_ENGINE_LOG_PREFIX_NAME:-}"
|
||||
|
||||
# [optional] Name of session (tmux session or screen session)
|
||||
# If not specified, a default name will be generated based on server binary
|
||||
export SESSION_NAME="${RUN_ENGINE_SESSION_NAME:-}"
|
||||
|
||||
# [optional] Screen-specific options: -A -m -d -S
|
||||
# WARNING: if you are running it under a systemd service
|
||||
# please do not remove -m -d arguments from screen if you are using it,
|
||||
# or keep WITH_CONSOLE=0. Otherwise the journald-logging system will take
|
||||
# 100% of CPU slowing down the whole machine.
|
||||
export SCREEN_OPTIONS="${RUN_ENGINE_SCREEN_OPTIONS:-}"
|
||||
|
||||
# Enable/disable console output
|
||||
# If disabled, output will be redirected to logging files
|
||||
export WITH_CONSOLE="${RUN_ENGINE_WITH_CONSOLE:-0}"
|
||||
|
||||
# Server PID (needed when GDB_ENABLED=1)
|
||||
export SERVERPID="${RUN_ENGINE_SERVERPID:-}"
|
||||
|
||||
|
||||
48
apps/startup-scripts/src/examples/restarter-auth.sh
Executable file
48
apps/startup-scripts/src/examples/restarter-auth.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore Auth Server Restarter Example
|
||||
# This example shows how to use the run-engine with restart functionality for authserver
|
||||
|
||||
PATH_RUNENGINE="./"
|
||||
CONFIG_FILE="./conf-auth.sh"
|
||||
|
||||
# Method 1: Using configuration file (recommended)
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo "Starting authserver with restart loop using config file: $CONFIG_FILE"
|
||||
source "$CONFIG_FILE"
|
||||
"$PATH_RUNENGINE/run-engine" restart "$SERVERBIN" --config "$CONFIG_FILE"
|
||||
else
|
||||
echo "Error: Configuration file not found: $CONFIG_FILE"
|
||||
echo "Please create $CONFIG_FILE by copying and modifying conf.sh.dist"
|
||||
echo "Make sure to set: export SERVERBIN=\"authserver\""
|
||||
echo ""
|
||||
echo "Alternative: Start with binary path directly"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine restart /path/to/bin/authserver"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine restart authserver # if in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Method 2: Direct binary path (full path)
|
||||
# Uncomment the line below to start with full binary path
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart /home/user/azerothcore/bin/authserver --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 3: Binary name only (system PATH)
|
||||
# Uncomment the line below if authserver is in your system PATH
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart authserver --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 4: With session manager (tmux/screen)
|
||||
# Uncomment the line below to use tmux session
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart authserver --session-manager tmux --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 5: Environment variables only
|
||||
# Uncomment the lines below for environment variable configuration
|
||||
#
|
||||
# export RUN_ENGINE_BINPATH="/path/to/your/bin"
|
||||
# export RUN_ENGINE_SERVERBIN="authserver"
|
||||
# export RUN_ENGINE_CONFIG="/path/to/authserver.conf"
|
||||
# "$PATH_RUNENGINE/run-engine" restart authserver
|
||||
|
||||
|
||||
47
apps/startup-scripts/src/examples/restarter-world.sh
Executable file
47
apps/startup-scripts/src/examples/restarter-world.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore World Server Restarter Example
|
||||
# This example shows how to use the run-engine with restart functionality for worldserver
|
||||
|
||||
PATH_RUNENGINE="./"
|
||||
CONFIG_FILE="./conf-world.sh"
|
||||
|
||||
# Method 1: Using configuration file (recommended)
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo "Starting worldserver with restart loop using config file: $CONFIG_FILE"
|
||||
"$PATH_RUNENGINE/run-engine" restart "$SERVERBIN" --config "$CONFIG_FILE"
|
||||
else
|
||||
echo "Error: Configuration file not found: $CONFIG_FILE"
|
||||
echo "Please create $CONFIG_FILE by copying and modifying conf.sh.dist"
|
||||
echo "Make sure to set: export SERVERBIN=\"worldserver\""
|
||||
echo ""
|
||||
echo "Alternative: Start with binary path directly"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine restart /path/to/bin/worldserver"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine restart worldserver # if in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Method 2: Direct binary path (full path)
|
||||
# Uncomment the line below to start with full binary path
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart /home/user/azerothcore/bin/worldserver --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 3: Binary name only (system PATH)
|
||||
# Uncomment the line below if worldserver is in your system PATH
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart worldserver --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 4: With session manager (tmux/screen)
|
||||
# Uncomment the line below to use tmux session
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" restart worldserver --session-manager tmux --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 5: Environment variables only
|
||||
# Uncomment the lines below for environment variable configuration
|
||||
#
|
||||
# export RUN_ENGINE_BINPATH="/path/to/your/bin"
|
||||
# export RUN_ENGINE_SERVERBIN="worldserver"
|
||||
# export RUN_ENGINE_CONFIG="/path/to/worldserver.conf"
|
||||
# "$PATH_RUNENGINE/run-engine" restart worldserver
|
||||
|
||||
|
||||
46
apps/startup-scripts/src/examples/starter-auth.sh
Executable file
46
apps/startup-scripts/src/examples/starter-auth.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore Auth Server Starter Example
|
||||
# This example shows how to use the run-engine to start authserver without restart loop
|
||||
|
||||
PATH_RUNENGINE="./"
|
||||
CONFIG_FILE="./conf-auth.sh"
|
||||
|
||||
# Method 1: Using configuration file (recommended)
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo "Starting authserver (single run) with config file: $CONFIG_FILE"
|
||||
"$PATH_RUNENGINE/run-engine" start "$SERVERBIN" --config "$CONFIG_FILE"
|
||||
else
|
||||
echo "Error: Configuration file not found: $CONFIG_FILE"
|
||||
echo "Please create $CONFIG_FILE by copying and modifying conf.sh.dist"
|
||||
echo "Make sure to set: export SERVERBIN=\"authserver\""
|
||||
echo ""
|
||||
echo "Alternative: Start with binary path directly"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine start /path/to/bin/authserver"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine start authserver # if in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Method 2: Direct binary path (full path)
|
||||
# Uncomment the line below to start with full binary path
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start /home/user/azerothcore/bin/authserver --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 3: Binary name only (system PATH)
|
||||
# Uncomment the line below if authserver is in your system PATH
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start authserver --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 4: With session manager (tmux/screen)
|
||||
# Uncomment the line below to use tmux session
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start authserver --session-manager tmux --server-config /path/to/authserver.conf
|
||||
|
||||
# Method 5: Environment variables only
|
||||
# Uncomment the lines below for environment variable configuration
|
||||
#
|
||||
# export RUN_ENGINE_BINPATH="/path/to/your/bin"
|
||||
# export RUN_ENGINE_SERVERBIN="authserver"
|
||||
# export RUN_ENGINE_CONFIG="/path/to/authserver.conf"
|
||||
# "$PATH_RUNENGINE/run-engine" start authserver
|
||||
|
||||
47
apps/startup-scripts/src/examples/starter-world.sh
Executable file
47
apps/startup-scripts/src/examples/starter-world.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore World Server Starter Example
|
||||
# This example shows how to use the run-engine to start worldserver without restart loop
|
||||
|
||||
PATH_RUNENGINE="./"
|
||||
CONFIG_FILE="./conf-world.sh"
|
||||
|
||||
# Method 1: Using configuration file (recommended)
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
echo "Starting worldserver (single run) with config file: $CONFIG_FILE"
|
||||
"$PATH_RUNENGINE/run-engine" start "$SERVERBIN" --config "$CONFIG_FILE"
|
||||
else
|
||||
echo "Error: Configuration file not found: $CONFIG_FILE"
|
||||
echo "Please create $CONFIG_FILE by copying and modifying conf.sh.dist"
|
||||
echo "Make sure to set: export SERVERBIN=\"worldserver\""
|
||||
echo ""
|
||||
echo "Alternative: Start with binary path directly"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine start /path/to/bin/worldserver"
|
||||
echo "Example: $PATH_RUNENGINE/run-engine start worldserver # if in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Method 2: Direct binary path (full path)
|
||||
# Uncomment the line below to start with full binary path
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start /home/user/azerothcore/bin/worldserver --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 3: Binary name only (system PATH)
|
||||
# Uncomment the line below if worldserver is in your system PATH
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start worldserver --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 4: With session manager (tmux/screen)
|
||||
# Uncomment the line below to use tmux session
|
||||
#
|
||||
# "$PATH_RUNENGINE/run-engine" start worldserver --session-manager tmux --server-config /path/to/worldserver.conf
|
||||
|
||||
# Method 5: Environment variables only
|
||||
# Uncomment the lines below for environment variable configuration
|
||||
#
|
||||
# export RUN_ENGINE_BINPATH="/path/to/your/bin"
|
||||
# export RUN_ENGINE_SERVERBIN="worldserver"
|
||||
# export RUN_ENGINE_CONFIG="/path/to/worldserver.conf"
|
||||
# "$PATH_RUNENGINE/run-engine" start worldserver
|
||||
|
||||
|
||||
7
apps/startup-scripts/src/gdb.conf
Normal file
7
apps/startup-scripts/src/gdb.conf
Normal file
@@ -0,0 +1,7 @@
|
||||
set logging enabled on
|
||||
set debug timestamp
|
||||
run
|
||||
bt
|
||||
bt full
|
||||
info thread
|
||||
thread apply all backtrace full
|
||||
467
apps/startup-scripts/src/run-engine
Executable file
467
apps/startup-scripts/src/run-engine
Executable file
@@ -0,0 +1,467 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore Run Engine
|
||||
# Advanced script for running AzerothCore services with session management and restart capabilities
|
||||
#
|
||||
# This script can be sourced to provide functions or executed directly with parameters
|
||||
#
|
||||
# Configuration Priority Order (highest to lowest):
|
||||
# 1. conf.sh - User configuration file (highest priority)
|
||||
# 2. Command line arguments (--config, --server-config, etc.)
|
||||
# 3. Environment variables (RUN_ENGINE_*)
|
||||
# 4. conf.sh.dist - Default configuration (lowest priority)
|
||||
#
|
||||
# Environment Variables:
|
||||
# RUN_ENGINE_CONFIG_FILE - Path to temporary configuration file (optional)
|
||||
# RUN_ENGINE_SESSION_MANAGER - Session manager (none|auto|tmux|screen, default: auto)
|
||||
# RUN_ENGINE_BINPATH - Binary directory path
|
||||
# RUN_ENGINE_SERVERBIN - Server binary name (worldserver|authserver)
|
||||
# RUN_ENGINE_CONFIG - Server configuration file path
|
||||
# RUN_ENGINE_LOGS_PATH - Directory for log files
|
||||
# RUN_ENGINE_CRASHES_PATH - Directory for crash dumps
|
||||
# RUN_ENGINE_SESSION_NAME - Session name for tmux/screen
|
||||
|
||||
export RUN_ENGINE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Configuration priority order:
|
||||
# 1. conf.sh (highest priority - user overrides)
|
||||
# 2. Environment variables (RUN_ENGINE_*)
|
||||
# 3. conf.sh.dist (lowest priority - defaults)
|
||||
|
||||
# Load default configuration first (sets defaults from environment variables)
|
||||
if [ -e "$RUN_ENGINE_PATH/conf.sh.dist" ]; then
|
||||
source "$RUN_ENGINE_PATH/conf.sh.dist"
|
||||
fi
|
||||
|
||||
# Load user configuration if exists (this takes priority over everything)
|
||||
if [ -e "$RUN_ENGINE_PATH/conf.sh" ]; then
|
||||
source "$RUN_ENGINE_PATH/conf.sh"
|
||||
fi
|
||||
|
||||
# Load configuration
|
||||
function load_config() {
|
||||
local config_file="$1"
|
||||
|
||||
# If a specific config file is provided via command line, load it
|
||||
# This allows temporary overrides for specific runs
|
||||
if [ -n "$config_file" ] && [ -e "$config_file" ]; then
|
||||
echo "Loading configuration from: $config_file"
|
||||
source "$config_file"
|
||||
elif [ -n "$RUN_ENGINE_CONFIG_FILE" ] && [ -e "$RUN_ENGINE_CONFIG_FILE" ]; then
|
||||
echo "Loading configuration from environment: $RUN_ENGINE_CONFIG_FILE"
|
||||
source "$RUN_ENGINE_CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# Final override with any remaining environment variables
|
||||
# This ensures that even after loading config files, environment variables take precedence
|
||||
BINPATH="${RUN_ENGINE_BINPATH:-$BINPATH}"
|
||||
SERVERBIN="${RUN_ENGINE_SERVERBIN:-$SERVERBIN}"
|
||||
CONFIG="${RUN_ENGINE_CONFIG:-$CONFIG}"
|
||||
SESSION_MANAGER="${RUN_ENGINE_SESSION_MANAGER:-$SESSION_MANAGER}"
|
||||
LOGS_PATH="${RUN_ENGINE_LOGS_PATH:-$LOGS_PATH}"
|
||||
CRASHES_PATH="${RUN_ENGINE_CRASHES_PATH:-$CRASHES_PATH}"
|
||||
}
|
||||
|
||||
# Detect available session manager
|
||||
function detect_session_manager() {
|
||||
if command -v tmux >/dev/null 2>&1; then
|
||||
echo "tmux"
|
||||
elif command -v screen >/dev/null 2>&1; then
|
||||
echo "screen"
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
}
|
||||
|
||||
# Determine which session manager to use
|
||||
function get_session_manager() {
|
||||
local requested="$1"
|
||||
|
||||
case "$requested" in
|
||||
"none")
|
||||
echo "none"
|
||||
;;
|
||||
"auto")
|
||||
detect_session_manager
|
||||
;;
|
||||
"tmux")
|
||||
if command -v tmux >/dev/null 2>&1; then
|
||||
echo "tmux"
|
||||
else
|
||||
echo "error"
|
||||
fi
|
||||
;;
|
||||
"screen")
|
||||
if command -v screen >/dev/null 2>&1; then
|
||||
echo "screen"
|
||||
else
|
||||
echo "error"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "none"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Configure log files
|
||||
function configure_files() {
|
||||
TRACE_BEGIN_STRING="SIGSEGV"
|
||||
TRACE_FILE="$LOGS_PATH/${LOG_PREFIX_NAME}_trace.log"
|
||||
ERR_FILE="$LOGS_PATH/${LOG_PREFIX_NAME}_error.log"
|
||||
SYSLOG="$LOGS_PATH/${LOG_PREFIX_NAME}_system.log"
|
||||
SYSERR="$LOGS_PATH/${LOG_PREFIX_NAME}_system.err"
|
||||
LINKS_FILE="$LOGS_PATH/${LOG_PREFIX_NAME}_crash_links.link"
|
||||
}
|
||||
|
||||
# Check if service is running
|
||||
function check_status() {
|
||||
local session_name="$1"
|
||||
local ret=1
|
||||
|
||||
# Check for GDB process
|
||||
local gdbres=$(pgrep -f "gdb.*--batch.*$SERVERBIN")
|
||||
if [[ "$GDB_ENABLED" -eq 1 && -n "$gdbres" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check for binary process
|
||||
local binres=$(pgrep -f "$SERVERBIN -c $CONFIG")
|
||||
if [ -n "$binres" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check session manager
|
||||
if [ -n "$session_name" ]; then
|
||||
case "$(get_session_manager "${SESSION_MANAGER:-auto}")" in
|
||||
"tmux")
|
||||
tmux has-session -t "$session_name" 2>/dev/null && return 1
|
||||
;;
|
||||
"screen")
|
||||
screen -ls "$session_name" 2>/dev/null | grep -q "$session_name" && return 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Run with session manager
|
||||
function run_with_session() {
|
||||
local session_manager="$1"
|
||||
local session_name="$2"
|
||||
local wrapper="$3"
|
||||
shift 3
|
||||
local args=("$@")
|
||||
|
||||
if [ "$wrapper" = "simple-restarter" ]; then
|
||||
script_path="$RUN_ENGINE_PATH/simple-restarter"
|
||||
else
|
||||
script_path="$RUN_ENGINE_PATH/starter"
|
||||
fi
|
||||
|
||||
case "$session_manager" in
|
||||
"tmux")
|
||||
echo "> Starting with tmux session: $session_name - attach with 'tmux attach -t $session_name'"
|
||||
tmux new-session -d -s "$session_name" -- "$script_path" "${args[@]}"
|
||||
;;
|
||||
"screen")
|
||||
local OPTIONS="-A -m -d -S"
|
||||
if [ -n "$SCREEN_OPTIONS" ]; then
|
||||
OPTIONS="$SCREEN_OPTIONS"
|
||||
fi
|
||||
echo "> Starting with screen session: $session_name (options: $OPTIONS) - attach with 'screen -r $session_name'"
|
||||
echo "screen $OPTIONS \"$session_name\" -- \"$script_path\" ${args[*]}"
|
||||
screen $OPTIONS "$session_name" -- "$script_path" "${args[@]}"
|
||||
;;
|
||||
"none"|*)
|
||||
echo "> Starting without session manager"
|
||||
"$script_path" "${args[@]}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
function parse_arguments() {
|
||||
local mode="$1"
|
||||
local serverbin="$2"
|
||||
shift 2
|
||||
|
||||
local config_file=""
|
||||
local serverconfig=""
|
||||
local session_manager=""
|
||||
|
||||
# Parse named arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--config)
|
||||
config_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
--server-config)
|
||||
serverconfig="$2"
|
||||
shift 2
|
||||
;;
|
||||
--session-manager)
|
||||
session_manager="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Export parsed values for use by start_service
|
||||
export PARSED_MODE="$mode"
|
||||
export PARSED_SERVERBIN="$serverbin"
|
||||
export PARSED_CONFIG_FILE="$config_file"
|
||||
export PARSED_SERVERCONFIG="$serverconfig"
|
||||
export PARSED_SESSION_MANAGER="$session_manager"
|
||||
}
|
||||
|
||||
# Start service (single run or with simple-restarter)
|
||||
function start_service() {
|
||||
local config_file="$1"
|
||||
local serverbin_path="$2"
|
||||
local serverconfig="$3"
|
||||
local use_restarter="${4:-false}"
|
||||
local session_manager_choice="$5"
|
||||
|
||||
# Load configuration first
|
||||
load_config "$config_file"
|
||||
|
||||
# if no session manager is specified, get it from config
|
||||
if [ -z "$session_manager_choice" ]; then
|
||||
session_manager_choice="$SESSION_MANAGER"
|
||||
fi
|
||||
|
||||
|
||||
# Parse serverbin_path to extract BINPATH and SERVERBIN
|
||||
if [ -n "$serverbin_path" ]; then
|
||||
# If it's a full path, extract directory and binary name
|
||||
if [[ "$serverbin_path" == */* ]]; then
|
||||
BINPATH="$(dirname "$serverbin_path")"
|
||||
SERVERBIN="$(basename "$serverbin_path")"
|
||||
else
|
||||
# If it's just a binary name, use it as-is (system PATH)
|
||||
SERVERBIN="$serverbin_path"
|
||||
BINPATH="${BINPATH:-""}" # Empty means use current directory or system PATH
|
||||
fi
|
||||
fi
|
||||
|
||||
# Use environment/config values if not set from command line
|
||||
BINPATH="${BINPATH:-$RUN_ENGINE_BINPATH}"
|
||||
SERVERBIN="${SERVERBIN:-$RUN_ENGINE_SERVERBIN}"
|
||||
CONFIG="${serverconfig:-$RUN_ENGINE_CONFIG}"
|
||||
|
||||
echo "SERVERBIN: $SERVERBIN"
|
||||
|
||||
# Validate required parameters
|
||||
if [ -z "$SERVERBIN" ]; then
|
||||
echo "Error: SERVERBIN is required"
|
||||
echo "Could not determine server binary from: $serverbin_path"
|
||||
echo "Provide it as:"
|
||||
echo " - Full path: $0 <mode> /path/to/bin/worldserver"
|
||||
echo " - Binary name: $0 <mode> worldserver"
|
||||
echo " - Environment variables: RUN_ENGINE_SERVERBIN"
|
||||
echo " - Configuration file with SERVERBIN variable"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# If BINPATH is set, validate binary exists and create log paths
|
||||
if [ -n "$BINPATH" ]; then
|
||||
if [ ! -d "$BINPATH" ]; then
|
||||
echo "Error: BINPATH not found: $BINPATH"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Set up directories and logging relative to BINPATH
|
||||
LOGS_PATH="${LOGS_PATH:-"$BINPATH/logs"}"
|
||||
mkdir -p "$LOGS_PATH"
|
||||
mkdir -p "$LOGS_PATH/crashes"
|
||||
else
|
||||
# For system binaries, try to detect binary location and create logs accordingly
|
||||
local detected_binpath=""
|
||||
|
||||
# Try to find binary in system PATH
|
||||
local binary_location=$(which "$SERVERBIN" 2>/dev/null)
|
||||
if [ -n "$binary_location" ]; then
|
||||
detected_binpath="$(dirname "$binary_location")"
|
||||
echo "Binary found in system PATH: $binary_location"
|
||||
# Set BINPATH to the detected location so starter script can find the binary
|
||||
BINPATH="$detected_binpath"
|
||||
fi
|
||||
|
||||
# Set up log paths based on detected or fallback location
|
||||
if [ -n "$detected_binpath" ]; then
|
||||
LOGS_PATH="${LOGS_PATH:-"$detected_binpath/logs"}"
|
||||
else
|
||||
# Fallback to current directory for logs
|
||||
LOGS_PATH="${LOGS_PATH:-./logs}"
|
||||
fi
|
||||
|
||||
CRASHES_PATH="${CRASHES_PATH:-"$LOGS_PATH/crashes"}"
|
||||
|
||||
mkdir -p "$LOGS_PATH"
|
||||
mkdir -p "$CRASHES_PATH"
|
||||
fi
|
||||
|
||||
# Set up logging names
|
||||
LOG_PREFIX_NAME="${LOG_PREFIX_NAME:-${SERVERBIN%server}}"
|
||||
|
||||
# Set up session name (with backward compatibility for SCREEN_NAME)
|
||||
SESSION_NAME="${SESSION_NAME:-$SCREEN_NAME}"
|
||||
SESSION_NAME="${SESSION_NAME:-AC-${SERVERBIN%server}}"
|
||||
|
||||
configure_files
|
||||
|
||||
local session_manager=$(get_session_manager "$session_manager_choice")
|
||||
|
||||
if [ "$session_manager" = "error" ]; then
|
||||
echo "Error: Invalid session manager specified: $session_manager_choice, is it installed?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using session manager: $session_manager"
|
||||
echo "Starting server: $SERVERBIN"
|
||||
|
||||
if [ -n "$CONFIG" ]; then
|
||||
echo "Server config: $CONFIG"
|
||||
else
|
||||
echo "Server config: default (not specified)"
|
||||
fi
|
||||
|
||||
if [ "$use_restarter" = "true" ]; then
|
||||
# Use simple-restarter for restart functionality
|
||||
local gdb_enabled="${GDB_ENABLED:-0}"
|
||||
run_with_session "$session_manager" "$SESSION_NAME" "simple-restarter" "$BINPATH" "$SERVERBIN" "$GDB" "$CONFIG" "$SYSLOG" "$SYSERR" "$gdb_enabled" "$CRASHES_PATH"
|
||||
else
|
||||
# Single run using starter
|
||||
local gdb_enabled="${GDB_ENABLED:-0}"
|
||||
run_with_session "$session_manager" "$SESSION_NAME" "starter" "$BINPATH" "$SERVERBIN" "$GDB" "$CONFIG" "$SYSLOG" "$SYSERR" "$gdb_enabled" "$CRASHES_PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
function finish() {
|
||||
local session_manager=$(get_session_manager "${SESSION_MANAGER:-auto}")
|
||||
if [ -n "$SESSION_NAME" ]; then
|
||||
case "$session_manager" in
|
||||
"tmux")
|
||||
tmux kill-session -t "$SESSION_NAME" 2>/dev/null || true
|
||||
;;
|
||||
"screen")
|
||||
screen -X -S "$SESSION_NAME" quit 2>/dev/null || true
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# Legacy compatibility functions for old examples
|
||||
function restarter() {
|
||||
echo "Legacy function 'restarter' called - redirecting to new API"
|
||||
start_service "" "" "" "true" "${SESSION_MANAGER:-auto}"
|
||||
}
|
||||
|
||||
function starter() {
|
||||
echo "Legacy function 'starter' called - redirecting to new API"
|
||||
start_service "" "" "" "false" "${SESSION_MANAGER:-auto}"
|
||||
}
|
||||
|
||||
# Set trap for cleanup (currently disabled to avoid interfering with systemd)
|
||||
# trap finish EXIT
|
||||
|
||||
# Main execution when script is run directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
case "${1:-help}" in
|
||||
"start"|"restart")
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "Error: Missing required arguments"
|
||||
echo "Usage: $0 <mode> <serverbin> [options]"
|
||||
echo "Example: $0 start worldserver --config ./conf-world.sh --server-config worldserver.conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse arguments
|
||||
if ! parse_arguments "$@"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine restart mode
|
||||
use_restarter="false"
|
||||
if [ "$PARSED_MODE" = "restart" ]; then
|
||||
use_restarter="true"
|
||||
fi
|
||||
|
||||
# Start service with parsed arguments
|
||||
start_service "$PARSED_CONFIG_FILE" "$PARSED_SERVERBIN" "$PARSED_SERVERCONFIG" "$use_restarter" "$PARSED_SESSION_MANAGER"
|
||||
;;
|
||||
"help"|*)
|
||||
echo "AzerothCore Run Engine"
|
||||
echo ""
|
||||
echo "Usage: $0 <mode> <serverbin> [options]"
|
||||
echo ""
|
||||
echo "Modes:"
|
||||
echo " start - Start service once (no restart on crash)"
|
||||
echo " restart - Start service with restart on crash (uses simple-restarter)"
|
||||
echo ""
|
||||
echo "Required Parameters:"
|
||||
echo " serverbin - Server binary (full path or binary name)"
|
||||
echo " Full path: /path/to/bin/worldserver"
|
||||
echo " Binary name: worldserver (uses system PATH)"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --config <file> - Path to configuration file"
|
||||
echo " --server-config <file> - Server configuration file (sets -c parameter)"
|
||||
echo " --session-manager <type> - Session manager: none|auto|tmux|screen (default: auto)"
|
||||
echo ""
|
||||
echo "Configuration Priority (highest to lowest):"
|
||||
echo " 1. conf.sh - User configuration file"
|
||||
echo " 2. Command line arguments (--config, --server-config, etc.)"
|
||||
echo " 3. Environment variables (RUN_ENGINE_*)"
|
||||
echo " 4. conf.sh.dist - Default configuration"
|
||||
echo ""
|
||||
echo "Environment Variables:"
|
||||
echo " RUN_ENGINE_CONFIG_FILE - Config file path"
|
||||
echo " RUN_ENGINE_SESSION_MANAGER - Session manager (default: auto)"
|
||||
echo " RUN_ENGINE_BINPATH - Binary directory path"
|
||||
echo " RUN_ENGINE_SERVERBIN - Server binary name"
|
||||
echo " RUN_ENGINE_CONFIG - Server configuration file"
|
||||
echo " RUN_ENGINE_LOGS_PATH - Directory for log files"
|
||||
echo " RUN_ENGINE_CRASHES_PATH - Directory for crash dumps"
|
||||
echo " RUN_ENGINE_SESSION_NAME - Session name for tmux/screen"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo ""
|
||||
echo " # Using full path to binary"
|
||||
echo " $0 start /home/user/ac/bin/worldserver"
|
||||
echo ""
|
||||
echo " # Using binary name (system PATH)"
|
||||
echo " $0 start worldserver"
|
||||
echo ""
|
||||
echo " # With configuration file"
|
||||
echo " $0 start worldserver --config ./conf-world.sh"
|
||||
echo ""
|
||||
echo " # With server configuration (sets -c parameter)"
|
||||
echo " $0 start /path/to/bin/worldserver --server-config /etc/worldserver.conf"
|
||||
echo ""
|
||||
echo " # With session manager"
|
||||
echo " $0 restart worldserver --session-manager tmux"
|
||||
echo ""
|
||||
echo " # Complete example"
|
||||
echo " $0 restart /home/user/ac/bin/worldserver --config ./conf-world.sh --server-config worldserver.conf --session-manager screen"
|
||||
echo ""
|
||||
echo "Binary Resolution:"
|
||||
echo " - Full path (contains /): Extracts directory and binary name"
|
||||
echo " - Binary name only: Uses system PATH to find executable"
|
||||
echo " Auto-detection will check current directory first, then system PATH"
|
||||
echo ""
|
||||
echo "Server Config:"
|
||||
echo " If --server-config is specified, it's passed as -c parameter to the server."
|
||||
echo " If not specified, the server will use its default configuration."
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
1261
apps/startup-scripts/src/service-manager.sh
Executable file
1261
apps/startup-scripts/src/service-manager.sh
Executable file
File diff suppressed because it is too large
Load Diff
89
apps/startup-scripts/src/simple-restarter
Executable file
89
apps/startup-scripts/src/simple-restarter
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore Simple Restarter
|
||||
# This script is a wrapper around the starter script that provides restart functionality
|
||||
# and maintains compatibility with the acore dashboard
|
||||
#
|
||||
# Usage: simple-restarter <binary> [gdb_file] [config] [syslog] [syserr] [gdb_enabled] [crashes_path]
|
||||
#
|
||||
# Parameters (same as starter):
|
||||
# $1 - Binary to execute (required)
|
||||
# $2 - GDB configuration file (optional)
|
||||
# $3 - Configuration file path (optional)
|
||||
# $4 - System log file (optional)
|
||||
# $5 - System error file (optional)
|
||||
# $6 - GDB enabled flag (0/1, optional)
|
||||
# $7 - Crashes directory path (optional)
|
||||
|
||||
# Get script directory
|
||||
CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Parameters (same as starter)
|
||||
BINPATH="$1"
|
||||
BINFILE="$2"
|
||||
GDB_FILE="$3"
|
||||
CONFIG="$4"
|
||||
SYSLOG="$5"
|
||||
SYSERR="$6"
|
||||
GDB_ENABLED="${7:-0}"
|
||||
CRASHES_PATH="$8"
|
||||
|
||||
BINARY="$BINPATH/$BINFILE"
|
||||
|
||||
# Default values (same as starter)
|
||||
DEFAULT_CRASHES_PATH="./crashes"
|
||||
DEFAULT_GDB_FILE="$CURRENT_PATH/gdb.conf"
|
||||
|
||||
# Set defaults if not provided
|
||||
CRASHES_PATH="${CRASHES_PATH:-$DEFAULT_CRASHES_PATH}"
|
||||
GDB_FILE="${GDB_FILE:-$DEFAULT_GDB_FILE}"
|
||||
|
||||
# Counters for crash detection
|
||||
_instant_crash_count=0
|
||||
_restart_count=0
|
||||
|
||||
# Check if starter script exists
|
||||
STARTER_SCRIPT="$CURRENT_PATH/starter"
|
||||
if [ ! -f "$STARTER_SCRIPT" ]; then
|
||||
echo "Error: starter script not found at $STARTER_SCRIPT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Main restart loop
|
||||
while true; do
|
||||
STARTING_TIME=$(date +%s)
|
||||
|
||||
# Use starter script to launch the binary with all parameters
|
||||
"$STARTER_SCRIPT" "$BINPATH" "$BINFILE" "$GDB_FILE" "$CONFIG" "$SYSLOG" "$SYSERR" "$GDB_ENABLED" "$CRASHES_PATH"
|
||||
|
||||
_exit_code=$?
|
||||
|
||||
echo "$(basename "$BINARY") terminated with exit code: $_exit_code"
|
||||
|
||||
# Calculate runtime
|
||||
ENDING_TIME=$(date +%s)
|
||||
DIFFERENCE=$((ENDING_TIME - STARTING_TIME))
|
||||
|
||||
((_restart_count++))
|
||||
echo "$(basename "$BINARY") terminated after $DIFFERENCE seconds, restart count: $_restart_count"
|
||||
|
||||
# Crash loop detection
|
||||
if [ $DIFFERENCE -lt 10 ]; then
|
||||
# Increment instant crash count if runtime is lower than 10 seconds
|
||||
((_instant_crash_count++))
|
||||
echo "Warning: Quick restart detected ($DIFFERENCE seconds) - instant crash count: $_instant_crash_count"
|
||||
else
|
||||
# Reset count on successful longer run
|
||||
_instant_crash_count=0
|
||||
fi
|
||||
|
||||
# Prevent infinite crash loops
|
||||
if [ $_instant_crash_count -gt 5 ]; then
|
||||
echo "Error: $(basename "$BINARY") restarter exited. Infinite crash loop prevented (6 crashes in under 10 seconds each)"
|
||||
echo "Please check your system configuration and logs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$(basename "$BINARY") will restart in 3 seconds..."
|
||||
sleep 3
|
||||
done
|
||||
117
apps/startup-scripts/src/starter
Executable file
117
apps/startup-scripts/src/starter
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# AzerothCore Starter Script
|
||||
# This script handles the execution of AzerothCore binaries with optional GDB support
|
||||
#
|
||||
# Usage: starter <binary> [gdb_file] [config] [syslog] [syserr] [gdb_enabled] [crashes_path]
|
||||
#
|
||||
# Parameters:
|
||||
# $1 - Binary to execute (required)
|
||||
# $2 - GDB configuration file (optional)
|
||||
# $3 - Configuration file path (optional)
|
||||
# $4 - System log file (optional)
|
||||
# $5 - System error file (optional)
|
||||
# $6 - GDB enabled flag (0/1, optional)
|
||||
# $7 - Crashes directory path (optional)
|
||||
|
||||
BINPATH="$1"
|
||||
BINFILE="$2"
|
||||
GDB_FILE="$3"
|
||||
CONFIG="$4"
|
||||
SYSLOG="$5"
|
||||
SYSERR="$6"
|
||||
GDB_ENABLED="${7:-0}"
|
||||
CRASHES_PATH="$8"
|
||||
|
||||
BINARY=$(realpath "$BINPATH/$BINFILE")
|
||||
|
||||
# Default values
|
||||
CURRENT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DEFAULT_CRASHES_PATH="$CURRENT_PATH/logs/crashes"
|
||||
DEFAULT_GDB_FILE="$CURRENT_PATH/gdb.conf"
|
||||
|
||||
# Set defaults if not provided
|
||||
CONFIG="${CONFIG:-""}"
|
||||
CRASHES_PATH="${CRASHES_PATH:-$DEFAULT_CRASHES_PATH}"
|
||||
GDB_FILE="${GDB_FILE:-$DEFAULT_GDB_FILE}"
|
||||
|
||||
# Validate binary
|
||||
if [ -z "$BINARY" ]; then
|
||||
echo "Error: Binary parameter is required"
|
||||
echo "Usage: $0 <binary> [gdb_file] [config] [syslog] [syserr] [gdb_enabled] [crashes_path]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$BINARY" ]; then
|
||||
echo "Error: Binary '$BINARY' not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create crashes directory if it doesn't exist
|
||||
mkdir -p "$CRASHES_PATH"
|
||||
|
||||
cd $BINPATH || {
|
||||
echo "Error: Could not change to binary path '$BINPATH'"
|
||||
exit 1
|
||||
}
|
||||
|
||||
EXECPATH=$(realpath "$BINFILE")
|
||||
|
||||
if [ "$GDB_ENABLED" -eq 1 ]; then
|
||||
echo "Starting $EXECPATH with GDB enabled"
|
||||
|
||||
# Generate GDB configuration on the fly
|
||||
TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)
|
||||
GDB_TEMP_FILE="$CRASHES_PATH/gdb-$TIMESTAMP.conf"
|
||||
GDB_OUTPUT_FILE="$CRASHES_PATH/gdb-$TIMESTAMP.txt"
|
||||
|
||||
# Create GDB configuration
|
||||
cat > "$GDB_TEMP_FILE" << EOF
|
||||
set logging file $GDB_OUTPUT_FILE
|
||||
set logging enabled on
|
||||
set debug timestamp
|
||||
EOF
|
||||
|
||||
# Add run command with config if specified
|
||||
if [ -n "$CONFIG" ]; then
|
||||
echo "run -c $CONFIG" >> "$GDB_TEMP_FILE"
|
||||
else
|
||||
echo "run" >> "$GDB_TEMP_FILE"
|
||||
fi
|
||||
|
||||
cat >> "$GDB_TEMP_FILE" << EOF
|
||||
bt
|
||||
bt full
|
||||
info thread
|
||||
thread apply all backtrace full
|
||||
EOF
|
||||
|
||||
# Create log files if specified
|
||||
if [ -n "$SYSLOG" ]; then
|
||||
[ ! -f "$SYSLOG" ] && touch "$SYSLOG"
|
||||
fi
|
||||
if [ -n "$SYSERR" ]; then
|
||||
[ ! -f "$SYSERR" ] && touch "$SYSERR"
|
||||
fi
|
||||
|
||||
# Execute with GDB
|
||||
if [ "${WITH_CONSOLE:-0}" -eq 0 ] && [ -n "$SYSLOG" ] && [ -n "$SYSERR" ]; then
|
||||
gdb -x "$GDB_TEMP_FILE" --batch "$EXECPATH" >> "$SYSLOG" 2>> "$SYSERR"
|
||||
else
|
||||
echo "> Console enabled"
|
||||
if [ -n "$SYSLOG" ] && [ -n "$SYSERR" ]; then
|
||||
gdb -x "$GDB_TEMP_FILE" --batch "$EXECPATH" > >(tee "$SYSLOG") 2> >(tee "$SYSERR" >&2)
|
||||
else
|
||||
gdb -x "$GDB_TEMP_FILE" --batch "$EXECPATH"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Cleanup temporary GDB file
|
||||
rm -f "$GDB_TEMP_FILE"
|
||||
else
|
||||
if [ -n "$CONFIG" ]; then
|
||||
script -q -e -c "$EXECPATH -c \"$CONFIG\""
|
||||
else
|
||||
script -q -e -c "$EXECPATH"
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user