|
|
3 months ago | |
|---|---|---|
| .gitignore | 3 months ago | |
| Makefile | 3 months ago | |
| README.md | 3 months ago | |
| config.ini | 3 months ago | |
| main.py | 3 months ago | |
| port-butler.service | 3 months ago | |
README.md
Service Butler - Quick Start Guide
This script is a "butler" for your services (especially game servers). It saves RAM and CPU by running them only when someone actually wants to connect.
Install
make install
It will place the binary and configs on it's place.
The next step is enable and start service:
systemctl enable port-butler
systemctl start port-butler
How it works
The butler follows a simple loop for each service you configure:
- Sleeping & Listening: It sits on your service's port, waiting. The real service is offline.
- Wake Up Call: As soon as someone tries to connect, the butler catches the attempt, tells them to hold on (by closing the connection), and immediately starts waking up the real service.
- Waking Up: It runs your
start_command. After a shortstartup_delay_sec, it begins watching. - Watching: It periodically runs your
check_commandto see if anyone is using the service. As long as people are active, it does nothing. - Going to Sleep: Once the service has been empty for
idle_limit_sec, the butler runs thestop_commandand goes back to step 1.
If the script is restarted, it uses is_running_command to see if the service is already up, so it can jump straight to the "Watching" step without restarting it.
Configuration
See config.ini for example.
It placed to /etc/butler.ini during installation.
Each service gets its own section, like [minecraft]. Here are the options:
-
start_commandThe shell command to start your service. e.g.,systemctl start minecraft. -
stop_commandThe shell command to stop your service. e.g.,systemctl stop minecraft. -
is_running_commandA command that checks if the service is already active. This is crucial for when the butler script restarts. It should exit with0if running, and non-zero otherwise. Thesystemctl is-active --quiet <service>command is perfect for this. -
check_commandThe most important command. It checks if the service is being used. The butler only cares about the exit code:0means "active", anything else means "idle". -
listen_portThe public port of your service (e.g.,25565for Minecraft). The butler will listen here when the service is down. -
listen_hostThe IP to listen on.0.0.0.0is what you want 99% of the time, as it means "listen for connections from anywhere." -
check_interval_secHow often (in seconds) to run thecheck_commandwhile the service is up. -
idle_limit_secHow long (in seconds) the service can be idle before the butler shuts it down. -
startup_delay_secA short pause (in seconds) after starting the service before the first activity check. This gives your server time to fully load.