[Mongrel] versioning of win32 versus ruby gems

Ezra Zygmuntowicz ezmobius at gmail.com
Thu Dec 21 16:28:01 EST 2006

On Dec 21, 2006, at 11:13 AM, Charles Brian Quinn wrote:
> Thanks Steven,
> This is using Jamis' net/ssh library and using:
> sudo cmd do |channel, stream, data|
>        data.each_line do | line |
> to regex match lines and type in input.  this could work, but i was
> hoping for bash or something simpler....
> Guess that means it's time to move my all of my shell scripts over to
> ruby (except for the one that installs ruby) ;-)
> Thanks!


	You and me both. I didn't want to spend the time writing bash  
scripts for this when I need to do it on tons of machines anyway. So  
the script he linked to is actually a capistrano plugin. Take the  
file and put it somewhere in your load path and then require it from  
a capistrano recipe file and then you can use it like this:

require 'cap_gem'

task :install_gems, :roles => :app do
   gem.select 'mongrel' , 'http://mongrel.rubyforge.org/releases'
   gem.install 'mongrel',  'http://mongrel.rubyforge.org/releases' ,  

select will select the most recent versions for the current platform  
and install it. install will install a specific version but won't  
auto select from a menu. So is there are two or more versions of a  
gem then you want to use select.

Here is the more current version of the plugin for cap. This one  
supports the --source option.

require 'rubygems'
require 'capistrano'
# Installs within Capistrano as the plugin _gem_.
# Prefix all calls to the library with <tt>gem.</tt>
# Manages installing gems and versioned gems.
module Gem

   # Default install command
   # * doesn't install documentation
   # * installs all required dependencies automatically.
   GEM_INSTALL="gem install -y --no-rdoc"

   # Upgrade the *gem* system to the latest version. Runs via *sudo*
   def update_system
     sudo "gem update --system"

   # Updates all the installed gems to the latest version. Runs via  
   # Don't use this command if any of the gems require a version  
   def upgrade
     sudo "gem update --no-rdoc"

   # Removes old versions of gems from installation area.
   def cleanup
     sudo "gem cleanup"

   # Installs the gems detailed in +packages+, selecting version  
+version+ if
   # specified.
   # +packages+ can be a single string or an array of strings.
   def install(packages, source=nil, version=nil)
     sudo "#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} # 
{source ? '--source='+source : nil } #{packages.to_a.join(' ')}"

   def uninstall(package)
     sudo "gem uninstall #{package}" do |channel, stream, data|
       data.each_line do |line|
         if line =~ /\[Yn\]/
           channel.send_data "Y\n"

   # Auto selects a gem from a list and installs it.
   # *gem* has no mechanism on the command line of disambiguating  
builds for
   # different platforms, and instead asks the user. This method has  
the necessary
   # conversation to select the +version+ relevant to +platform+ (or  
the one nearest
   # the top of the list if you don't specify +version+).
   def select(package, source=nil, version=nil, platform='ruby')
     cmd="#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} # 
{package} #{source ? '--source='+source : nil }"
     sudo cmd do |channel, stream, data|
       data.each_line do | line |
     case line
     when /\s(\d+).*\(#{platform}\)/
       if selections[channel[:host]].nil?
         logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
     when /\s\d+\./
       # Discard other selections from data stream
     when /^>/
       channel.send_data selections[channel[:host]]
       logger.debug line, "#{stream} :: #{channel[:host]}"
       logger.info line, "#{stream} :: #{channel[:host]}"


Capistrano.plugin :gem, Gem

-- Ezra Zygmuntowicz-- Lead Rails Evangelist
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)

More information about the Mongrel-users mailing list