Skip to content

Instantly share code, notes, and snippets.

@steadystatic
Last active December 30, 2015 22:50
Show Gist options
  • Select an option

  • Save steadystatic/21c111d984baaa7c7ae6 to your computer and use it in GitHub Desktop.

Select an option

Save steadystatic/21c111d984baaa7c7ae6 to your computer and use it in GitHub Desktop.
On/Off DigitalOcean Image for my Minecraft server
#!/bin/sh
PATH=/usr/local/bin:/bin:/usr/bin
if [ "$1" = "on" ]; then
tugboat create mikecraft -i `tugboat images | grep "mikecraft" | awk -F: '{print $2}' | sed 's/,.*//'` -r3 -s63 && tugboat wait mikecraft -s active && tugboat password-reset mikecraft && yes | tugboat destroy_image _mikecraft
elif [ "$1" = "off" ]; then
tugboat halt mikecraft && tugboat wait -n mikecraft -s off && tugboat snapshot `/bin/date +%s`_mikecraft mikecraft && sleep 180 && yes | tugboat destroy mikecraft
else
echo 'Turn Mikecraft on or off?'
fi
@steadystatic
Copy link
Author

This is a lazy way to not pay all day hosting when no one is using my Minecraft server I run for my son and some friends. This script uses the awesome Tugboat and timestamps a snapshot of the VM before destroying the droplet (to avoid being charged for its uptime).

The next evening when a cron job runs this script, it's powered back on.

(Issues:)

Usage:

(This assumes you already have setup a DigitalOcean droplet with this name and have it all setup the way you want.)

mikecraft.sh (or put in /usr/local/bin/mikecraft just mikecraft)
gives “Turn Mikecraft on or off"

and mikecraft on gives:
create digital ocean image named "mikecraft" from latest snapshot named mikecraft in the san francisco region, sized 1gb...wait until its active and destroy the last snapshot image (to keep clean, avoid dupes which cause script errors)

and mikecraft off gives:
power down server named mikecraft, wait, take a snapshot now that its off, destroy the server

@steadystatic
Copy link
Author

Other fun:

  • Wired up /etc/rc.local to auto run 3 scripts dns.sh (sets the correct IP for minecraft server), desktop.sh and pocket.sh which start tmux sessions for the minecraft consoles for Desktop and Pocket edition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment