For aspiring Raspberry Pi programmers looking to host their own Minecraft server, getting it to launch automatically upon boot can seem like a daunting task. This guide will walk you through the process, combining the power of screen for interactive control and systemd for seamless background execution.
Prepare Your Minecraft Server: Download Forge: Get the required Forge version (1.12.2 in your case) from the official website.Create a .sh Script: This script will simplify starting your server. Save the following code as minecraft.sh in your server directory:#!/bin/bash screen -S mcserver -dm java -Xms1024M -Xmx2048M -jar /home/pi/MinecraftServer/server/forge-1.12.2-14.23.5.2854.jar nogui
Make the script executable: Use chmod +x minecraft.sh.
Create Your systemd Unit: Create a new file called mcserver.service in /etc/systemd/system with the following content: [Unit] Description=Minecraft Server [Service] Type=forking ExecStart=/home/pi/MinecraftServer/server/minecraft.sh [Install] WantedBy=multi-user.target
Enable and Start the Service: Enable the service for automatic startup at boot: systemctl enable mcserver.service
Start the service immediately: systemctl start mcserver.service
Verify the Service: Check the service status: systemctl status mcserver.service
You should see a message indicating the service is "active (running)" and "Main PID" referencing the screen process.
Accessing the Server: List Running Screens: screen -list
You should see a screen session named mcserver. Connect to the Screen: screen -r mcserver
You'll be connected to the Minecraft server terminal, ready to run commands.
Log Files: Consider setting up log files to monitor your server's activity and troubleshoot issues.Firewall: Adjust your firewall rules to allow incoming connections to the Minecraft server port.Security: Implement security measures to protect your server from unauthorized access.
0 comments:
Post a Comment