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:
Yehonal
2025-07-05 23:02:04 +02:00
committed by GitHub
parent a1a11a7c38
commit 9a837ee1f7
6 changed files with 265 additions and 79 deletions

View File

@@ -135,6 +135,9 @@ export CONFIG="/path/to/worldserver.conf"
export SESSION_MANAGER="tmux" # none|auto|tmux|screen
export SESSION_NAME="ac-world"
# Interactive mode control
export AC_DISABLE_INTERACTIVE="0" # Set to 1 to disable interactive prompts (useful for non-interactive services)
# Debugging
export GDB_ENABLED="1" # 0 or 1
export GDB="/path/to/gdb.conf"
@@ -372,6 +375,29 @@ pm2 save
pm2 startup # Auto-start on boot
```
NOTE: pm2 cannot run tmux/screen sessions, but you can always use the `attach` command to connect to the service console because pm2 supports interactive mode.
### Environment Variables
The startup scripts recognize several environment variables for configuration and runtime behavior:
#### Service Detection Variables
- **`AC_LAUNCHED_BY_PM2`**: Set to `1` when launched by PM2 (automatically set by service-manager)
- Disables the use of the `script` command for output capture
- Enables non-interactive mode to prevent prompts
- More robust than relying on PM2's internal variables
- **`AC_DISABLE_INTERACTIVE`**: Controls interactive mode (0=enabled, 1=disabled)
- Automatically set based on execution context
- Prevents AzerothCore from showing interactive prompts in service environments
#### Configuration Variables
- **`RUN_ENGINE_*`**: See [Configuration](#configuration) section for complete list
- **`SERVICE_MODE`**: Set to `true` to enable service-specific behavior
- **`SESSION_MANAGER`**: Override session manager choice (tmux, screen, none, auto)
### Systemd Services
When using systemd as the service provider:
@@ -388,6 +414,11 @@ sudo systemctl status acore-auth
sudo systemctl enable acore-auth
```
**Enhanced systemd Integration:**
- **Automatic Service Type**: When using session managers (tmux/screen), services are automatically configured with `Type=forking` for proper daemon behavior
- **Smart ExecStop**: Services with session managers get automatic `ExecStop` commands to properly terminate tmux/screen sessions when stopping the service
- **Non-Interactive Mode**: Services without session managers automatically set `AC_DISABLE_INTERACTIVE=1` to prevent hanging on prompts
### Session Management in Services
Services can be configured with session managers for interactive access: