SRE/Software Engineer hybrid

Self-hosted Minecraft Realms

Self-hosted Minecraft Realms

Running a Minecraft server is something I've found myself doing a ridiculous amount of times. Sometimes I'm able to get a few people to hop on and play for a bit, but usually, it doesn't last very long. Every time I've gone through one of these "phases" of creating a Minecraft server I've generally ended up spinning up a Cloud VM (performance, yo) and then tearing it down, only to have interest in playing on that same map months after I'd already nuked the VM to save money.

A while back, during perhaps my 100th run of a Minecraft server, I had noticed that Minecraft Realms existed. This seemed really cool, but I wasn't a fan of the cost. Unfortunately, I primarily play only modded Minecraft, which this did not support either. Somewhat surprisingly there seemed to be no projects out there that supported either, so I set to work on my own solution called minecraft-preempt (named after the preemptible machines that GCP offers)

How It Works

minecraft-preempt works by acting as, essentially, a Minecraft proxy. Using the amazing github.com/tnze/go-mc I was able to quickly spin up a Minecraft proxy. Added on top of this is player activity detection, using basic socket count tracking. When the number of users hits 0, the target VM is stopped. When a server attempts to join, the instance status is checked, if it's offline then it's started and the user is disconnected informing them that the server is coming online. Using GCP's shared machines, with this, can bring down the cost of a Minecraft server (when not used) from hundreds of dollars to just $5 a month.

Running It

Running minecraft-preempt is super simple, simply create a config.yaml file:

# Which cloud driver to use
cloud: gcp
cloudConfig:
  gcp:
    # ID of your instance
    instanceID: my-instance-id

    # GCP Project
    project: my-project

    # GCP Zone
    zone: us-west1-b
server:
  # Hostname/IP of the VM that runs Minecraft
  hostname: 127.0.0.1
  # Port Minecraft is running on on the VM
  port: 25565

  # Get from here: https://wiki.vg/Protocol_History
  protocolVersion: 578
  textVersion: 1.15.2

Once you have created this file, download a release or compile a build of minecraft-preempt yourself. Run minecraft-preempt and you'll have a proxy running at 0.0.0.0:25565! You can now point your Minecraft client at that machine. Below are some pictures of what this looks like!

Connecting to the minecraft-preempt instance triggers a start instance operation
Server shows as being online after a connection
We're in!

The Future

Currently, the only cloud supported is gcp and a testing driver docker for local development. In the future, we'd like to bring support for more cloud providers, and better handling of Minecraft versions. Currently, new binaries need to be created using different versions of tnze/go-mc to support Minecraft versions


Want emails when I post?

No spam, no sharing to third party. Only you and me.

Member discussion