gekware / minecraft-server-hibernation Goto Github PK
View Code? Open in Web Editor NEWAutostart and stop minecraft-server when players join/leave
License: GNU General Public License v3.0
Autostart and stop minecraft-server when players join/leave
License: GNU General Public License v3.0
Checking whether or not the server.jar can be found on script startup should be essential to avoid users setting up something incorrectly and thinking their setup is working, while the script cannot find the server when a users actually tries to connect.
This should be handled with OS independent functions/libraries.
Since you need to have java installed to run a Minecraft server it might be nice to inform the user if the Java installation is not found or the version is insufficient.
A simple java -version
command in cmd/bash works on Windows and Linux and prints the current Java version along some other info.
Since this is probably language specific, it might be hard to parse the string that comes back.
A first step would then be to log the output so that the user can at least interpret it themselves.
Analytic logging level mention in #43 would be local analytics (saved to file).
Brainstorming for fledging out this feature needed.
Useful for optimizing server hardware and utilization.
Current ideas include (but are not guaranteed or limited to):
@gekigek99 just treat this as an idea collection to write anything that comes to mind to.
Before starting work on this feature, it needs to be properly planned out and it should also be done after most of the other issues.
Hello,
are you able to write the same code in javascript for the pterodactyl panel?
If yes I can even pay you for this.
thank you
to avoid problems when issuing start and stop commands
It would improve readability and allows the addition of comments (which is handy since the parameters are increasing)
Line 130 python (and corresponding golang) change from if to elif and adapt debug/client messages
I just installed this, but it couldn't run. The exact message I got was
# command-line-arguments ./minecraft-server-hibernation.go:491:21: undefined: strings.ReplaceAll
I'm running this on an Ubuntu server install. Are there any dependencies I'm not aware of or something else of that order?
Hello,
Do you think it’s possible to auto-detect when the server is up instead or using an static defined timer? By trying to connect to it, or using rcon, for example.
Change from screen to systemctl for Docker version to follow master.
Further testing required before changes can be implemented.
the script has come to the point where a reliable and complete log system is required.
I don't have particular plans but a good starting point could be to add in the logger()
function the ability to write the logs to a file.
Hi gekigek99, I came across this script yesterday and was excited to see it was exactly what I was looking for with the server I'm currently hosting.
However, I'm having an issue when trying to join the server after launching the script. As soon as I attempt to connect, the error message:
"**** FAILED TO BIND TO PORT!
[00:23:44] [Server thread/WARN]: The exception was: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[00:23:44] [Server thread/WARN]: Perhaps a server is already running on that port?"
comes up and stops the server immediately.
I have made sure that no other instances of the server are running
I have made sure that nothing else is assigned to that port.
I have also tried using several different ports
I have edited the ports within the server.properties file as well as the python script.
The server also runs flawlessly when I do not run it with the python script and there is no error message.
Any suggestions would be greatly appreciated. Thank you!
mojang probaby changed some rules and I would like to know how @najtin come up with the string to communicate the warning during server startup.
did you just captured the the bytes exchanged with the clients to reproduce them? if so how did you make the minecraft server send those?
Just to avoid tons of hours to solve this "stupid" issue.
thanks
I am currently testing some different configurations and encountered a different bug in the main go script.
@gekigek99 should I open a new issue for this?
I am using 1.16.2 and with the current code and only changed debug to true.
Originally posted by @lubocode in #31 (comment)
When trying to run the latest version of the python script I encountered a few errors. Some I was able to fix, others I am not.
After fixing these issues, the script would start but after starting up the server it would send me the error message:
this issue is to keep track of what to do before deprecating the python version.
before deprecating I want:
I think it might be helpful for users if the scripts advise them when a update is available. This would be set as an option in the config file.
(I would like to implement it before the v2.0.0 is released)
Make Server version into a Docker ENV variable and parse it in main.
Currently script advertises vanilla server. Previously, when neither advertising version number nor vanilla status, modded MC servers worked without a problem. Make this either dynamic or remove it from info string.
Edit: The two things above are partly implemented with the config.json from the latest commits on master.
The actual problem seems to be earlier during the connection establishment of the join process.
The server is just starting by visiting the multiplayer server list, this is due to the client requesting the amount of players online as well among other info.
The python Dockerfile and script on Branch "docker" currently do not work.
I think it’s related, so what about adding configuration for custom hibernation and startup messages? I modified the Python version for that until now but since it’s deprecated…
Sorry if it was already present or proposed.
Originally posted by @Br31zh in https://github.com/gekigek99/minecraft-server-hibernation/issue_comments/709141763
Is it planned to be able to pause the process?
And can you not let the port listen to that of the server when the server is stopped?
You can simply query the number of players.
Can the motd be transferred or replaced with a text?
Is it any way possible to access the server command line? Starting the script @reboot with crontab and launching the server.jar in a screen session as readme explains. Can't find any running screen sessions, but can connect to the server with minecraft client?
For now all I have is the following:
2020/10/14 18:15:47 *** MINECRAFT SERVER IS STARTING!
2020/10/14 18:15:47 *** PLAYER tried to join from 172.24.144.1:25555 to 127.0.0.1:25565
2020/10/14 18:15:47 closing connection for: 172.24.144.1
2020/10/14 18:16:08 *** MINECRAFT SERVER IS UP!
2020/10/14 18:16:59 *** from 172.24.144.1:25555 to 127.0.0.1:25565
2020/10/14 18:16:59 handleClientSocket: error during serverSocket.Dial()
2020/10/14 18:17:08 error stopping minecraft server: exit status 1
2020/10/14 18:17:08 *** MINECRAFT SERVER IS SHUTTING DOWN!
This indicates that the console command executes without error, but does not do what is intended.
Probably some permission stuff, but I will not exclude some moved file as a possibility for now.
I've been using the script for months now without any problems. It even worked in versions 1.16.0 and 1.16.1. Once I updated my server to 1.16.x the message telling clients how long it is until the server comes up isn't showing anymore. And with my current problem, I am getting the message "Exception in main(): [Errno 111] Connection refused" once I try to connect after the server has started. Any help is appreciated. Also, do you have any plans on updating the script to 1.16.2 for Linux?
I'm new to Ubuntu so I set up a VM on my computer before making my server run on it. I'm having some trouble getting the script work properly and I don't know what's wrong because there is no output to the terminal. It is likely because I incorrectly put in the server path. It is located in my home directory with all my other server files in a folder called minecraftdir. I am using the line "/home/gavvydizzle/minecraft" to reference the server folder. Just to add, I am using the terminal to run the python3 script. Is my directory wrong? or am I running the script incorrectly? Thanks for your help in advance. Edit: This was occuring on version 2.0 of the script
Function handleClientSocket at line 267 onwards for managing client joins should be changed so it looks manages packets based on the config's ListenPort rather than looking for [221, 2].
I changed my listening port to 25565 and target port to 25555. handleClientSocket is hard-coded to look for packets [...63 DD 2...] which is specifically for port 25565. When changing target to port 25555 it should be looking for [...63 D3 2...]. What should happen is it looks for bytes based on the config's Listen port.
edit - clarification
Hello,
That’s not really an issue, but I wanted to share this and don’t know where I can say it: I have my server on my (Linux) PC, and starting the server create CPU usage pikes, and freezes my other programs. So, instead of shutdown the server, I freeze it with a kill -STOP <pid>
and resume with kill -CONT <pid>
. It constantly use the 2GB of assigned RAM, but CPU, disk and network usage are null during this time. And the resume is instant, without CPU spike.
I had to set max-tick-time
to -1
in server.properties
and start the server before your script (and, since your script expect the server to be down, I freeze it before launching your script). I set the startup time to 1 in the configuration, and I resume the server before stopping it in my shutdown script (used when I want to completely stop the server).
It can give idea to others people, or to add new functionalities to the script, or as an example since it’s not an obvious way to use it.
on linux it throws this error.
I will investigate tomorrow
This issue derives from #30
I may have totally misunderstood but this "just" sleeps and wakes the server on an active machine?
I'd like to Sleep/Hibernate/Shutdown the Windows PC when nobody on server (and machine inactive also) and to use Wake on LAN to wake the machine and resume server.
Use case: 2nd PC I sometimes use... so don't want it suddenly sleeping when I am actually using it (which Windows itself takes care of, or MacOS or Linux if I were to use them). So I need it to pass the decision as to when to sleep to the OS when the MC server is inactive and on resume (someone remotely WOL's the PC) the MC server needs to resume....
Does that make any sense?!?
I mean, you take 1KB of data and forward it to the other port, however this process is slow and makes the connection between the client and the server be very laggy. If there was another way without involving python doing the job manually (like some builtin function to redirect data) then it may improve the overall performance.
Originally posted by @mariohackandglitch in #4 (comment)
make the python version windows compatible.
(it's better to maintain just one file and use different if to execute different instructions)
so that msh can send important messages to players when they are in-game
Im most likely being dumb here but im not used to python and code in general,
was wondering how i specify a path. "C:\Servs\1.16.1" Wont work...
The location of the config.json inside the docker does not make much sense without further info, as it is not easy to change.
I have three ideas for this:
That being said, it will still work without the user touching the config, but having options is always nice.
Since one can usually set their own MC server icon by naming a 64x64 pixel png to "server-icon.png" and putting it in the main server folder, how about having the current static image as a kind of default image and trying to detect, once on script startup, whether there is a user image and then using that?
...to make sure MC server is shut down upon script exit
Currently the Python script throws exceptions when interrupted through a SIGINT (ctrl + c) or SIGTERM.
To gracefully exit the script a signal handler needs to be introduced. This could look something like this:
from threading import Thread, Timer, Lock, enumerate, main_thread
import signal
def interruptHandler(signal, frame):
print('Termination signal detected. Exiting gracefully.')
threads = enumerate()
print("Trying to join the following threads:")
print(threads)
for t in threads:
if t != main_thread():
if t is threading.Timer:
t.cancel()
else:
t.join()
sys.exit(0)
def main():
# Listen for interrupt signal (e.g.: ctrl + c)
signal.signal(signal.SIGINT, interruptHandler)
signal.signal(signal.SIGTERM, interruptHandler)
Though after trying around a bit, the script continues to run even after successfully going through the join loop on my PC.
It also spawns a new Timer thread, which at least shows that the original Timer thread was successfully cancelled.
I think that either there is a thread that is not listed with enumerate()
or sys.exit(0)
is not working correctly, but I don't have enough experience with python threading to figure out what's really going on.
Resources:
Signal library
Threading library
Startup works fine. When I open multiplayer list as client, server instantly believes 126 players have joined:
A PLAYER JOINED THE SERVER! - 126 players online
Exception in main(): [Errno 24] Too many open files
I need some help setting this up for a Forge server. Thanks.
Currently all connection messages just say that someone wanted to connect to 127.0.0.1:25565 or in other words localhost.
This is the way the script communicates with the MC server, but for the user it would be more useful to know the IP address the script uses to communicate with the clients.
Maybe this should be added in the logging messages or perhaps even replace the 127.0.0.1:25565.
I've been running the 4.0 Version of the vanilla server hibernation script for about 2-3 weeks with no problems. Tonight I restarted my Ubuntu machine to come back to the error "OSError: [Errno 98] Address already in use." I'm not sure that this error entails so I'm asking here. The weird thing is that despite this error message, players can still join my server. Any suggestions or fixes? Thanks. I attached the error in the terminal window
I feel like this could be really useful for server panels that don't support this feature. The main one I can think of is Crafty Controller. Its a very barebones panel, but it is missing a hibernation feature.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.