RE: Symlinks in Capistrano?

This might help, I didn’t want to store a rails version in svn or to
make my deployment dependent on the rails site being up. Therefore, I
checked out rails 1.1.1, and created a directory called rel_1-1-1 under
my home directory. Then I created this simple task below to create a
symlink whenever it is deploying. I placed this code into the deploy.rb
file.

desc “Symlink Rails to version 1.1”
task :add_symlink_to_rails, :roles => :web do
run “ln -s ~/rails/rel_1-1-1/ #{release_path}/vendor/rails”
end

I also modified the long_deploy task to run this custom task right after
the symlink task.

desc “A task demonstrating the use of transactions.”
task :long_deploy do
transaction do
update_code
disable_web
symlink
add_symlink_to_rails
migrate
end

restart
enable_web
end

Hope this helps!

you can also create an after_deploy task as part of your deploy.rb. it
will
run automatically at the end of the defauly deploy task. (and perhaps
the
others as well? not sure…) This would be similar to what’s shown
above,
but perhaps a little simpler if your needs aren’t as complex. I do this
to
seperate my static html into shared.

task :after_deploy do
run “ln -s #{shared_path}/pages #{releases_path}/public/pages”
end

either will work… My needs are simpler, and perhaps yours are as well
:wink:

Matt

whoops. noticed an error. should be:

run “ln -s #{shared_path}/pages #{release_path}/public/pages”

Note that you can prepend “after_” or “before_” to any task name to
extend the behavior of that task. Thus, if you want to do extra work
at the symlink stage, just create a task called “after_symlink”:

task :after_symlink do

end

  • Jamis