mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-26 07:06:23 +00:00
fix(bash): Improve session management and GDB handling in service scripts (#22418)
This pull request introduces several enhancements and fixes to the startup scripts for AzerothCore, focusing on improving service management, interactive mode handling, and script execution. The most important changes include adding support for non-interactive mode, enhancing systemd integration, and refactoring the starter script to handle binary paths and files more robustly. ### Enhancements to Service Management: * **Non-Interactive Mode:** Added `AC_DISABLE_INTERACTIVE` environment variable to disable interactive prompts for services running without session managers (e.g., systemd/pm2). This prevents hanging during non-interactive execution. (`apps/startup-scripts/src/run-engine`, `apps/startup-scripts/src/service-manager.sh`) [[1]](diffhunk://#diff-1792abab64da981c71221890876ce832aab405f670f320f75b73b8788b1a4174R336-R349) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R724-R727) * **Enhanced Systemd Integration:** Services using session managers like tmux/screen are automatically configured with `Type=forking` and appropriate `ExecStop` commands to terminate sessions gracefully. (`apps/startup-scripts/src/service-manager.sh`) [[1]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R401-R425) [[2]](diffhunk://#diff-31edfed7f73d0647a5fc96ce74c249e025e884cd1fe06621cb78eb4a381464f9R567-R578) ### Improvements to Script Execution: * **Starter Script Refactor:** Updated the starter script to require both binary path and file name as parameters, improving clarity and error handling. (`apps/startup-scripts/src/starter`) [[1]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631L6-R16) [[2]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631L26-R44) * **Temporary GDB File Management:** Enhanced handling of temporary GDB configuration files, ensuring proper cleanup after execution. (`apps/startup-scripts/src/starter`) [[1]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631R68-R70) [[2]](diffhunk://#diff-e92f132163ec1e49dc625eac9107c6841ae14e416aa35adec787dca5031dc631R92-R141) ### Updates to Tests: * **Test Adjustments:** Modified test cases to reflect the updated starter script parameter requirements and error messages. (`apps/startup-scripts/test/test_startup_scripts.bats`) [[1]](diffhunk://#diff-febbaeb294e50bdba0511ecad5d44b0c3f11ae92c79dd19dbd5f61d41a654278L26-R26) [[2]](diffhunk://#diff-febbaeb294e50bdba0511ecad5d44b0c3f11ae92c79dd19dbd5f61d41a654278L41-R49)
This commit is contained in:
@@ -3,16 +3,17 @@
|
||||
# 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]
|
||||
# Usage: starter <binpath> <binfile> [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)
|
||||
# $1 - Binary path (required)
|
||||
# $2 - Binary file name (required)
|
||||
# $3 - GDB configuration file (optional)
|
||||
# $4 - Configuration file path (optional)
|
||||
# $5 - System log file (optional)
|
||||
# $6 - System error file (optional)
|
||||
# $7 - GDB enabled flag (0/1, optional)
|
||||
# $8 - Crashes directory path (optional)
|
||||
|
||||
BINPATH="$1"
|
||||
BINFILE="$2"
|
||||
@@ -23,25 +24,22 @@ 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"
|
||||
[ -n "$CONFIG" ] && CONFIG_ABS=$(realpath "$CONFIG")
|
||||
|
||||
# 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]"
|
||||
if [ -z "$BINPATH" ] || [ -z "$BINFILE" ]; then
|
||||
echo "Error: Binary path and file are required"
|
||||
echo "Usage: $0 <binpath> <binfile> [gdb_file] [config] [syslog] [syserr] [gdb_enabled] [crashes_path]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BINARY="$BINPATH/$BINFILE"
|
||||
if [ ! -f "$BINARY" ]; then
|
||||
echo "Error: Binary '$BINARY' not found"
|
||||
exit 1
|
||||
@@ -50,7 +48,7 @@ fi
|
||||
# Create crashes directory if it doesn't exist
|
||||
mkdir -p "$CRASHES_PATH"
|
||||
|
||||
cd $BINPATH || {
|
||||
cd "$BINPATH" || {
|
||||
echo "Error: Could not change to binary path '$BINPATH'"
|
||||
exit 1
|
||||
}
|
||||
@@ -59,22 +57,25 @@ 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
|
||||
|
||||
# Create GDB configuration file if it is not defined
|
||||
if [ -z "$GDB_FILE" ]; then
|
||||
|
||||
# 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"
|
||||
if [ -n "$CONFIG_ABS" ]; then
|
||||
echo "run -c $CONFIG_ABS" >> "$GDB_TEMP_FILE"
|
||||
else
|
||||
echo "run" >> "$GDB_TEMP_FILE"
|
||||
fi
|
||||
@@ -86,32 +87,54 @@ info thread
|
||||
thread apply all backtrace full
|
||||
EOF
|
||||
|
||||
|
||||
GDB_FILE="$GDB_TEMP_FILE"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# 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"
|
||||
gdb -x "$GDB_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)
|
||||
gdb -x "$GDB_FILE" --batch "$EXECPATH" > >(tee "$SYSLOG") 2> >(tee "$SYSERR" >&2)
|
||||
else
|
||||
gdb -x "$GDB_TEMP_FILE" --batch "$EXECPATH"
|
||||
gdb -x "$GDB_FILE" --batch "$EXECPATH"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Cleanup temporary GDB file
|
||||
rm -f "$GDB_TEMP_FILE"
|
||||
|
||||
|
||||
# clean up temporary GDB file if it exists
|
||||
if [ -n "$GDB_TEMP_FILE" ]; then
|
||||
# Clean up temporary GDB file
|
||||
rm -f "$GDB_TEMP_FILE"
|
||||
fi
|
||||
else
|
||||
if [ -n "$CONFIG" ]; then
|
||||
script -q -e -c "$EXECPATH -c \"$CONFIG\""
|
||||
# check if it's running under PM2 or `script` command does not exist
|
||||
# Note: script is used to capture output in non-interactive sessions such as systemd (without tmux/screen)
|
||||
# We use AC_LAUNCHED_BY_PM2 environment variable set by service-manager for robust PM2 detection
|
||||
if [[ "$AC_LAUNCHED_BY_PM2" == "1" || ! -x "$(command -v script)" ]]; then
|
||||
if [ -n "$CONFIG_ABS" ]; then
|
||||
"$EXECPATH" -c "$CONFIG_ABS"
|
||||
else
|
||||
"$EXECPATH"
|
||||
fi
|
||||
else
|
||||
script -q -e -c "$EXECPATH"
|
||||
if [ -n "$CONFIG_ABS" ]; then
|
||||
script -q -e -c "$EXECPATH -c \"$CONFIG_ABS\""
|
||||
else
|
||||
script -q -e -c "$EXECPATH"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user