12
When you run a server that only has players for a few hours a day, you can save memory on your server by switching the server off when nobody's on.
This tutorial shows how to stop it when it's empty but just as importantly, how to start it when people want to get in. This can all be done without any plugins or mods. it only needs two scripts and a linux box.
In essence, what it does it to listen to the default minecraft server port 25565 and when a connection comes in, it starts the server and then passes all network traffic from the default port to the minecraft server port which needs to be different from default.
So in the server.properties, set "server-port=25555".
Next, the startup script to start the server uses 'screen' to start the server in the background. Create a 'start.sh" in your minecraft directory with the following content:
And that's it. Reload your xinetd and wait 15 minutes for the server to shutdown.
This tutorial shows how to stop it when it's empty but just as importantly, how to start it when people want to get in. This can all be done without any plugins or mods. it only needs two scripts and a linux box.
In essence, what it does it to listen to the default minecraft server port 25565 and when a connection comes in, it starts the server and then passes all network traffic from the default port to the minecraft server port which needs to be different from default.
So in the server.properties, set "server-port=25555".
Next, the startup script to start the server uses 'screen' to start the server in the background. Create a 'start.sh" in your minecraft directory with the following content:
- #!/bin/bash
- cd "$(dirname "$0")"
- # Change the next variables if needed
- RUN="bukkit.jar"
- USERNAME="minecraft"
- MINMEM="256M"
- MAXMEM="1280M"
- if ! pgrep -U "$USERNAME" -f "$RUN" > /dev/null ; then
- screen -dmS minecraft sudo -u "$USERNAME" -- /usr/bin/java -XX:ParallelGCThreads=2 -Djava.net.preferIPv4Stack=true -Xmx$MAXMEM -Xms$MINMEM -jar "$RUN"
- echo -en "xFFx00x16x00"
- echo -n "$MESSAGE" | sed 's/./x0/g'
- echo -en "xA7x00x30x00xA7x00x35"
- fi
- IP=$(sed -n 's/^server-ips*=s*([0-9.]*)s*$/1/p' server.properties)
- PORT=$(sed -n 's/^server-ports*=s*([0-9]*)s*$/1/p' server.properties)
- exec sudo -u "$USERNAME" nc "${IP:-127.0.0.1}" "${PORT:-25555}"
- #!/bin/bash
- cd $(dirname $0)
- scan=minecraft
- pl() {
- screen -S $scan -p 0 -X stuff 'who15'
- echo $(tail -n 1 /opt/minecraft/server.log | cut -f 6- -d ' ' | wc -m)
- }
- [ $(pl) -lt 5 ] && {
- echo NO players connected
- sleep 300
- screen -S $scan -p 0 -X stuff 'who15'
- [ $(pl) -lt 5 ] && {
- screen -S $scan -p 0 -X stuff 'stop15'
- }
- }
- # 25565 stream tcp nowait root /srv/minecraft/connectserver
- service minecraft
- {
- disable = no
- type = UNLISTED
- port = 25565
- socket_type = stream
- protocol = tcp
- user = root
- wait = no
- server = /opt/minecraft/start.sh
- max_load = 20.0
- }
- #change the 'server' setting to whatever dir minecraft is in.
- */15 * * * * /opt/minecraft/stop.sh
- #again, edit it to match de minecraft server directory
And that's it. Reload your xinetd and wait 15 minutes for the server to shutdown.
Tags |
tools/tracking
1473747
6
automatically-stop-a-server-when-nobodys-playing
Create an account or sign in to comment.
[url=/blog/automatically-stop-a-server-when-nobodys-playing/<a href=]github.com/gekigek99/minecraft-vanilla-server-hibernation[/url]
and it's updated to 2019 if someone needs it!!!
Because, it looks so COOL.
I have some questions concerning what is decribed above :
- Also, once the redirection step has occured, the redirection to port 25555 does not end when the server stops.
My understanding is that this tutorial presumes the minecraft server runs on a dedicated machine.I would like to use my own Mac to do so under a dedicated user account (setup according to the tutorial found here : Create a Mac OS X startup daemon).
For this purpose, is it OK to modify the redirection like this :
exec sudo -u "$USERNAME" nc -p 25565 "${IP:-127.0.0.1}" "${PORT:-25555}"
Also, if necessary, how do I stop/clear the redirection to port 25555 ?
Finally, what are those lines for ? :
- echo -en "xFFx00x16x00"
- echo -n "$MESSAGE" | sed 's/./x0/g'
- echo -en "xA7x00x30x00xA7x00x35"
Please, can somebody help me with that.