[SOLVED] Minecraft server as systemd service, server keeps closing, no logs being generated
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Minecraft server as systemd service, server keeps closing, no logs being generated
I'm following this guide on how to setup a Minecraft server to run as a systemd service. I finally (sorta) think I know what I'm doing now, since I'm new to systemd scripting. My problem is when "systemctl start minecraft@bukkit" is run, it will begin consuming resources, seen in htop, and then after a few seconds all the server stuff just closes. I went to go check the bukkit folder for logs, there are no logs to be found, nothing in ./logs/, nothing in ./crash-reports/.
Apr 01 18:11:19 ubuntu systemd[1]: Started Minecraft Server bukkit.
Apr 01 18:11:19 ubuntu screen[15687]: No screen session found.
Apr 01 18:11:19 ubuntu systemd[1]: minecraft@bukkit.service: Control process exited, code=exited status=1
Apr 01 18:11:19 ubuntu systemd[1]: minecraft@bukkit.service: Failed with result 'exit-code'.
Apr 01 18:12:19 ubuntu systemd[1]: minecraft@bukkit.service: Service hold-off time over, scheduling restart.
Apr 01 18:12:19 ubuntu systemd[1]: minecraft@bukkit.service: Scheduled restart job, restart counter is at 5.
It's an issue with the software screen, not screens.
Though I don't understand how it can be an issue with screen when it works OK when you start it from the CLI.
Dumb question maybe. Did you accept the terms in the eula file in the server folder? If it isn't accepted it will do this. Check the server folder for eula.txt and change false to true. Then try again. I'm not sure if this applies to bukkit as I've never used it. It does for vanilla.
This is the service I use. Along with a custom script it seems to do just fine. Fair bit less complicated. I'm not sure what most of those options mean on that service. But that is my own lack of knowledge to be honest and in no way saying it is wrong.
Dumb question maybe. Did you accept the terms in the eula file in the server folder? If it isn't accepted it will do this. Check the server folder for eula.txt and change false to true. Then try again. I'm not sure if this applies to bukkit as I've never used it. It does for vanilla.
This is the service I use. Along with a custom script it seems to do just fine. Fair bit less complicated. I'm not sure what most of those options mean on that service. But that is my own lack of knowledge to be honest and in no way saying it is wrong.
Actually after looking at yours and mine try adding
Code:
Type = forking
to the [Service] section.
That will also do it as the service just runs then dies without it.
I saved your script and modified it to my needs, though I hardly know a thing about bash scripting so I might of screwed up somewhere. https://pastebin.com/rjX7qGZJ
I made it executable, did systemctl start minecraft.service, got this error from journalctl -u minecraft.service. This time the server didn't even try to start. It couldn't locate java or the server directory, not sure why. In case it was a permissions thing I said heck with it and chmod ugo+rwx it, no difference.
And yes, I did accept the eula.txt, just like I would any server.
For your exec stop that mcstop command is a script i wrote so it won't apply to you at the moment. Also remove the ConditionHost line as that is for my environment only. I'm running my servers on an LTSP pxe chroot machine, and have multiple machines running the same image but only wanted one to do the minecraft servers. As far as the rest did you install the headless java jdk? I'm not sure regular java would work as it is for gui stuff. Only a guess though.
For your exec stop that mcstop command is a script i wrote so it won't apply to you at the moment. Also remove the ConditionHost line as that is for my environment only. I'm running my servers on an LTSP pxe chroot machine, and have multiple machines running the same image but only wanted one to do the minecraft servers. As far as the rest did you install the headless java jdk? I'm not sure regular java would work as it is for gui stuff. Only a guess though.
I # out those 2 lines you mentioned and we made progress, we now have a new error to figure out. I also made sure that java package was installed, and it is.
Code:
root@ubuntu:~# systemctl start minecraft.service
Job for minecraft.service failed because the control process exited with error code.
See "systemctl status minecraft.service" and "journalctl -xe" for details.
"screen[15741]: Error: Empty session-name?" seems like the main problem now, it's in both logs. That drew my attention to that "%i", what does it do/mean? I changed both instances of it to "bukkit", which is the name of the server folder, but it just threw the same screen error. I also change WorkingDirectory to /opt/minecraft/%i since I thought /opt/minecraft/bukkit/%i was wrong if "%i" represents the server folder.
Your error is back to a screen problem. If your exec start line doesn't look like mine exactly then it won't work. Empty session name means something is wrong there. The variable should be the screen session name.
Last edited by jmgibson1981; 04-03-2020 at 08:09 PM.
Your error is back to a screen problem. If your exec start line doesn't look like mine exactly then it won't work. Empty session name means something is wrong there. The variable should be the screen session name.
Nope, the service won't even start now. Again with the No such file or directory. I did create /minecraftservers and put the jar file in it, and renamed the jar file to server.jar. I'm expecting, if it will launch, that I'll have to sign the eula.txt true, since it's in a new directory.
Code:
root@ubuntu:/minecraftservers# systemctl start minecraft.service
Job for minecraft.service failed because the control process exited with error code.
See "systemctl status minecraft.service" and "journalctl -xe" for details.
root@ubuntu:/minecraftservers# systemctl status minecraft.service
● minecraft.service - Launch Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-04-03 21:21:01 CDT; 10s ago
Process: 1502 ExecStart=/usr/bin/screen -dmS /usr/bin/java -jar /minecraftservers/server.jar nogui (code=exited, status=200/CHDIR)
Apr 03 21:21:01 ubuntu systemd[1]: Starting Launch Minecraft Server...
Apr 03 21:21:01 ubuntu systemd[1502]: minecraft.service: Changing to the requested working directory failed: No such file or directory
Apr 03 21:21:01 ubuntu systemd[1502]: minecraft.service: Failed at step CHDIR spawning /usr/bin/screen: No such file or directory
Apr 03 21:21:01 ubuntu systemd[1]: minecraft.service: Control process exited, code=exited status=200
Apr 03 21:21:01 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.
Apr 03 21:21:01 ubuntu systemd[1]: Failed to start Launch Minecraft Server.
Another thing I tried was only changing the path to .jar in ExecStart while keeping everything else in that line the same as your script, I got the same error as above. Also I am making sure WorkingDirectory points to the right location each time I edit the script, with %i representing the server's directory.
Ok. I'm rewriting this post. I am sorry that I am only just now getting back to you. I have solved the issue as it hit me as well. It is due to some minor positioning errors in the script as well as a few Gotcha's! that I haven't dealt with in a few years. Here is a working service file. I ran this inside of an LXD container with 2 worlds at the same time. I suppose it would scale to as many as the hardware can handle.
This is set for the variables you provided in your first post, except for the location of the .jar file. That can be wherever you wish it, make sure to use a full path. I removed the parallel threads and xmx / xms because unless you are trying to restrict, they are pointless. Minecraft will use whatever is available and no longer requires either to use everything you've got. Add back in if you need to keep minecraft from taking all available cores / memory.
I never considered putting all of that stuff into the service file other than startup. I will be modifying my own setup to use just a service file for start and stop. I'll shrink my script to just do backups and that simplifies that. Thank you for posting this issue as it helped me simplify my own setup.
The above service file requires a couple things. These are most likely the original problem.
The target world folder must exist.
Once the world is started and fails, you must agree to the eula. You also MUST change the port number for that world in server properties file. It seems the server won't let another server run if the port numbers are the same. I don't recall these issues because I already had my worlds from a long time ago along with differing port numbers. Refresher I suppose. If you plan on running more than 1 server from the same IP then I would recommend that you start with the first one and get it on a different port than default. My 3 servers are in the 50k range so I have never had this issue before, at least as I can recall.
Enjoy your minecraft server{s}. I hope it works out for you. If I'm to late, I hope this is of use to someone.
Last edited by jmgibson1981; 04-12-2020 at 12:51 AM.
Enjoy your minecraft server{s}. I hope it works out for you.
I actually got help from someone else, this thread helped me a lot getting an understanding of systemd scripts. It turns out when we had a working script it was throwing errors because the minecraft user wasn't the owner of /opt/minecraft. I took notes of how I set it up, then used those notes to deploy the server on the real deal. Here's the file, I used my newly acquired skills to also set up a python SimpleHTTPServer script. I'm glad this thread could help, and thanks a lot for helping me learn about systemd scripts. I don't wanna change a thing in the script since the players are happy with the current setup.
PS. Don't make your root SSH password 123 and then port forward it, you'll get owned in the first 2 hours of deployment.
Yeah, I have also seen that there have been some problems with the Minecraft servers lately, but I have never experienced any of those problems while playing. I have been kicked out of a server, and no server has closed while I was playing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.