In Valid Logic

Endlessly expanding technology

Using server aliases with Capistrano output

One thing we often run into without deploys is “what server is that executing on?” After updating code, we actually a fairly elaborate process to remove servers from load balancing, restart, wait for load to drop off, then add it back in to load balancing. We also just use the AWS hostnames rather than our own since our server list pretty much changes weekly. Wouldn’t it be nice to have the ouptut show “app10” instead of “ec2-123-123-123-123.compute-1.amazonaws.com”.

Luckily adding an alias to Capistrano is pretty easy!

 1 class Capistrano::ServerDefinition
 2   def to_s
 3     @to_s ||= begin
 4       s = @options[:alias] || host
 5       s = "#{user}@#{s}" if user
 6       s = "#{s}:#{port}" if port && port != 22
 7       s
 8     end
 9   end
10 end

Simply add that to your deploy.rb, or another file that is included with your recipes for utility methods. It works simply by overriding the ServerDefinition.to_s method, which is used for the logger output. The only change to the default method is line 4.

Then for your role definitions:

role :app, 'ec2-123-123-123-123.compute-1.amazonaws.com', :alias => 'app10'

Then you see much better output:

 ** [out :: app10] Alive

Thursday, July 15, 2010

 
blog comments powered by Disqus