Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set up a Minecraft server System 10.8

Hereís a recipe for setting up Minecraft server on OS X. Since I donít fully trust the server not to have some security hole, I want it to run as user nobody so it doesnít have a lot of permissions. And I also want it to restart automatically when I reboot the computer. Finally I show how to backup the worlds you create.

Thereís three parts to this hint.

1) creating the launchDaemon that starts the minecraft server.
2) how to turn it on and off
3) maintaining backups

The first step is to download the minecraft server jar file from the Mojang website. Currently that site is https://minecraft.net/download but that might change in the future. And currently the jar filename is: minecraft_server.1.6.2.jar, but that will change too.

1) Creating a place for it. When you run the jar the first time itís going to create a lot of files and subdirectories the in the current working directory (CWD) so we want to create a nice place to do this. It doesnít matter where this it, but the permissions on the folder do matter. I put mine in /opt

sudo -s -
mkdir -p /opt/minecraft_server/state

Now if your user name is bob then move the minecraft jar into place:

mv /User/bob/Downloads/minecraft_server.1.6.2.jar /opt/minecraft

and make sure the top level folder and executable are owned by root. This will assure that no one can change the jar file without root access. Since the system is going to invoke this file automatically you donít want it changing with simple user level permissions.

chown -R root:wheel /opt/minecraft<em>server
chmod -R a+xr  /opt/minecraft</em>server

Minecraft is going to run as user nobody, and it will need permission to modify the state folder contents.

chown nobody /opt/state
chmod 755 /opt/state

2) Creating the launch daemon:

As root, create the file

/Library/LaunchDaemons/net.minecraft.plist

The file name is not important, but itís tradition to name the Daemon for website that it came from. You need to create this as root or otherwise assure itís owned by root:wheel and can be read. Itís not an executable.


<!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_server/state</string></p>

<pre><code>     &lt;key&gt;UserName&lt;/key&gt;
        &lt;string&gt;nobody&lt;/string&gt;

    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
            &lt;string&gt;/usr/bin/java&lt;/string&gt;
            &lt;string&gt;-Xmx1024M&lt;/string&gt;
    &lt;string&gt;-Xms1024M&lt;/string&gt;
    &lt;string&gt;-jar&lt;/string&gt;
    &lt;string&gt;/opt/minecraft_server/minecraft_server.1.6.2.jar&lt;/string&gt;
    &lt;string&gt;nogui&lt;/string&gt;
    &lt;/array&gt;
</code></pre>

<p></dict>
</plist>
The above is plist speak to tell it that it should change into the working directory where we want it to store its data, then launch the java jar with a memory size of 1G. You can adjust the values for your system if that turns out to be too much. It also tells it to run the job as the username nobody. And it will start the server when the Daemon is loaded, which happens either at boot time or if you explicitly tell the daemon to load.

The key thing here is that the paths to the ďstateĒ folder and the executable are hardcoded. You must change these paths if you set this up in a different place.

2) testing it. first make sure you have java installed. /usr/bin/java -version if java is installed then this will reply with the java version at that path. If itís not installed OSX will usually ask you if you want to install java and then automagically do this for you.

as root, (sudo -s -) run the following: launchctl load /Library/LaunchDaemons/net.minecraft.plist

test to see if it worked:

ps auxww | grep java | grep jar

does the output include something like this:


nobody          1405   0.5 10.8  3814720 681608   ??  Rs   Mon06PM  25:58.23 /usr/bin/javaÖ

If so then the server jar is running and is running as nobody.

If not then you made a mistake. To help diagnose this try running the command right from the command line.


cd /opt/minecraft<em>server/state
/usr/bin/java -Xmx1024M -Xms1024M -jar /opt/minecraft</em>server/minecraft_server.1.6.2.jar 
note, at this point you are running the server as root. This is reasonably safe, assuming you trust mojang, to do for a moment just to eliminate the permission issues. If you are nervous, disconnect your ethernet cable for a moment.

