This repository contains Python scripts designed to manage and maintain Dathost game servers. These scripts automate the cleanup of old logs, temporary files, and ensure the servers are kept active to avoid unintended shutdowns. The focus is on managing files related to the CS2 plugin MatchZy, console logs, and logs from CounterStrikeSharp.
-
cleanup.py
:- Automates the deletion of old logs and temporary files specific to MatchZy and other elements of the game server.
- Uses
CLEANUP_SERVER_IDS
from the.env
file to target specific servers for cleanup.
-
keepalive.py
:- Ensures that specified servers are kept active by periodically sending a start command.
- Configurable via the
.env
file withALLOW_REASSIGNMENT
to allow or disallow host reassignment. - Uses
KEEPALIVE_SERVER_IDS
from the.env
file to manage servers separately from the cleanup process.
- Clone this repository to your local machine or server where you intend to run these scripts:
git clone https://github.com/enghausen/Dathost-maintenance-scripts.git
- Navigate into the repository directory:
cd Dathost-maintenance-scripts
- Set up a virtual environment and activate it:
python -m venv venv source venv/bin/activate # For Linux/macOS venv\Scripts\activate # For Windows
- Install required packages:
pip install -r requirements.txt
- Copy the example environment file and configure your settings:
cp .env.example .env vi .env # Edit as needed
The .env
file includes the following variables:
# Dathost API credentials
USERNAME=your_username_here # The username for API authentication
PASSWORD=your_password_here # The password for API authentication
# Server IDs for cleanup script
CLEANUP_SERVER_IDS=server_id1,server_id2 # List of server IDs to run the cleanup script on
# Server IDs for keepalive script
KEEPALIVE_SERVER_IDS=server_id3,server_id4 # List of server IDs to run the keepalive script on
# Enable or disable host reassignment for keepalive
ALLOW_REASSIGNMENT=true # Set to 'true' or 'false'
# Number of days to retain logs before deletion
LOG_RETENTION_DAYS=7 # Days to keep logs before they are eligible for deletion
# Path where logs should be saved
LOG_DIRECTORY_PATH=/absolute/path/to/logs # Absolute path for storing logs
Important Note:
Always specify an absolute path for LOG_DIRECTORY_PATH
in the .env
file. When running via cron, relative paths (e.g., ./logs
) default to the user's home directory, which can lead to logs being saved in unexpected locations.
Logs are stored in the specified log directory (LOG_DIRECTORY_PATH
) and are divided into:
cleanup.log
: Logs cleanup operations.keepalive.log
: Logs keepalive operations.
To automate the execution of the scripts, add entries to your crontab. Use crontab -e
to edit your cron jobs:
# Daily cleanup at 06:00
0 6 * * * /path/to/venv/bin/python /path/to/Dathost-maintenance-scripts/cleanup.py
# Weekly server keepalive at 01:00 on Sundays
0 1 * * 0 /path/to/venv/bin/python /path/to/Dathost-maintenance-scripts/keepalive.py
Note:
- Logs are handled within the scripts themselves, so additional cron redirection (e.g.,
>> logfile
) is unnecessary. - Replace
/path/to/venv
and/path/to/Dathost-maintenance-scripts
with the actual paths on your system.
You can customize the scripts by editing the .env
file or directly modifying the Python scripts. Ensure that the paths specified for logs and other directories match your server's directory structure.
This project is licensed under the MIT License - see the LICENSE file for details.