Score:0

Minecraft server not loading server.properties when it's loaded as a service

cn flag

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 [email protected] 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.target

If there's any other data needed I'll be happy to provide it. Thanks in advance.

in flag
Where is the server properties file and is it accessible by the `minecraft` user account?
VALOS avatar
cn flag
@matigo Yeah, it is accessible. It's owned by the minecraft user account, the entire server folder is. I start the server with the java command on the minecraft account as well, and it has no problems loading server.properties when I do it that way instead of the systemctl start minecraft@ishikawa-aof3
Score:0
cn flag

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
VALOS avatar
cn flag
I tried this with the following code: ```#!/bin/bash cd /opt/minecraft-servers/ishikawa-aof3/ MEM="-Xms4G -Xmx12G" JAVA=/usr/bin/java $JAVA $MEM -jar serverstarter-2.0.1.jar nogui ``` and it errored when I tried starting the service. However, when I start the script normally with sudo start.sh it did launch the server.
VALOS avatar
cn flag
EDIT: I tried again and it seems to work now. Gonna reboot the server and hope that it still works and loads the server config. Note: **I just tried it and it doesn't load the config. Both not normally, and upon reboot.**
VALOS avatar
cn flag
**UPDATE:** I'm not exactly sure what I changed, but it seems to be working now. Will have to further test it once I'm home, thank you for the help!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.