|
1 month ago | |
---|---|---|
.gitignore | 1 month ago | |
Makefile | 1 month ago | |
README.md | 1 month ago | |
config.ini | 1 month ago | |
main.py | 1 month ago | |
port-butler.service | 1 month 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_command
to 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_command
and 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_command
The shell command to start your service. e.g.,systemctl start minecraft
. -
stop_command
The shell command to stop your service. e.g.,systemctl stop minecraft
. -
is_running_command
A command that checks if the service is already active. This is crucial for when the butler script restarts. It should exit with0
if running, and non-zero otherwise. Thesystemctl is-active --quiet <service>
command is perfect for this. -
check_command
The most important command. It checks if the service is being used. The butler only cares about the exit code:0
means "active", anything else means "idle". -
listen_port
The public port of your service (e.g.,25565
for Minecraft). The butler will listen here when the service is down. -
listen_host
The IP to listen on.0.0.0.0
is what you want 99% of the time, as it means "listen for connections from anywhere." -
check_interval_sec
How often (in seconds) to run thecheck_command
while the service is up. -
idle_limit_sec
How long (in seconds) the service can be idle before the butler shuts it down. -
startup_delay_sec
A short pause (in seconds) after starting the service before the first activity check. This gives your server time to fully load.