Persistent Data Between Sandbox Environments | Torque

Persistent Data Between Sandbox Environments


Our previous blogs addressed how to use Torque to setup a Minecraft Server and troubleshoot the sandbox environment where the Minecraft Server exists.  At the end of the last blog, we discussed how to save the Minecraft Server state manually.

Saving the Minecraft Serve state manually is difficult to do every time we destroy a sandbox environment. It would be ideal if we could restore the Minecraft world you created once you’ve created a new sandbox. And, voila, you can

For this, we’ll create another “application” within our Minecraft environment that allows you to save your world and restore it with just a few mouse clicks. Notice the start and init scripts referenced in the application blueprint; these are the requisite steps to deploy and launch the application. Let’s get into it…

Artifacts: Inputs for our application blueprint

To manage our Minecraft Server, I created a Python Flask script that exposes API endpoints, which we can use to retrieve a zip of our world. (And if we already have one, we can use the same app and its restore API endpoint to restore the world to the newly created sandbox.

We will need the application binaries (called mcadminconsole) while setting up our Minecraft server. In previous blogs, I used curl to get the Minecraft binary I needed. However, in production, you would not want your sandbox creation to depend on a link outside of your control.  Torque provides a section to define your artifact:

  1. Go to Settings
  2. Click the Repositories tab
  3. Click the Add repository button
  4. Select (for my example) your S3 bucket

Within my S3 bucket, I dir structure and binary. I created the binary for my mcadmin python/flask app (artifacts/minecraft/):

To allow the blueprint to pull artifacts, I must define it in my blueprint YAML file:

artifacts:   – mcadminconsole: ‘artifacts/minecraft/’

The above allows the Artifact location is available to my Application, defined in my application YAML. The Application YAML has an init and a startup script.

configuration:  start:    script:  initialization:    script:

The init script sets up the application, which is unzipping and installing the python script and html for the python/flask app:


echo ‘=============== init script for mcadminconsole UI ===============’

# save all env for debugging

printenv > /var/log/torque-vars-“$(basename “$BASH_SOURCE” .sh)”.txt


echo ‘=============== Get artifact and unzip  ===============’

echo ‘==> Extract artifact to /tmp/’

mkdir $ARTIFACTS_PATH/drop

unzip -o $ARTIFACTS_PATH/ -d /tmp/

The startup script starts the application, which is a web app viewable from within the sandbox’s dashboard.

#!/bin/bashecho ‘=============== Staring script for mcadminconsole UI ===============’# save all env for debuggingprintenv > /var/log/torque-vars-“$(basename “$BASH_SOURCE” .sh)”.txtcd /tmppython3

If you click on the mcadminconsole app link, it will say, “Hello World.”

However, the above is your base URL for the following endpoints:

  • /saveMCworld – backs up your Minecraft world and allows you to save it as a zip locally before you destroy the sandbox.
  • /stopMCworld – stops the Minecraft server; purely a helper method.
  • /form (which performs a PUT to /uploadMCworld) – We upload our previously saved zip here from another sandbox environment.
  • /restoreMCworld – will stop the Minecraft server (using /stopMCworld), restore the Minecraft world based on the zip you uploaded, and then restart the Minecraft server.

Workflow for Saving and Restoring your Minecraft server

Saving your Minecraft world

  1. Setup Torque to work with your cloud account and , detailed in part 1 of this blog post.
  2. Instantiate the Minecraft blueprint (covered in part 1). After Torque emails you that it’s complete, you can grab the IP from the Sandbox Summary Tab’s Quick Link section.
  3. Invite others to connect to your Minecraft server and craft away!
  4. When done, open a browser tab and use the following endpoint to create a backup of your Minecraft world: http://<ip_of_mcadminconsole>/saveMCworld.
  5. Shut down the sandbox to reduce costs and resources.

Restoring your Minecraft world

  1. Instantiate the Minecraft blueprint (also covered in part 1). After Torque emails you that it’s complete, you can grab the IP from the Sandbox Summary Tab’s Quick Link section.
  2. Open another browser tab and send your restore file to the Minecraft server using the following endpoint: http://<ip_of_mcadminconsole>/form.
  3. Restore the world using the following endpoint: http://<ip_of_mcadminconsole>/restoreMCworld
  4. Re-connect to your Minecraft server with your client and continue crafting away where you left off!


Parting Thoughts

I hope you had fun following and now have a glimpse of what you can accomplish with Torque.

P.S. My python code was very hacky. For example, I didn’t error check for a valid zip file when I ran the /restoreMCworld api endpoint.  Please feel free to send me pull requests to improve it!