Minecraft server not loading server.properties when it's loaded as a service
Sophia Terry
I've followed many tutorials, but for some reason the service for my minecraft server won't read the server.properties file. I have a basic understanding of Ubuntu (had to learn how to use it for personal projects and college).
However, when I start it normally through the command line with the following command java -Xms4G -Xmx12G -jar serverstarter-2.0.1.jar nogui it does read the server properties file. I already checked if any other server.properties files exist on the system, and as far as I am aware there is only one on the system.
Is this a problem related to screen, or is there anything else I'm doing wrong?
My minecraft@.service file looks like this:
[Unit]
Description=Minecraft Server: %i
After=network.target
[Service]
WorkingDirectory=/opt/minecraft-servers/%i
User=minecraft
Group=minecraft
ProtectSystem=full
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
Restart=always
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xms4G -Xmx12G -jar serverstarter-2.0.1.jar nogui
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING ALL MAPS..."\015'
ExecStop=/bin/sleep 5
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.targetIf there's any other data needed I'll be happy to provide it. Thanks in advance.
21 Answer
Are you manually starting minecraft with the same user / group as in the service definition?
If you are, I would guess it's looking for server.properties in the wrong directory.
In your ExecStart, try adding a script that does the screen setup, but first changes dir to the correct dir where server.properties is located.
I have a few minecraft servers that I start from crontab @reboot.
/usr/bin/screen -dmS vanillamc /home/xxxx/minecraft/minecraft-1.17.sh
My script (you can adapt and send your dynamic working dir as input)
#!/bin/bash
cd /home/xxxx/minecraft/
MEM="-Xms1G -Xmx2G"
JAVA=/usr/lib/jvm/java-16-oracle/bin/java
$JAVA $MEM -jar minecraft_server-1.17.jar nogui 3