Switchtower custom tasks question


#1

hi,

i’m just getting started using switchtower for deployment. i’m working
with a small team of 3 and a hosted subversion repository.

i have switchtower working, but i need to create two custom tasks and
have those tasks run at deployment. 1) copy a working dispatch.fcgi
from another folder, and 2) copy db/database.example to
db/database.yml

here is what i’ve tried, inside of deploy.rb:

custom tasks

desc “copy another dispatch.fcgi, which gets deleted”
task :cp_dispatch_fcgi do
File.copy("/path/to/other_app/public_html/dispatch.fcgi",
“/path/to/current/public/dispatch.fcgi”)
end

desc “copy database.example to database.yaml”
task :cp_database_yaml do
put(File.read(’/path/to/current/db/database.example’),
“/path/to/current/db/database.yml”, :mode => 0444)
end

and then:

desc “deploy”
task :deploy do
transaction do
update_code
update_current
cp_dispatch_fcgi
cp_database_yaml
end
end

i may be going about this all wrong, so any help would be appreciated.

thanks in advance, ian

Ian Kennedy
http://www.fiftymillimeter.com


#2

Ian,

The easiest way is to take advantage of ST’s ability to hook into an
existing task. If you define a new task and give it the same name as
an existing task, prefixed with “before_” or “after_”, ST will
execute that task either before or after its namesake.

An example:

task :after_update_code do
cp_dispatch_fcgi
cp_database_yml
end

That way, you don’t have to duplicate the existing :deploy task just
to add your custom functionality to it.

  • Jamis