Monday, September 15, 2014

Disposable minecraft servers in a flash with Vagrant

Minecraft Vagrant


Disposable Minecraft Servers

Minecraft is a game where you run around punching blocks and building stuff with your imagination, basically like legos for boys and girls born in the 21st century.
Vagrant is a virtualization service for creating disposable dev environments. Now the two of them are together for running easy, shareable minecraft servers.

What does this do

This is a hands-off, automated minecraft server builder. You can clone this repo on any machine that has vagrant installed to have a minecraft server up and running in minutes.
You can run vagrant up on your windows, linux, or mac machine and have a minecraft server running in a compartmentalized virtual server. When you run vagrant destroy the virtual machine is destroyed but your persistent data is kept in persistent_data.

Why

Initially I created this vagrant config so I could quickly and easily test mods. Just start the vagrant instance and do whatever you want. If you break something or decide you don't want to use that mod any longer, simply destroy the image and the persistent data and start it again. It will be just like new.
Backing up and restoring your minecraft server is very easy, since all of your data -- including the information necessary for running the server -- is contained in just a few files and folders. You can even copy the entire directory over to a new server and run it there.
Lastly, I bet there are parents out there who want to run minecraft servers for their children. This let's you do this easily from just about any platform without having to configure anything.

Running the server

First install Vagrant if you haven't already done that.
Next clone the repo:
git clone git@github.com:stephen-mw/vagrant_minecraft_auto_launch.git
Pop into the vagrant server and run vagrant up
cd vagrant_minecraft_auto_launch
vagrant up
The server will bootstrap and install everything it needs to run minecraft. It will also start the service automatically for you.
After the initial bootstrap you can run vagrant ssh to go into the server. You'll be greated with a MOTD with some helpful information:
WELCOME TO MINECRAFT!

To stop, start, restart or check the status of the the minecraft server
process, simply run:

  $ service minecraft <stop|start|restart|status>

The runtime logs are available at /opt/minecraft/logs

To change the min or max server memory values, make the change in:

  /etc/init/minecraft.conf

And then restart the server proces.

Status of minecraft server:

minecraft start/running, process 2344

Have fun!

Under the hood

The server will launch an Ubuntu 12.04 image that will download and install everything you need to run minecraft automatically. It will also start the service and take care of logs. Everything related to your server will be in persistent_data and that folder will survive the destruction and creation of these vagrant instances.
After the installation completes, you and others will be able to connect to your server at your host's ip address. That means if you launch the vagrant instance on a laptop that has the ip address of 192.168.0.101, then you can connect to the server at the same address (regardless of what your guest ip address is).
The instance itself doesn't need to be destroyed between runs. You can also halt it. Either way, when you bring it back online it should be running the server.

How to get it

Sunday, September 14, 2014

Minecraft server upstart script

I see a lot of people running minecraft server in strange ways: nohup, bg & disown, tmux, screen, etc. The problem with those options is that they are all ephemeral. If you restart your server you'll need to do it all over again.

Here's a simple upstart script that starts and watches your minecraft server. It runs as a service and works for centos 6.5+ and ubuntu 12.04+

Once you create the file at /etc/init/minecraft.conf, simply run:

initctl reload-configuration
service minecraft <start|stop|status>

upstart script:
# Minecraft upstart script

start on (local-filesystems and net-device-up IFACE!=lo)
stop on [!12345]

respawn

chdir SOME_MINECRAFT_DIRECTORY

exec java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.jar nogui

Logs for the server will be rotated by the server and are available at /var/log/upstart/minecraft.log

Monday, July 28, 2014

ec2list -- quickly and easily list ec2 instances across all accounts and regions

Here's a quick tool I cooked up after working in with multiple AWS accounts in many regions. Sometimes I just need a particular piece of information about a host and I only had its instance id. Before this script I would have to run multiple aws calls in different regions until I found the instance.

The script itself is a wrapper around the aws cli tools. It will gather a list of instances in all accounts you specify and in all of the regions. It's multithreaded and I find it finishes in about 4 to 5 seconds. You'll get better performance if you comment out regions that you're not using.

Just clone the repo and execute.

Usage

usage: ec2list [-h] [-i INSTANCES] [-v] [-a] [-f FILTER]

optional arguments:
  -h, --help            show this help message and exit
  -i INSTANCES, --instances INSTANCES
                        Comma-separated list of instances to filter results.
  -v, --verbose         Print all host metadata.
  -a, --all             List all hosts, even those that aren't running.
  -f FILTER, --filter FILTER
                        key value filters to pass directly to command. Eg:
                        Name=instance-type,Value=m1.small

Prerequisites

You must have a $HOME/.aws/config file setup with the proper credentials.
An example profile:
[profile production]
aws_access_key_id=AKIAFOO
aws_secret_access_key=grzOgbar
region=us-west-1

[profile staging]
aws_access_key_id=AKIAIFOO
aws_secret_access_key=BAYS232bar
region=us-west-1
You can test that the different profiles are active by running the aws cli tool
aws ec2 describe-instances --profile=production
aws ec2 describe-instances --profile=staging

Listing all instances in a succinct manner.

The columns when run this way will always be predictable (unlike -v). Useful if you're using awk or other things.
$ ./list
i-7e15d971 stephen_test_001 10.0.0.100 54.183.84.15 m3.large production
i-7e15d971 stephen_test_002 10.0.0.100 54.183.84.16 m3.large staging
...

List instances that are also stopped

By default only running instances will be shown. Use the -a or --all flag to show all instances, even those that are stopped.
$ ./list -a

Be verbose 

Verbose prints everything returned by ec2. The return values are unordered.
./list -v
i-7e15d971:
  Monitoring: {"State": "disabled"}
  PublicDnsName: ec2-54-131-88-95.us-west-2.compute.amazonaws.com
  RootDeviceType: ebs
  State: {"Code": 16, "Name": "running"}
  EbsOptimized: False
  ...
i-bba5d6e6:
  Monitoring: {"State": "disabled"}
  PublicDnsName: ec2-54-210-162-78.us-west-1.compute.amazonaws.com
  RootDeviceType: ebs
  State: {"Code": 16, "Name": "running"}
  EbsOptimized: False
  ...

Filter by a list of instance IDs

To easily filter instances by instance id, they can be passed as a comma-separated list with the -i or --instances flag.
./list -i i-bba5d6e6,i-cad1b0c2,i-afa406f2

Print only instances that are an m1.small, or other things

Note that the filters arg allows you to pass filters down directory to the underlying aws ec2 command. See the ec2 api for information on the types of filtering you can do.
$ ./list -f Name=instance-type,Values=m1.small

Thursday, May 8, 2014

Converting NMEA latitude and longitude coordinates to degrees decimal for use in google maps

I've been tinkering around with my GlobalSat bu-353 USB gps receiver lately. Initially I was confused about the coordinates I received from the device. I mapped them in google maps and it showed my location in the middle of the pacific ocean. Do I really live in the plastic bag vortex in the pacific??

After some googling I realized I wasn't using the correct formula to convert the lat/long NMEA-specified format to decimal degrees acceptable to google maps.

According to the specs, NMEA specifies latitude as ddmm.mmmm and longitude as dddmm.mmmm. To convert these to decimal degrees, we need to simply divide the minute (mm.mmmm) by 60.

(d)dd + (mm.mmmm / 60)

The first "d" is optional and only pertains to longitudinal coordinates.

Plotting these coordinates in google maps is easy. Just use the following URL:

http://maps.google.com/maps?q=<latitude>,<longitude>

Friday, February 14, 2014

Move over upstart and make way for systemd

Earlier this week the Debian technical committee voted to make systemd the default init system for Debian. It was a nail-biter to follow, and it essentially came down to a tie-breaker vote cast by Bdale Garbee.

The result is clear: systemd will be the default init system for Debian -- and also Ubuntu -- going forward.

Mark Shuttleworth of Canonical confirmed Ubuntu's decision to follow suit in a blog post called "Losing Graciously". No drama, no attempt to revote or repeal the vote.

If only politics worked that smoothly.

Now it's time to familiarize yourself with systemd. I recommend you start writing all future init scripts in systemd.

The time frame for obsolescence of upstart and sysVinit is unclear for Ubuntu, but I predict around 7 years, so you have time to migrate.

Here's how I got that number (remember that odd number of releases are 2 year support):

13.04 is already out and obviously not part of the decision
14.04 is too far into the development stages
15.04 nobody will use because it's not "true" LTS
16.04: the only logical next release to enforce this decision.

I'll be writing more about systemd in the future. First I'm going to begin my own conversation from upstart so I can figure out how to use the dang thing. I'm glad that now I can write a service that will work across multiple distros.

Saturday, January 25, 2014

Zabbix Server 2.2 with Percona 5.6 Auto Install on Ubuntu



Here's an easy-install for Zabbix server 2.2 running on Percona 5.6.


Zabbix is an enterprise monitoring tool. I've been using it for about two years and find it decent, though it does have shortfalls (especially when dealing with aggregate metrics). If you're dealing with less than two or three hundred hosts, then I think Zabbix is a great tool.

Percona is a high performance mysql fork. This auto-install will download the Zabbix source code and compile it. This is the easiest way I can find to installing Zabbix server without using legacy mysql software.

If you're looking for high-performance metric aggregation, then may I suggest the venerable OpenTSDB or the tried-and-true graphite? These tools can be easily integrated with Zabbix via their respective APIs.

How to install

Simply clone the repo and run:

./bootstrap

Requirements

There are a few things that are assumed. The first is that you don't have apache running or installed. If you do then beware this will nuke your default site vhost and overwrite it with a Zabbix specific one. It also assumes you don't have mysql installed.

As always you should inspect the code before running it on your system. Enjoy and let me know if you have any issues.

Wednesday, January 22, 2014

UDP only rsyslog server and client on Ubuntu

The first thing you'll need to do is install a new version of rsyslog. There's a bug in the version that comes along with Ubuntu 12.04 that prevents rsyslog from listening on a privileged port if you're using drop-privileges. You can read instructions for installing a newer version of rsyslog here. Once you've done that, open up /etc/rsyslog.conf and uncomment the following lines:

#$ModLoad imudp
#$UDPServerRun 514

Restart rsyslog and you're done on the server. Now head over to a client and open up /etc/rsyslog.d/50-default.conf and make the following addition to the top of the file:

*.* @your_server:514

Note that the single @ sign is what designates the sending to UDP only. Restart rsyslog on the server and you can test to see if logs are being sent using the logger command:

logger -t TEST testing