Tag: Minecraft

CanaryMod as Virtual Machine in Azure

CanaryMod is a wrapper around MineCraft which provides an extension framework. The framework provides a stable API as well as extended permission and group management. The extensions in Minecraft/CanaryMod is called mods and my reason to use CanaryMod was to make use of two mods called ScriptCraft and RaspberryJuice. These two mods make it easy to run scripts or make your own mods in the supported scripting lanuage. ScriptCraft supports JavaScript and RaspberryJuice supports python using the same API as the MineCraft PI version.

Creating the Server in Azure
Azure is Microsofts cloud platform containing different services for running applications, and collecting/visualizing data. In this case we will only use it as a server host running our virtual machine. In Azure it is possible to choose among different OS templates published by companies or open source community. First thought was to use an Ubuntu OS template, and then install java, open up ports, create start/stop scripts etc. However, since Microsoft bought Mojang (creator of Minecraft), they are providing a Minecraft Server themselves using Ubuntu (quite a change in business strategy nowadays – signed Satya Nadella). So at second thought, let’s use this preconfigured server and just reconfigure it for CanaryMod to save time!

Step by step creating the server:

First create or use an existing account at portal.azure.com.

Search for the Minecraft Server published by Microsoft:

Create a virtual machine instance in the Azure cloud containing the Minecraft server. Choose a hostname (hint: use some uncommon name otherwise you will end up with a name containing your name and some long id provided by microsoft). Choose a username and password for your user at the server (hint: choose an uncommon username to make it harder to guess). We will use ssh later on to connect to the server and then we will make use of the username/password.

The final step is to press create a wait for like 5-10 minutes while the server is created:

Finally the server is created and running:

In Microsoft Azure it is possible to inspect the server and remap ports (endpoints). Let’s do that for the our virtual machine:

As expected there two ports open, minecraft and ssh. The ssh is using the default port and as a security step we will change it to high private port number e.g. 59592 (49152–65535) :

Try it out by using ssh (if windows use the Chocolately package manager to install ssh – see this former blog post).

> ssh -p @.cloudapp.net

Now your are into your Ubuntu virtual machine  – verify that minecraft server is running by

> ps -efw | grep java

You should see something like – i.e. the running process:
/usr/bin/java -Xms1024m -Xmx1024m -jar
As a last security thing – assure that the system is updated (sudo is running as root temporary):

sudo apt-get update

Installing CanaryMod
Now we are ready to begin the installation of Canarymod!
First of all stop the process running official minecraft by calling the systemctl scripts:

> sudo systemctl stop minecraft-server

Create the Canarymod directory side by side of the official minecraft directory and make the minecraft user owner of the directory:

> cd /srv
> sudo mkdir canarymod_server
> sudo chown minecraft canarymod_server
> cd canarymod_server

Download Canarymod and run it for the first time to create all necessary files:

> sudo wget https://canarymod.net/releases/CanaryMod-1.8.0-1.2.0-RC1.jar
> sudo chown minecraft CanaryMod-1.8.0-1.2.0-RC1.jar
> sudo -u minecraft java -jar CanaryMod-1.8.0-1.2.0-RC1.jar
....logging from canarymod....
> > shutdown
....logging from canarymod - save/stop server....

Confirm the End-User License Agreement (EULA) by setting it to true in the nano texteditor:

> sudo -u minecraft nano eula.txt

Restart the CanaryMod process and make your minecraft user operator (use the uuid – get it by using this link) in the command console. The command console is entered right after the server has started and preceded by ‘> >’.

sudo -u minecraft java -jar CanaryMod-1.8.0-1.2.0-RC1.jar
....logging from canarymod....
> > /op 
> > shutdown
....logging from canarymod - save/stop server....

Next step is to change the system control script ran at startup/shutdown of the virtual machine, instead of starting the official minecraft they shall start Canarymod. The system control script of minecraft is called minecraft-server.service and the only thing needed to be changed is the directory path and the name of the .jar file.

> cd /etc/systemd/system
> sudo nano minecraft-server.service
change all /srv/minecraft_server to /srv/canarymod_server
change the .jar to CanaryMod-1.8.0-1.2.0-RC1.jar
remove Alias in [Install]

Once the system control script is changed, it has be verified that it does what it is supposed to do.
First make sure it is started each time the server is started by enabling it.

> sudo systemctl enable minecraft-server
> sudo shutdown -r now

Reconnect once again and verify that the process is running – see last part of  ‘Creating the server in Azure’.

Installing ScriptCraft

One of the reasons of choosing CanaryMod was to be able to run mods in javascript, to aid in constructing large buildings and as an introduction into programming. ScriptCraft is installed as a plugin of CanaryMod – made in just a few steps:

cd /srv/canarymod_server/plugins
> sudo wget http://scriptcraftjs.org/download/latest/scriptcraft-3.1.12/scriptcraft.jar
> sudo chown minecraft scriptcraft.jar

Verify that it is installed correctly by trying the simplest possible javascript code in the console window.

> sudo systemctl stop minecraft-server
> sudo -u minecraft java -jar CanaryMod-1.8.0-1.2.0-RC1.jar
....logging from canarymod....
> js 1+1
.... canarymod is logging '2' as a result ....

Trying it all out
Ready for prime time? Connecting to the CanaryMod server in Azure….