feat: improve session management and PM2 support in startup scripts (#22420)

New feature to manage service restart policies and refactors crash logging paths for better flexibility and clarity. The most significant changes include adding support for configurable restart policies (`on-failure` and `always`), updating documentation to reflect these changes, and improving crash path handling in multiple scripts.
This commit is contained in:
Yehonal
2025-07-06 12:00:38 +02:00
committed by GitHub
parent 9a837ee1f7
commit 9fcacf7ea7
10 changed files with 150 additions and 57 deletions

View File

@@ -257,6 +257,29 @@ Production-ready service management:
# Force systemd
./service-manager.sh create world worldserver --provider systemd --bin-path /path/to/bin
# Create service with restart policy
./service-manager.sh create world worldserver --bin-path /path/to/bin --restart-policy always
```
#### Restart Policies
Services support two restart policies:
- **`on-failure`** (default): Restart only on crashes or errors (exit code != 0, only works with PM2 or systemd without tmux/screen)
- **`always`**: Restart on any exit, including clean shutdown (exit code 0)
**Important**: When using `--restart-policy always`, the in-game command `server shutdown X` will behave like `server restart X` - the service will automatically restart after shutdown. Only the shutdown message differs from a restart message.
```bash
# Service that restarts only on crashes (default behavior)
./service-manager.sh create auth authserver --bin-path /path/to/bin --restart-policy on-failure
# Service that always restarts (even on manual shutdown)
./service-manager.sh create world worldserver --bin-path /path/to/bin --restart-policy always
# Update existing service restart policy
./service-manager.sh update worldserver --restart-policy always
```
#### Service Operations
@@ -296,19 +319,22 @@ Production-ready service management:
### Method 1: Using Service Manager (Recommended)
```bash
# Create multiple world server instances
# Create multiple world server instances with different restart policies
./service-manager.sh create world1 worldserver \
--bin-path /path/to/bin \
--server-config /path/to/worldserver-realm1.conf
--server-config /path/to/worldserver-realm1.conf \
--restart-policy on-failure
./service-manager.sh create world2 worldserver \
--bin-path /path/to/bin \
--server-config /path/to/worldserver-realm2.conf
--server-config /path/to/worldserver-realm2.conf \
--restart-policy always
# Single auth server for all realms
# Single auth server for all realms (always restart for stability)
./service-manager.sh create auth authserver \
--bin-path /path/to/bin \
--server-config /path/to/authserver.conf
--server-config /path/to/authserver.conf \
--restart-policy always
```
### Method 2: Using Run Engine with Different Configurations
@@ -384,7 +410,7 @@ The startup scripts recognize several environment variables for configuration an
#### 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
- Disables the use of the `unbuffer` command for output capture
- Enables non-interactive mode to prevent prompts
- More robust than relying on PM2's internal variables