diff --git a/script/6_server-start.sh b/script/6_server-start.sh index 10d0f71..7629090 100755 --- a/script/6_server-start.sh +++ b/script/6_server-start.sh @@ -1,23 +1,37 @@ #!/bin/bash +#./script.sh # normal mode +#./script.sh debug # debug mode (GDB, timestamped crash logs) + +########################################################################################## +# Toggle debug mode +########################################################################################## +DEBUG_MODE=0 +if [[ "$1" == "debug" ]]; then + DEBUG_MODE=1 +fi + ########################################################################################## # Paths for logs and crash dumps ########################################################################################## export LOGS_PATH="/tmp/ac/logs" export CRASHES_PATH="/tmp/ac/crashes" +# Ensure directories exist mkdir -p "$LOGS_PATH" "$CRASHES_PATH" ########################################################################################## -# Helper to start a tmux session and run a command +# Helper: start tmux session and run command ########################################################################################## start_tmux_session() { local session_name=$1 local command=$2 local log_file=$3 + local debug=$4 + # 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." + 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" @@ -30,53 +44,27 @@ start_tmux_session() { # Export environment variables inside tmux tmux send-keys -t "$session_name" "export LOGS_PATH=$LOGS_PATH; export CRASHES_PATH=$CRASHES_PATH" C-m - # Run the command and pipe output to a log file - tmux send-keys -t "$session_name" "$command | tee -a $log_file" C-m - - echo "Executed '$command' inside $session_name, logging to $log_file" + if [[ "$debug" -eq 1 ]]; then + # Timestamped GDB log + local gdb_log="$CRASHES_PATH/${session_name}_gdb_$(date +%Y%m%d_%H%M%S).log" + tmux send-keys -t "$session_name" "gdb -ex 'set logging file $gdb_log' -ex 'set logging enabled on' -ex 'run' -ex 'bt full' -ex 'quit' --args $command" C-m + echo "Debug mode enabled for $session_name, logging to $gdb_log" + else + # Normal mode: append output to log + tmux send-keys -t "$session_name" "$command | tee -a $log_file" C-m + echo "Executed '$command' inside $session_name, logging to $log_file" + fi echo } ########################################################################################## -# Start authserver normally in tmux +# Start servers ########################################################################################## -start_tmux_session "$AUTHSERVER_SESSION" "${SERVER_ROOT}/acore.sh run-authserver" "$LOGS_PATH/authserver.log" +# Authserver (no debug) +start_tmux_session "$AUTHSERVER_SESSION" "${SERVER_ROOT}/acore.sh run-authserver" "$LOGS_PATH/authserver.log" 0 -########################################################################################## -# Start worldserver under tmux + GDB for crash logging -########################################################################################## -WORLDSESSION="$WORLDSERVER_SESSION" -WORLD_CRASH_LOG="$CRASHES_PATH/worldserver_gdb.log" - -# Remove old crash log -[ -f "$WORLD_CRASH_LOG" ] && rm -f "$WORLD_CRASH_LOG" - -# Create worldserver tmux session if needed -if tmux has-session -t "$WORLDSESSION" 2>/dev/null; then - echo "Tmux session '$WORLDSESSION' already exists." -else - if tmux new-session -d -s "$WORLDSESSION"; then - echo "Created tmux session: $WORLDSESSION" - else - echo "Error creating tmux session: $WORLDSESSION" - exit 1 - fi -fi - -# Command to run worldserver under gdb in tmux -WORLD_CMD="gdb -ex 'set logging file $WORLD_CRASH_LOG' \ - -ex 'set logging on' \ - -ex 'run' \ - -ex 'bt full' \ - -ex 'quit' \ - --args ${SERVER_ROOT}/acore.sh run-worldserver" - -# Export env + run GDB inside tmux -tmux send-keys -t "$WORLDSESSION" "export LOGS_PATH=$LOGS_PATH; export CRASHES_PATH=$CRASHES_PATH" C-m -tmux send-keys -t "$WORLDSESSION" "$WORLD_CMD" C-m - -echo "Worldserver started in tmux session '$WORLDSESSION' with GDB crash logging to $WORLD_CRASH_LOG." -echo "Attach to tmux to see live output: tmux attach -t $WORLDSESSION" +# Worldserver (toggle debug) +start_tmux_session "$WORLDSERVER_SESSION" "${SERVER_ROOT}/acore.sh run-worldserver" "$LOGS_PATH/worldserver.log" $DEBUG_MODE ########################################################################################## # Launch interactive menu if needed