Deploying the Minecraft Charm!

Updated 2013/04/17: Reflect Charm Store, updated links, removed several out of date paragraphs.

 

For the past three weeks I’ve been working with Charms, which are part of the Juju project. I love charms, I even went so far as to join the Charmers group on Launchpad. During the Ubuntu Developer Summit I was lucky enough to sit down with a few of the Juju hackers and get a first hand look at developing an deploying charms. There are lots of videos showing how quick and easy it is to deploy Hadoop, WordPress, and MySQL to the cloud but those demos always just kind of sailed over my head, because I didn’t really care about that kind of infrastructure.

Juju!

So, you want to run a Minecraft server in the cloud. First you’ll need to grab juju – if you’re running the latest and greatest Ubuntu release then installation is a pretty straight forward process execute the following lines to add the Juju PPA and install Juju along with the additional charm tools.

sudo add-apt-repository ppa:juju/pkgs
sudo apt-get update && sudo apt-get install juju charm-tools

Finally, we need to setup an environment for which to deploy these charms to! Run juju once to have Juju create it’s environments file, which is placed in ~/.juju/environments.yaml Since I use Amazon’s Web Services (AWS) EC2, all I had to do was add two extra keys one for access-key and the other secret-key. These are the access and secret keys (respectively) from your Amazon Web Service account. All of this can be found in the documentation

Now you’re ready for some charming!

There are a whole bunch of directions you can go in now. You can pull down all the charms in the Charm Browser, you can checkout the list of charms that are still in development/awaiting approval, or you can just deploy the totally awesome Minecraft charm. Lets do that! You’ll need to setup the cloud for deployment. This is done via bootstrapping, which will create an instance on the cloud that acts as the gatekeeper and manager for all services and charms you deploy with Juju to the cloud.

juju bootstrap

Bootstrapping can take up to five minutes to complete and it runs in the background. So even though the command completed doesn’t always mean the environment is ready! You can check on the Juju environment anytime by issuing the juju status command. Output, when bootstrapping is completed, will look like this

2011-11-16 13:18:27,464 INFO Connecting to environment.
machines:
  0: {dns-name: ec2-50-19-58-136.compute-1.amazonaws.com, instance-id: i-45bdd926}
2011-11-16 13:18:28,408 INFO 'status' command finished successfully

So we’ve got one machine (our bootstrap!) and it’s all ready to rock and roll. So, lets deploy!

juju deploy minecraft

When that command completes, it’ll send a request to the bootstrap machine to spin up a minecraft service (just so you know, charms that are deployed are called services). It’s almost ready to rock and roll! Check on the machine periodically using the juju status command, eventually you’ll end up with the following:

2011-11-16 13:28:14,584 INFO Connecting to environment.
machines:
  0: {dns-name: ec2-50-19-58-136.compute-1.amazonaws.com, instance-id: i-45bdd926}
  1: {dns-name: ec2-50-17-53-192.compute-1.amazonaws.com, instance-id: i-fdb8dc9e}
services:
  minecraft:
    charm: local:oneiric/minecraft-1
    exposed: false
    relations: {}
    units:
      minecraft/0:
        machine: 1
        open-ports:
        public-address: ec2-50-17-53-192.compute-1.amazonaws.com
        relations: {}
        state: started
2011-11-16 13:28:15,711 INFO 'status' command finished successfully

As is shown, there are two machines now, bootstrap and the newly created minecraft machine. We have one service running, minecraft, and a bunch of other information, most importantly the state and public-address. As is shown, the machine is started! So everything went A-OK! All that needs to happen now: Expose the server to the outside world. Exposing simply opens the appropriate ports for a service, if required. In this case we want our server to be available to the rest of the world so they can play! You can do this by running

juju expose minecraft

Running juju status one more time will show that the Minecraft service is now exposed and ready to rock and roll

2011-11-16 13:32:18,630 INFO Connecting to environment.
machines:
  0: {dns-name: ec2-50-19-58-136.compute-1.amazonaws.com, instance-id: i-45bdd926}
  1: {dns-name: ec2-50-17-53-192.compute-1.amazonaws.com, instance-id: i-fdb8dc9e}
services:
  minecraft:
    charm: local:oneiric/minecraft-1
    exposed: true
    relations: {}
    units:
      minecraft/0:
        machine: 1
        open-ports: [25565/tcp]
        public-address: ec2-50-17-53-192.compute-1.amazonaws.com
        relations: {}
        state: started
2011-11-16 13:32:19,558 INFO 'status' command finished successfully

Now, the machine is available on port 25565 (the default port!) Try to connect and this is what you get:

I would have written this post sooner, but I was too busy “testing”

Now, I know what you’re thinking. “But Marco, I want to configure the server, now I have to log in and configure it.” Nope! Juju Charms are configurable! To get a list of configuration options just run juju get minecraft which should produce the following list

2011-11-16 13:31:06,718 INFO Connecting to environment.
charm: minecraft-1
service: minecraft
settings:
    allow-nether:
        description: Allow generation of the nether, true or false
        type: string
        value: 'True'
    difficulty:
        description: Level of complexity 1-5
        type: int
        value: 1
    level-name:
        description: Name of the level, will be generated if it doesn't exist
        type: string
        value: world
    max-players:
        description: Maximum players allowed on the server
        type: int
        value: 10
    motd:
        description: Message of the day displayed to users in the server list
        type: string
        value: Juju Powered Minecraft Server
    port:
        description: Port for which Minecraft runs upon
        type: int
        value: 25565
    spawn-animals:
        description: Generate animals, true or false
        type: string
        value: 'True'
    spawn-monsters:
        description: Generate monsters, true or false
        type: string
        value: 'True'
2011-11-16 13:31:07,473 INFO 'config_get' command finished successfully

At this point you can update the configuration at any time using juju set minecraft option=value option2=value [...] an example to change the maximum players and the MOTD would be

juju set minecraft motd="Juju I love you" max-players=5

And in no time flat you’ll see something like this

That about sums up getting started with launching Minecraft in Juju. It may seem like a lot but the majority of this was a one time setup. This is also just the tip of the iceburg when it comes to charms and Juju. I strongly recommend checking out their site and asking questions in the #juju room on freenode.

Tagged:

Leave A Comment?