How to Reliably Run a Minecraft Server on OCI Using Systemd for Auto-Restarts

 

In this guide, we will build on the previous tutorial for setting up a modded Minecraft server on Oracle Cloud Infrastructure (OCI). You will learn how to configure your Minecraft server to run as a systemd service, ensuring it starts automatically at boot and restarts in case of crashes.


Step 1: Verify Your Server Setup

Before proceeding, ensure that:

  1. You have completed the basic setup of a Minecraft server on OCI as outlined in the previous guide.
  2. The Minecraft server files are located in ~/minecraft and can be started with the command:
    java -Xmx8G -Xms8G -jar forge-*.jar nogui
    
    Replace 8G with your desired RAM allocation.

Step 2: Create a Systemd Service File

  1. Open a terminal and switch to the root user:

    sudo su
    
  2. Navigate to the systemd configuration directory:

    cd /etc/systemd/system
    
  3. Create a new service file for your Minecraft server:

    nano minecraft.service
    
  4. Add the following configuration to the file:

    [Unit]
    Description=Minecraft Server
    After=network.target
    
    [Service]
    User=ubuntu
    WorkingDirectory=/home/ubuntu/minecraft
    ExecStart=/usr/bin/java -Xmx8G -Xms8G -jar forge-*.jar nogui
    Restart=always
    RestartSec=10
    StandardOutput=append:/home/ubuntu/minecraft/server.log
    StandardError=append:/home/ubuntu/minecraft/server.log
    
    [Install]
    WantedBy=multi-user.target
    
    • Replace ubuntu with the username of the user running the server.
    • Adjust the -Xmx and -Xms values to match your server's resources.
  5. Save and exit the file by pressing Ctrl+O, Enter, and Ctrl+X.


Step 3: Reload Systemd and Enable the Service

  1. Reload the systemd daemon to recognize the new service:
    systemctl daemon-reload
    
  2. Enable the Minecraft service to start at boot:
    systemctl enable minecraft.service
    
  3. Start the Minecraft service:
    systemctl start minecraft.service
    
  4. Check the service status to ensure it is running:
    systemctl status minecraft.service
    
    You should see output indicating that the service is active and running.

Step 4: Configure Firewall for Automatic Restarts

If you have not already configured the firewall for port 25565 (Minecraft’s default port), ensure the rule is set in your OCI Console:

  1. Go to Networking > Virtual Cloud Networks in the OCI Console.
  2. Select the VCN and then the Subnet.
  3. Under Security Lists, confirm that an ingress rule exists for:
    • Source CIDR: 0.0.0.0/0
    • Destination Port Range: 25565
    • Protocol: TCP

Step 5: Test the Service

  1. Stop the service to simulate a crash:
    systemctl stop minecraft.service
    
  2. Wait for a few seconds and verify that the service restarts automatically:
    systemctl status minecraft.service
    
  3. You can also check the log file for restart activity:
    tail -f /home/ubuntu/minecraft/server.log
    

Step 6: Update and Manage Your Service

  • To Restart the Service Manually:

    systemctl restart minecraft.service
    
  • To Disable the Service from Starting at Boot:

    systemctl disable minecraft.service
    
  • To Edit the Service File:

    nano /etc/systemd/system/minecraft.service
    

    After editing, always reload the systemd daemon:

    systemctl daemon-reload
    
  • To View Logs:

    journalctl -u minecraft.service
    

Now your Minecraft server is configured to run as a systemd service. It will automatically start on boot, restart after crashes, and log its output to server.log for easy debugging.

Comments

Popular posts from this blog

Is Docker Still Relevant in 2025? A Practical Guide to Modern Containerization

Going In With Rust: The Interview Prep Guide for the Brave (or the Mad)

Becoming an AI Developer Without the Math PhD: A Practical Journey into LLMs, Agents, and Real-World Tools