jump to navigation

Rake tasks :through Capistrano January 27, 2008

Posted by John Dewey in Capistrano, Example, Rake.
1 comment so far

Executing Rake tasks on host(s) through Capistrano is nothing new, and there are quite a few ways to do it. Some of the configurations out there, use a common Capistrano task to execute all Rake tasks. This works quite well, but you run into problems when scoping tasks to specific roles. The common Rake exec task is not scoped to a specific role (because it could run any task on any given role), so if you call it from a Cap task scoped to :db, it will still execute across all roles.

This was corrected by creating a Rake exec method instead of a Cap task. The method can pass any arbitrary variables and/or Rakefile to Rake.An example Capistrano task, displays it’s usage. There are a few Cap variables already set, such as rake and rails_env. Using the rakefile variable allows the execution of a specific Rakefile, which comes in handy when wanting to ignore the Rails Rakefile.

Why ignore the Rails Rakefile? In our configuration the Rakefile loads environment.rb, which sets the load_paths to our custom rubygems path – that means loading Rails! What happens when Rails is not installed, and you need a bootstrap task. The ability to pass in a Rakefile all of the sudden becomes useful.

Multi-App Mongrel Cluster Init Script January 22, 2008

Posted by John Dewey in Capistrano, Configuration, Deployment, Mongrel, Rails.

I found the mongrel_cluster.sh script, everyone uses — doesn’t quite cut it.   Especially, when a system may host several RoR applications.  Why, you ask?  The ability to easily control, and dynamically discover applications is missing.  In most cases, this doesn’t matter.  Especially when the applications are deployed with Capistrano, since it is leveraged for various tasks (including stop, starts, and restarts).

The SAs on the other hand, usually do not use Capistrano (they should!), or have a recent version of the app checked out.  Having a standard init script across all your applications and servers becomes useful.

You get bonus points for dynamically discovering new application installs.We can make certain assumptions in our environment.

We use Capistrano, apps run as the same user,  live under the same base directory, and link to common Subversion Rake tasks.  That enables the use of a generic Rake task to control all RoR applications. Furthermore, the Rake task can be wrapped by a system init script for use under /etc/init.d/.

Patching Sake for hidden tasks January 18, 2008

Posted by John Dewey in Rake, Sake.
add a comment

Rake will “hide” tasks from ‘rake -T’ when a description is missing from an associated task. This behavior is was missing from Sake until today.  I recently submitted a patch to Sake, which Chris applied to version (1.0.12).

To display all installed tasks, run ‘sake -Tv’, otherwise Sake will hide tasks without a description.

Use ActiveResource to Consume Simple Objects Over REST January 16, 2008

Posted by reidmix in ActiveResource, Code, Example, Rails.
add a comment

I’m sure that many organizations have services available via REST that are not produced by Rails and do not follow Rails conventions. That doesn’t mean you have to write your own client. For simple objects, use ActiveResource.

To take advantage of ActiveResource in this way use the ActiveResource::Base#find method. You need to find(:all), find(:first), or find(:one) but you need to pass a string of the path to the :from option along with any :params you need. If you pass a symbol as the :from option, this will not work and will employ all of the the ActiveResource::Base mechanics. A string will bypass this, for example:

class RestClient < ActiveResource::Base
  self.site = "http://java-based-service.company.com"

  def self.invoke(params = {})
    find(:one, :from => "/nonconventional/path/to/rest/service/", :params => params)

object = RestClient.invoke(:irregular_id => 10) #=> service returns <data><name>reid</name><role>blogger</role></data>
object.name #=> reid
object.role #=> blogger

Advanced Rails Recipes Contribution January 6, 2008

Posted by John Dewey in Capistrano, Configuration.

Giles and I had our contributions selected for the upcoming Advanced Rais Recipes Book — pretty cool!


Scrape mongrel status from Apache’s mod_proxy_balancer January 4, 2008

Posted by John Dewey in Apache, Capistrano, Code, Command Line, Configuration, Example, Rails, Rake, WebServers.
1 comment so far

Access to Apache’s load balancer manager (mod_proxy_balancer) is typically protected.  Rather than maintaining an ever changing list of ACLs or configuring HTTP authentication, I wrote a simple scraper Rake task.

This task is bundled with all of our rails applications as a svn external, and included in our common Capistrano tasks.This task is a quick and dirty solution to checking the status of your Mongrels.

Feel free to modify, and provide a pastie.http://pastie.caboo.se/135223

P.S. The SAs can plug this into their monitoring software as well.