A systemd service runs your Minecraft server in the background as a managed Linux service. This means you can start, stop, restart, check logs, and enable it on boot with systemctl instead of leaving the server running in an SSH window.

This guide is for a Linux VPS where you already have SSH access and a Minecraft server jar. If you have not installed Java or downloaded a Minecraft server jar yet, do that first, then come back to this guide.

In the examples below, the Minecraft server folder is /home/minecraft/server and the jar file is named server.jar. Change those paths if your server uses a different folder or jar name.

  1. Create a dedicated Linux user for the Minecraft server. Running the server as its own user is safer than running it as root.
    sudo useradd -m -r -s /bin/bash minecraft
    sudo mkdir -p /home/minecraft/server
    sudo chown -R minecraft:minecraft /home/minecraft/server
  2. Upload or download your Minecraft server jar into /home/minecraft/server. The folder should contain the jar and, after the first manual run, files such as eula.txt, server.properties, logs, and the world folder.

    Linux terminal showing example Minecraft server folder contents

  3. Accept the Minecraft EULA after you have read it. Minecraft will not start properly until eula.txt contains eula=true.
    sudo -u minecraft nano /home/minecraft/server/eula.txt
  4. Create a start script. This keeps the Java command in one place, so the systemd service can run the same command every time.
    sudo nano /home/minecraft/server/start.sh

    Use a command like this, adjusting the RAM and jar name for your server:

    #!/bin/bash
    cd /home/minecraft/server
    exec java -Xms2G -Xmx4G -jar server.jar nogui

    -Xms is the starting RAM allocation. -Xmx is the maximum RAM allocation. Do not set -Xmx to all VPS memory; leave RAM for Linux, Java overhead, SSH, backups, and other services.

    Linux terminal showing a Minecraft start.sh script

  5. Make the start script executable and owned by the Minecraft user.
    sudo chmod +x /home/minecraft/server/start.sh
    sudo chown minecraft:minecraft /home/minecraft/server/start.sh
  6. Test the start script manually before creating the service. Stop it with stop from the Minecraft console or press Ctrl+C after confirming it starts.
    sudo -u minecraft /home/minecraft/server/start.sh

    If this manual test fails, fix the error before continuing. A systemd service will not fix a broken Java command, missing jar, wrong path, or unaccepted EULA.

  7. Create the systemd service file.
    sudo nano /etc/systemd/system/minecraft.service
    [Unit]
    Description=Minecraft Server
    After=network.target
    
    [Service]
    User=minecraft
    WorkingDirectory=/home/minecraft/server
    ExecStart=/home/minecraft/server/start.sh
    Restart=on-failure
    RestartSec=10
    
    [Install]
    WantedBy=multi-user.target

    User tells Linux which account runs the server. WorkingDirectory is the Minecraft folder. ExecStart is the script systemd runs. Restart=on-failure restarts the service if it crashes.

    Linux terminal showing a Minecraft systemd service file

  8. Reload systemd so it sees the new service file.
    sudo systemctl daemon-reload
  9. Start the Minecraft service and check its status.
    sudo systemctl start minecraft
    sudo systemctl status minecraft --no-pager

    Linux terminal showing systemctl status for a Minecraft service

  10. Enable the service on boot once you are happy it starts correctly.
    sudo systemctl enable minecraft
  11. Open the Minecraft port in your firewall if you use one. The default Java Edition port is 25565 TCP.
    sudo ufw allow 25565/tcp

    On AlmaLinux, Rocky Linux, Oracle Linux, or CentOS with firewalld, use:

    sudo firewall-cmd --permanent --add-port=25565/tcp
    sudo firewall-cmd --reload

 

Useful service commands

CommandWhat it does
sudo systemctl start minecraftStarts the Minecraft service.
sudo systemctl stop minecraftStops the Minecraft service.
sudo systemctl restart minecraftRestarts the Minecraft service.
sudo systemctl status minecraft --no-pagerShows whether the service is running or failed.
sudo journalctl -u minecraft -fFollows the live service log.
sudo systemctl disable minecraftStops the service starting automatically on boot.

 

Troubleshooting

ProblemWhat to check
Service fails immediatelyCheck the jar file name, ExecStart path, Java install, and eula.txt.
Players cannot connectCheck the server is running, port 25565 is open, and server.properties has the right port.
Server runs out of memoryLower -Xmx, reduce view distance, remove heavy mods, or upgrade RAM.
Changes are not applyingRestart the service after editing server.properties or replacing the jar.

Take a backup before replacing the jar, changing worlds, editing important config files, or updating a modded server.

  • 0 Utilizadores acharam útil
Esta resposta foi útil?

Artigos Relacionados

How to connect to a Linux VPS with SSH

SSH is the normal way to manage a Linux VPS. It gives you a terminal on the server so you can...

How to update packages on a Linux VPS

Keeping packages updated helps patch security issues and keeps server tools compatible. Run...

How to create a sudo user on a Linux VPS

A sudo user lets you manage a Linux VPS without logging in as root for every task. This is safer...

How to secure SSH on a Linux VPS

SSH is the main way to manage a Linux VPS, so it should be secured before the server is used for...

How to check disk usage on a Linux VPS

Disk usage issues can stop updates, backups, logs, databases, and game saves from writing...