Configure Minecraft Server with Upstart on Ubuntu 12.04


This post is in the category: Guides

Posts here are mostly step-by-step guides on how to replicate something I have set up in the past. Read over my About page to see how I show commands/output and read the disclaimer.


How to configure a Minecraft server with backups and upstart compatibility.

I use bukkit for the user and service names. Keep in mind though that this will work with Bukkit, vanilla Minecraft, or any of the major modded versions.

Base OS Install

Install/Deploy Ubuntu 12.04 Server. Configure SSH access, system level backups, etc. We will configure a separate backup for the Minecraft folder later.

Extra Software Packages

Install some required software.

[root]$ apt-get install openjdk-7-jre screen rdiff-backup

Create bukkit User

[root]$ useradd -m -s /bin/bash bukkit

Create a password.

[root]$ passwd bukkit

Configure bukkit Service

[root]$ cd /etc/init
[root]$ wget http://wellsie.net/files/349/bukkit.conf

This file contains a newline character. If you accidentally delete ^M, replace it with the actual newline character. In vim, this can be done by pressing CTRL+V and CTRL+M in sequence.

We want the bukkit user to handle the upstart commands, so let’s give them sudo rights to it.

[root]$ vim /etc/sudoers.d/bukkit

Add this:

bukkit ALL=(ALL) NOPASSWD:/usr/sbin/service bukkit stop
bukkit ALL=(ALL) NOPASSWD:/usr/sbin/service bukkit start

Fix the permissions.

[root]$ chmod 0440 /etc/sudoers.d/bukkit

Minecraft Server Setup

Log in as bukkit.

Create some directories.

[bukkit]$ cd ~
[bukkit]$ mkdir {minecraft,mcbackup,scripts}

minecraft – Holds minecraft.jar, plugins, etc – mcbackup – Holds local incremental backups for the minecraft folder – scripts – Currently I only have the backup script in here. I used to have start/stop scripts here as well before Upstart took over that task

Speaking of that backup script, here it is:

[bukkit]$ cd ~/scripts
[bukkit]$ wget http://wellsie.net/files/349/mcbackup.sh
[bukkit]$ chmod +x mcbackup.sh

Bring it up and read over what it does.

[bukkit]$ vim mcbackup.sh

The most important thing to note is that the script disables level saving during the backup process. This is to prevent files from changing in the middle of a backup. Also note that 7 days of incremental backups are retained.

Running the backup hourly is a good idea, especially if you are running several plugins that cause instability, worry about griefers, etc.

[bukkit]$ crontab -e

Add this:

@hourly /home/bukkit/scripts/mcbackup.sh

Now it’s time to install the binary. If you are sticking with vanilla Minecraft, download the server jar file here. To put it on the server in one step, run this.

[bukkit]$ cd ~/minecraft
[bukkit]$ wget https://s3.amazonaws.com/Minecraft.Download/versions/1.7.2/minecraft_server.1.7.2.jar

But remember, the Upstart script is expecting minecraft_server.jar. I like to create a symlink to the versioned jar file so I can keep the old binary when upgrading.

[bukkit]$ ln -s minecraft_server.1.7.2.jar minecraft_server.jar

Test Our Setup

Try to start the service.

[bukkit]$ sudo service bukkit start
bukkit start/running, process 31402

Wait a few seconds to see if it is still running.

[bukkit]$ service bukkit status
bukkit start/running, process 31402

Success! If you want to interact with the console, run this.

[bukkit]$ screen -rx

Press CRTL+A and then D to exit the screen session and leave the server running. Refer to the screen manual page for additional options.

Once the Minecraft server is started for the first time, several additional files are created.

[bukkit]$ tree /home/bukkit/minecraft
/home/bukkit/minecraft
├── banned-ips.txt
├── banned-players.txt
├── logs
│   ├── 2013-11-26-1.log.gz
│   └── latest.log
├── minecraft_server.1.7.2.jar
├── minecraft_server.jar -> minecraft_server.1.7.2.jar
├── ops.txt
├── server.properties
├── white-list.txt
└── world
    ├── data
    │   ├── Mineshaft.dat
    │   └── villages.dat
    ├── DIM1
    ├── DIM-1
    ├── level.dat
    ├── level.dat_old
    ├── players
    ├── region
    │   ├── r.0.-1.mca
    │   ├── r.0.-2.mca
    │   ├── r.1.-1.mca
    │   └── r.1.-2.mca
    └── session.lock

Now would be a good time to test the backup.

[bukkit]$ ~/scripts/mcbackup.sh
Fatal Error: Bad directory /home/bukkit/mcbackup.
It doesn't appear to be an rdiff-backup destination dir

Yeah, it threw an error message. That’s just because we were looking for expired backups on an empty directory. Run it again it it makes you feel better.

[bukkit]$ ~/scripts/mcbackup.sh
No increments older than Tue Nov 19 14:36:10 2013 found, exiting.

Yay. If you were in-game at the time, you should see that message in the screen stating that the backup has started.

Conclusion

Your server is now configured and ready to go! Don’t forget that the backups we configured only protects the application. This does not protect from a server crash. Configure your system backups accordingly.

This entry was posted in Guides and tagged on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

8 thoughts on “Configure Minecraft Server with Upstart on Ubuntu 12.04

  1. Marcel

    Thanks for your nice wiki guide.
    Still I’m missing something because I can’t start the service.
    I did “ln -s” the conf file in /etc/init, but when I want to start the service I get the response:
    start: Unknown job: bukkit
    the file /var/run/bukkit.pid is not created

    Starting manually:
    screen -S minecraft -D -m java -Xincgc -Xmx1024M -jar minecraft_server.jar
    is working correct…
    Do I need something to do in /etc/init.d?

    For your information I’m running Ubuntu 13.10 and not 12.04LTS

    Thanks, Marcel

    Reply
    1. Andrew Wells Post author

      Hi Marcel – please make sure that the upstart file is saved and with the correct permissions.

      [user]$ ls -alh /etc/init/bukkit.conf
      

      Should look like this:

      -rw-r--r-- 1 root root 508 Nov 26 12:15 /etc/init/bukkit.conf
      

      If not, run this:

      [root]$ chmod 0440 /etc/sudoers.d/bukkit
      

      Also make sure the file content matches the file at http://wellsie.net/files/349/bukkit.conf

      I spun up a VM today running Ubuntu 13.10 and was able to follow through the guide, so it doesn’t seem to be a difference between the two OS versions.

      Let me know how that works out.

      Reply
      1. Marcel

        I’ve tried it on 100% the same as your tutorial, same files and permissions:
        Unable to start the job. So the job is found, due to file permissions. But still unable to execute. I’ve changed the start script to the minimum:
        start on runlevel [2345]
        stop on runlevel [016]

        pre-start script
        echo $$ > /var/run/bukkit.pid
        end script

        post-stop script
        rm /var/run/bukkit.pid
        end script
        Now the service will start and stop. Something weird found the file is:
        /var/run/bukkit.pid^M
        (i’m working with nano as linux editor. Can that be the ^M(CR or LF) problem?)

        Sorry for the bad make-up, but i’m not familiar with your wiki for make up code boxing.
        I’m also running VmWare ESXI on my home server and this VM is dedicated for the bukkit server. I want to run multiple bukkit servers, because my youngest sun want to play different mods and worlds, but that’s the next challenge. This server going to connect to my main VM with samba file server and lots more. That part is already functioning, but skipped at the moment to get the bukkit up and running with exactly your guidance and I can easily reinstall this bukkit server VM. Once again a night spend on Ubuntu 😉

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *