2010 ski movie trailers

Trailers for the 2010 ski movies are starting to land! Here’s what I’ve found so far:

Level 1 Productions – Eye Trip

Matchstick Productions – The Way I See It

Poor Boyz Productions – Revolver.

Teton Gravity Research – Light the Wick

Warren Miller – Session #61

Posted in Skiing | Tagged | Leave a comment

Dynamic hosts file using Chef

There are a number of ways to setup your infrastructure so that you can refer to machines by hostname. I currently prefer the “dynamically generated hosts file” approach because it’s simple to understand and setting up a DNS server is intimidating (as well as a single point of failure).

Shlomo Swidler has a great article comparing different DNS configurations as well as some sample code for dynamically updating hosts files. However, if you’re already using Chef you can achieve the same thing with a very simple cookbook.

First, create a new cookbook:

$ cd chef-repo/
$ rake new_cookbook COOKBOOK=hosts CB_PREFIX=site-

Place the following in site-cookbooks/hosts/recipes/default.rb:

# Find all nodes, sorting by Chef ID so their
# order doesn't change between runs.
hosts = search(:node, "*:*", "X_CHEF_id_CHEF_X asc")
 
template "/etc/hosts" do
  source "hosts.erb"
  owner "root"
  group "root"
  mode 0644
  variables(
    :hosts => hosts,
    :fqdn => node[:fqdn],
    :hostname => node[:hostname]
  )
end

Then create the template, site-cookbooks/hosts/templates/default/hosts.erb:

127.0.0.1   localhost
 
<% @hosts.keys.sort.each do |fqdn| %>
<%= @hosts[fqdn][:ipaddress] %> <%= fqdn %> <%= @hosts[fqdn][:hostname] %>
<% end %>
 
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Add the recipe to your node’s run_list and run chef-client and your /etc/hosts should contain all the Chef nodes on your network. Note that one downside to this approach is that updates will be slow (since chef-client only runs every 30 minutes by default).

Now what if you wanted to point at a specific service, like having chef.example.com point at your Chef master? Just search for it in your recipe (and add it to the variables list):

chef_server = search(:node, 'run_list:recipe\[chef\:\:server\]')

And add a line to the template:

# Chef master server
<%= @chef_server[:ipaddress] %> chef.example.com

Sure beats setting up a DNS server!

Posted in Tech | Tagged , , , , , | 1 Comment

Redis plugin for collectd

Last weekend I wrote a small collectd plugin for monitoring Redis and put it on GitHub: http://github.com/powdahound/redis-collectd-plugin.

If you haven’t heard of Redis before, it’s a key-value store similar to memcached with support for more complex data types like lists, sets, and hashes. collectd is a stats collection daemon which recently added support for plugins written in Python. This is great because there’s no way I’d write a plugin in C! Anyway, you can use this plugin to collect data about your Redis server like number of active connections, database size, commands processed per second, and memory usage. You can then use a tool like drraw to generate nice graphs:

More info and installation instructions on the GitHub page.

Posted in Tech | Tagged , , , , , | Leave a comment

Tricky Apache configuration bug

When using Apache’s DirectoryIndex directive make sure you don’t separate the values with commas. If you do, Apache will be looking for filenames ending in commas!

# Incorrect
DirectoryIndex index.html, index.php, index.cgi
 
# Correct
DirectoryIndex index.html index.php index.cgi
Posted in Tech | Tagged | Leave a comment

Colorize log output with ack

Adding color to log files makes them a lot easier to understand, especially when tailing them. That’s why tools like MultiTail were created, and some logging tools can output in color. Last night I realized color could be added to any log file using ack, an awesome grep replacement that I recently found.

For example, to make 404s red in a standard Apache access log:

$ tail -f /var/log/apache2/access.log \
  | ack --passthru --color-match=red "^.* 404 .*$"

The --passthru option makes it so no lines are discarded. You can use multiple colors by piping the output through ack multiple times. The --flush option is needed to prevent pipe buffering issues and the --color option is needed to pass colors through. Here’s an example:

$ tail -f /var/log/apache2/access.log \
  | ack --flush --passthru --color --color-match=green "^.* 200 .*" \
  | ack --flush --passthru --color --color-match=yellow "^.* 302 .*" \
  | ack --flush --passthru --color --color-match=red "^.* 404 .*"

Apache access log colored with ack

You can use more complex colors like --color="white on_red" to make errors stand out even more.

I wonder what other cool things ack can do…

Note: You could also do this with perl, but it looks a lot less maintainable.

Posted in Tech | Tagged , , | Leave a comment