Monitoring script for a Euro Truck Simulator 2 dedicated server that detects and stops the server in rare cases where it hangs during startup or loses connection to Steam, allowing it to be restarted automatically. Currently supports Linux only.
Requirements:
- Python 3.9+
- Any modern Linux distribution
-
Clone or download the repository
git clone https://github.com/alexitx/ets2-server-watchdog cd ets2-server-watchdog
-
Create a virtual environment using virtualenv or venv
python3 -m virtualenv venv source ./venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
Run the server and watchdog script in separate terminals, screen/tmux sessions, or however is most convenient. The watchdog must be run as the same user as the server, or as root, to allow it to find the process of the server.
If the server is running inside Docker or any other sandboxed environment, you can pass custom command to the watchdog
script using --command
to be run whenever the server should be restarted. Make sure the server log file is accessible
on disk and that the watchdog has appropriate permissions to read it.
See example scripts.
python3 ets2_server_watchdog.py --server-log <server log file>
The server log file is in the Euro Truck Simulator 2
home directory, which is automatically created on server start in
$HOME
or $XDG_DATA_HOME
.
-
Create a start script for the ETS2 server that ensures the correct working directory for the server, has all environment variables set, such as
$LD_LIBRARY_PATH
or$XDG_DATA_HOME
(to set the location of theEuro Truck Simulator 2
config directory), and runs the server executable.Example:
#!/bin/bash SERVER_DIR="$HOME/servers/ets2-server" cd "$SERVER_DIR" export LD_LIBRARY_PATH="$SERVER_DIR/linux64" export XDG_DATA_HOME="$SERVER_DIR" ./bin/linux_x64/eurotrucks2_server
-
Wrap the executable call in a loop instead and add a small timeout after the server stops but before it restarts to allow exiting the script with Ctrl-C.
Before:
./bin/linux_x64/eurotrucks2_server
After:
while true; do ./bin/linux_x64/eurotrucks2_server echo 'Restarting the server in 3 seconds, press Ctrl-C to abort' sleep 3 done
Argument | Default | Required | Description |
---|---|---|---|
--debug |
No | Log debug messages | |
--debug-tail |
No | If debug is enabled, also log tail command output | |
--server-log |
Yes | Server log file | |
--hang-timeout |
1.0 |
No | Time in seconds for the server to hang on initialization before being killed |
--reconnect-timeout |
300.0 |
No | Time in seconds for the server to reconnect to Steam before being stopped |
--stop-timeout |
5.0 |
No | Time in seconds for the server to stop gracefully before being killed |
--monitor-interval |
0.25 |
No | Interval in seconds for monitoring log line changes; Should be < other timeout values, usually < 1s |
--command |
No | Custom command to run instead of finding and stopping the server process |
MIT license. See LICENSE for more information.