Ubuntu 20.04 Minecraft Server Setup - LinuxConfig.org

I copied this into the systemd script, which I’m pasting below. Then below it what happens when I try to shutdown minecraft with the “sudo systemctl stop minecraft@survival”. Then everytime I do a “status” check after the shutdown my console doesn’t seem to understand what’s going on. It doesn’t stop minecraft at all until I reboot the server.

[Unit]
Description=Minecraft Server: %i
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/%i

User=**********
Group=*********

Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say SERVER WILL SHUT DOWN IN 30 SECONDS. MAKE SURE YOU ARE IN A SAFE SPOT! SAVING ALL MAPS…”\015’
ExecStop=/bin/sleep 20
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say SERVER SHUTTING DOWN IN 10 SECONDS. YOU BETTER HURRY UP NOW! SAVING ALL MAPS…”\015’
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say 5…”\015’
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say 4…”\015’
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say 3…”\015’
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say 2…”\015’
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “say 1…”\015’
ExecStop=/bin/sleep 1
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “save-all”\015’
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “stop”\015’

[Install]
WantedBy=multi-user.target

*********@linuxserver:~$ sudo systemctl status minecraft@survival
● minecraft@survival.service - Minecraft Server: survival
Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2021-02-02 14:27:08 UTC; 1min 30s ago
Main PID: 5079 (screen)
Tasks: 35 (limit: 9290)
Memory: 2.3G
CGroup: /system.slice/system-minecraft.slice/minecraft@survival.service
├─5079 /usr/bin/SCREEN -DmS mc-survival /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui
└─5080 /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui

Feb 02 14:27:08 linuxserver systemd[1]: Started Minecraft Server: survival.
*********@linuxserver:~ sudo systemctl stop minecraft@survival *********@linuxserver:~ sudo systemctl status minecraft@survival
● minecraft@survival.service - Minecraft Server: survival
Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-02-02 14:33:36 UTC; 12s ago
Process: 5079 ExecStart=/usr/bin/screen -DmS mc-survival /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui (>
Process: 5891 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff "say SERVER WILL SHUT DOWN IN 30 SECON>
Process: 5892 ExecStop=/bin/sleep 20 (code=exited, status=0/SUCCESS)
Process: 5916 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff "say SERVER SHUTTING DOWN IN 10 SECOND>
Process: 5917 ExecStop=/bin/sleep 5 (code=exited, status=0/SUCCESS)
Process: 5923 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “say 5…”^M (code=exited, status=0/SU>
Process: 5924 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 5926 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “say 4…”^M (code=exited, status=0/SU>
Process: 5927 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 5930 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “say 3…”^M (code=exited, status=0/SU>
Process: 5931 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 5933 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “say 2…”^M (code=exited, status=0/SU>
Process: 5934 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 5936 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “say 1…”^M (code=exited, status=0/SU>
Process: 5937 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 5939 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “save-all”^M (code=exited, status=0/SU>
Process: 5940 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “stop”^M (code=exited, status=0/SUCCES>
Main PID: 5079 (code=exited, status=1/FAILURE)

Feb 02 14:27:08 linuxserver systemd[1]: Started Minecraft Server: survival.
Feb 02 14:33:03 linuxserver systemd[1]: Stopping Minecraft Server: survival…
Feb 02 14:33:33 linuxserver systemd[1]: minecraft@survival.service: Main process exited, code=exited, status=1/FAIL>
Feb 02 14:33:36 linuxserver systemd[1]: minecraft@survival.service: Failed with result ‘exit-code’.
Feb 02 14:33:36 linuxserver systemd[1]: Stopped Minecraft Server: survival.
lines 1-27/27 (END)

Hi Thencguy,

Welcome to our forums.

I would suggest commenting out all the “ExecStop” lines in your systemd unit file except for the last one, and check if the problem persists.

I commented out all but the last “ExecStop” and this was the result:
Feb 03 01:53:51 linuxserver systemd[1]: Started Minecraft Server: survival.
Feb 09 14:24:39 linuxserver systemd[1]: Stopping Minecraft Server: survival…
Feb 09 14:24:40 linuxserver systemd[1]: minecraft@survival.service: Main process exited, code=exited, status=1/FAILURE
Feb 09 14:24:43 linuxserver systemd[1]: minecraft@survival.service: Failed with result ‘exit-code’.
Feb 09 14:24:43 linuxserver systemd[1]: Stopped Minecraft Server: survival.
scott@linuxserver:/opt/minecraft/survival$ sudo systemctl status minecraft@survival
● minecraft@survival.service - Minecraft Server: survival
Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-02-09 14:24:43 UTC; 52s ago
Process: 4087 ExecStart=/usr/bin/screen -DmS mc-survival /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui (code=exited, status=1/FAILURE)
Process: 964456 ExecStop=/usr/bin/screen -p 0 -S mc-survival -X eval stuff “stop”^M (code=exited, status=0/SUCCESS)
Main PID: 4087 (code=exited, status=1/FAILURE)

Feb 03 01:53:51 linuxserver systemd[1]: Started Minecraft Server: survival.
Feb 09 14:24:39 linuxserver systemd[1]: Stopping Minecraft Server: survival…
Feb 09 14:24:40 linuxserver systemd[1]: minecraft@survival.service: Main process exited, code=exited, status=1/FAILURE
Feb 09 14:24:43 linuxserver systemd[1]: minecraft@survival.service: Failed with result ‘exit-code’.
Feb 09 14:24:43 linuxserver systemd[1]: Stopped Minecraft Server: survival.

On my screen it highlights the ^M after the “stop”, this probably means something.

Did you copy-pasted the unit file’s content from the browser? If so, check for any additional characters at the end of the lines that may be interpreted wrongly. I would suggest midnight commander’s editor that shows them visually.

Hi is there a way to turn online mode to false and if yes how?

It only showed CR and LF at the end of each line. I tried deleting these and it just put text lines as continuous lines. So I it doesn’t appear to have anything extra.

you can change that by editing the server.properties file. You have to stop the server before it allows editing.

Try to remove the last few characters of the stop command, so your line ends like the original:

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval ‘stuff “stop”5’

I commented out my only ExecStop line and retyped it manually as you suggested and it get the same error as before. Failed with result ‘exit-code’

As a side note, it will allow me to “restart” the minecraft server and the status looks fine. I’m about to give up on this install and try another method, my server is already corrupted to the point they can’t interact with certain objects.

Hi. i am pretty new. I wanted to ask if it is possible to start a forge server with that? When yes how? i tried changing the name in the .service file but it doesn’t want to work.
Please help!

Hi, I have made a server like shown above, but how do I update it to 1.17?

I know its a bit old now, really good guide/setup though. Just one thing re failed exit-code errors people are getting (I also had this…). Try running manually with the following:

$ sudo su - minecraft
$ cd /opt/minecraft/survival
$ java -Xms1024M -Xmx4G -jar minecraft_server.jar

I get error java.lang.UnsupportedClassVersionError… blah blah, basically, server.jar was compiled using a later jdk than the one installed of version 11 ($ java -version). I just installed latest jdk from oracle JDK 16.0.1 then changed that to be the default jdk. This now works fine!.

Hope it helps someone out there…