You may see some java exceptions printed in the process, but if the program stays running then itís working. Once it stops printing stuff out, type ctrl-c to kill it. List the current directory (state) and you will see a whole bunch of files and folders have been created. So now you know the program and the paths are right. Youíll need to find the error you made. Most likely a permissions issue.

2) controlling it. to load the server by hand:

sudo launchctl load /Library/LaunchDaemons/net.minecraft.plist

it will start when you load it the first time.

to stop the server temporarily

sudo launchctl stop net.minecraft

Here I used the name not the path. The name is one given in the plist file not the actual file name. Normally you want to make these the same for sanity sake. This command stops the server but it doesnít remove the autostart Daemonónext boot it will start again.

to restart it after stopping:

sudo launchctl start net.minecraft

to unload the daemon (so it wonít autostart at boot)

sudo launchctl unload  /Library/LaunchDaemons/net.minecraft.plist

If you edit the plist file, you need to stop the server and unload the daemon then (re)load the daemon. Otherwise it will ignore your edits till next reboot.

3) backing up the state. from time to time you may want to back up the state of your minecraft world and the server configuration (banned-IP, whitelist, configÖ)

To do that:


sudo -s -
cd /opt/minecraft_server
find ./state | sudo cpio -dpl <code>date "+%y%m%d-%H%M-minecraft"</code>

this command will create a snapshot backup of the state of your system. This will look like a copy off the state directory tree and files. But itís not a copy. Itís a hardlinked image. It doesnít actually occupy any (significant) disk space unless your world is changed. The command names the new snapshot for the date and time down to the hour.

You can restore an older image to being the current state by deleting the current state folder and moving the state folder from the image folder to the minecraft working directory.

Lex adds: I havenít tested this one.

    •    
  • Currently 2.27 / 5
  You rated: 1 / 5 (11 votes cast)
 
[14,732 views]  

Set up a Minecraft server | 4 comments | Create New Account
Click here to return to the 'Set up a Minecraft server' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set up a Minecraft server
Authored by: aol on Aug 22, '13 08:17:38AM

First, the Minecraft wiki (http://www.minecraftwiki.net/wiki/Create_a_Mac_OS_X_startup_daemon) has a great article that is very similar, but walks you through creating a dedicated _minecraft user and group. I don't know if I see much of a benefit of running as _minecraft or as nobody.

But second, the version of the article I read had a lot of encoding, stuff like <lt; instead of <. So folks using this hint, be careful to translate <lt; and <gt; to < and >. Stuff like <lt;string<gt; should actually be <string> in the plist file. Just FYI.

Finally, setting up the minecraft server is one thing, enabling port forwarding in your router so folks outside your network can get to your server is another. The default minecraft server port is 25565; there are general instructions at http://www.minecraftwiki.net/wiki/Setting_up_a_server#Port_forwarding.



[ Reply to This | # ]
Set up a Minecraft server
Authored by: SOX on Sep 11, '13 10:01:59AM

Hi, the tutorial you linked to is quite awful. The above method is significantly (massively) simpler, does not require a whole lot of ancillary scripts, actually gets the permissions right, explains how to control the daemon, and actually shows how to back it up. The formatting evidently got borked so I posted it in a reply below.



[ Reply to This | # ]
Please fix encoding of plist
Authored by: PatrickS on Aug 22, '13 11:00:34PM

Nice hint, but can you please fix the encoding of the plist snippet?



[ Reply to This | # ]
Set up a Minecraft server
Authored by: SOX on Sep 11, '13 09:51:22AM

The hint posting garbled my code segments. here's a cleaned up version

<!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>-Xmx1024M</string>
<string>-Xms1024M</string>
<string>-jar</string>
<string>/opt/minecraft_server.1.6.2.jar</string>
<string>nogui</string>
</array>

</dict>
</plist>



[ Reply to This | # ]