# RE: Symlinks in Capistrano?

**URL:** <https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739>\
**Category:** Rails\
**Created:** [April 25, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739 "2006-04-25T14:21:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CampanoS\_David](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/34f0e0/32.png) [@CampanoS\_David](https://www.ruby-forum.com/u/CampanoS_David)\
**Post date:** [April 25, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739/1 "2006-04-25T14:21:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![CampanoS\_David](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/34f0e0/32.png) [@CampanoS\_David](https://www.ruby-forum.com/u/CampanoS_David)\
**Post date:** [April 25, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739/2 "2006-04-25T16:32:34Z")

</div>

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  
😉

Matt

---

<div class="post-metadata">

**Author:** ![CampanoS\_David](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/34f0e0/32.png) [@CampanoS\_David](https://www.ruby-forum.com/u/CampanoS_David)\
**Post date:** [April 25, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739/3 "2006-04-25T16:35:37Z")

</div>

whoops. noticed an error. should be:

run “ln -s #{shared\_path}/pages #{release\_path}/public/pages”

---

<div class="post-metadata">

**Author:** ![CampanoS\_David](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/34f0e0/32.png) [@CampanoS\_David](https://www.ruby-forum.com/u/CampanoS_David)\
**Post date:** [April 25, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/re-symlinks-in-capistrano/58739/4 "2006-04-25T17:43:32Z")

</div>

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
