[ANN] SwitchTower 1.0.1, SwitchTower Extensions


#1

SwitchTower is a utility that can execute commands in parallel on
multiple servers. It allows you to define tasks, which can include
commands that are executed on the servers. You can also define roles
for your servers, and then specify that certain tasks apply only to
certain roles.

Manual: http://manuals.rubyonrails.org/read/book/17
Project: http://rubyforge.org/projects/switchtower
Install: gem install switchtower

SwitchTower 1.0.1, coming hard on the heels of 1.0.0, fixes the
broken rakefile that was generated for rails applications. Nothing
else was changed.

In addition to SwitchTower 1.0.1, I’d also like to announce
SwitchTower Extensions 1.0.0, a collection of SwitchTower tasks and
methods for use in your own SwitchTower recipes. There are two tasks
provided by this library:

  • watch_load. Just run “switchtower -r config/deploy -a watch_load”
    and you’ll see a display of the current load (1/5/15) for each of
    your servers. The display updates every 30 seconds.

  • watch_requests. Run “switchtower -r config/deploy -a
    watch_requests” and you’ll see a display of the current requests/
    second of each of your application servers, as harvested from your
    application log, in real-time.

Mostly, this library is provided as an example of how to write
SwitchTower extensions, though some may find the tasks themselves
useful. You can install SwitchTower extensions either by downloading
from http://rubyforge.org/projects/switchtower, or by rubygems (gem
install switchtower-ext). Once installed, you simply need to put
“require ‘switchtower/ext/monitor’” in your deploy.rb and the tasks
will be available to you.

  • Jamis

#2

In addition to SwitchTower 1.0.1, I’d also like to announce SwitchTower
Extensions 1.0.0, a collection of SwitchTower tasks and methods for use
in your own SwitchTower recipes. There are two tasks provided by this
library:

Ah, very nice. Totally minor, and I know these are just examples, but I
found 3 small issues:

  1. headers doesn’t properly handle a machine name that is exactly 1 char
    less than the load width (it doesn’t pad, leaving staggered columns).

  2. hostnames are truncated if they contain dashes – i’m assuming the
    regex done is meant to grab the hostname from a fully-qualified name.

  3. on debian (at least) uptime reports "load average: " and not
    "averages: "

I can give you a patch if you’d like.


#3

Amazing…

Good job Jamis!

Mikkel B.

www.strongside.dk - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk - Buy Old Stuff!(DK)


#4

Hi Jamis

One feature which I think would be nice to be included with
Switchtower, which I currently implement using my own tasks, is
provision for copying a ready to go database.yml file into the config
folder of the new release.

Because you would typically only check in an example database.yml
file, the way I’ve set things up is to create the database.yml file I
need and store it in the shared folder on the remote server. I’ve then
created a task that copies the database.yml file from shared into the
new release once its been checked out.

I’d submit a patch but to be honest I’m still a rake novice and you
might be able to come up with something more elegant. Here is the code
I’m using if its of any use though:

desc “Copy configured database.yml to new current release”
task :copy_database_settings, :roles => :web do
run “cp #{deploy_to}/shared/database.yml
#{release_path}/config/database.yml”
end

task :after_deploy, :roles => :web do
copy_database_settings
end

The reason why I ask if it could be built in is because its typically
something you need to do with every project and its annoying to have
to copy the above into each new deploy file.

Great work with switchtower though, it truly is excellent.

On 2/22/06, Jamis B. removed_email_address@domain.invalid wrote:

  1. headers doesn’t properly handle a machine name that is exactly 1
    I can give you a patch if you’d like.

A patch would be wonderful! Thank-you, Michael.

  • Jamis

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Cheers,
Luke R.
www.lukeredpath.co.uk


#5

Luke,

I’ll definitely consider adding the copy_database_settings task to
the standard tasks, but I wouldn’t make it executed by default
(mostly because that’s not the way we use SwitchTower, and I suspect
there are others that wouldn’t use that feature, either). Another
option, though, is to package that up in a task library (http://
manuals.rubyonrails.org/read/chapter/122), such that it can be easily
added to any of the projects you use.

  • Jamis

#6

On Feb 22, 2006, at 12:38 AM, Michael Schoen wrote:

columns).

  1. hostnames are truncated if they contain dashes – i’m assuming
    the regex done is meant to grab the hostname from a fully-qualified
    name.

  2. on debian (at least) uptime reports "load average: " and not
    "averages: "

I can give you a patch if you’d like.

A patch would be wonderful! Thank-you, Michael.

  • Jamis

#7

Jamis – it doesn’t look like this patches made it into the new
Capistrano Extensions…


#8

A patch would be wonderful! Thank-you, Michael.

Let me know if the formatting below doesn’t work and I’ll email you an
attachment. All changes are to monitor.rb:

39,40c39,41
< padding = size - header.length - 1
< print " ", “-” * padding if padding > 0

    padding = size - header.length
    print " " if padding > 0
    print "-" * (padding - 1) if padding > 1

50c51
< names = servers.map { |s| s.match(/^(\w+)/)[1] }

names = servers.map { |s| s.match(/^([^.]+)/)[1] }

57c58
< parser = Proc.new { |text| text.match(/averages:
(.*)$/)[1].split(/, /) }

parser = Proc.new { |text| text.match(/average.*:

(.*)$/)[1].split(/, /) }


#9

Michael,

My apologies for letting this patch languish for so long. It didn’t
make it into 1.0.1 because at that point I was just trying to get the
SwitchTower/Capistrano debacle taken care of and out of the way.

I’ve committed your patch, so it will be part of the next Capistrano
Extensions release. Again, my apologies for not acting on this sooner.

  • Jamis

#10

Luke, this is what I do to “copy” the current database to the current
release:

task :after_deploy do

create a link to database.yml

run <<-CMD
rm -rf #{current_path}/config/database.yml &&
ln -nfs #{shared_path}/config/database.yml
#{current_path}/config/database.yml
CMD

restart
end