
Well, Minecraft is a gigantic mess. Horibble piece of software. But kids love it, so I had to set up a server for them. Setting up the server is really easy, but there are no good instructions on how to set it up as a daemon on MacOS. The “official” page is really an absolute joke.
So, let’s get started. Execute the following as root.
Step 1. Create a folder to host your Minecraft server, say /opt/minecraft
mkdir /opt/minecraft
Step 2. Put your Minecraft server, world, settings … over there.
Step 3. Make nobody the owner for this directory and set the right permissions.
chown -R nobody /opt/minecraft
chmod -R 755 /opt/minecraft
Step 4. Create a Launch Daemon (this will allow your Minecraft server to start when your Mac starts).
vi /Library/LaunchDaemons/net.minecraft.plist
Paste the content below (adjust for your needs if required):
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.minecraft</string>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/opt/minecraft</string>
<key>UserName</key>
<string>nobody</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-Xmx4096M</string>
<string>-Xms4096M</string>
<string>-jar</string>
<string>/opt/minecraft_server.jar</string>
<string>nogui</string>
</array>
</dict>
</plist>
Step 5. Load the Launch Daemon and test it out:
sudo launchctl load /Library/LaunchDaemons/net.minecraft.plist
#
# test that the server is running
#
ps auxww | grep java | grep minecraft | grep nobody
nobody 82405 35.4 6.4 13275488 4310236 ?? Ss 5:53PM 16:59.56 /usr/bin/java -Xmx4096M -Xms4096M -jar /opt/minecraft/minecraft.jar nogui
Step 6. Done! Your server is now running and it will restart the next time you reboot your machine.
You can manually stop your server with:
sudo launchctl stop net.minecraft
Re-start it:
sudo launchctl start net.minecraft
And unload it (won’t start at the next boot anymore):
sudo launchctl unload /Library/LaunchDaemons/net.minecraft.plist
Not sure why it has to be so complicated…