# Trouble with Capistrano and custom symlink from shared direc

**URL:** <https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578>\
**Category:** Rails\
**Created:** [November 7, 2006, 10:48am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578 "2006-11-07T10:48:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:48am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/1 "2006-11-07T10:48:47Z")

</div>

Hi there

I have a Rails app which requires the client to upload image files to  
a certain directory.

I’m using capistrano to deploy and have created a directory in shared:  
shared/book\_images

I want to symlink this to my\_rails\_app/public/images/book\_images and  
have this task in my deploy.rb file:

desc “Link to the book images directory where uploads go”  
task :after\_symlink do  
run “ln -nfs #{shared\_dir}/book\_images  
#{release\_path}/public/images/book\_images”  
end

However, iif I ssh into the current release, I see that the symlink  
above is incorrect: the symlink to the shared book\_images directory is  
_inside_ of public/images/book\_images

that is, I end up with public/images/book\_images/book\_images

Any clues on how to resolve this would be appreciated.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/2 "2006-11-07T10:49:25Z")

</div>

Richard S. wrote:

> that is, I end up with public/images/book\_images/book\_images
> 
> Any clues on how to resolve this would be appreciated.

Does your release\_path/public already contain an images/book\_images  
directory _before_ you symlink? I seem to remember having a similar  
problem and it was because I already had a public/photos directory in  
subversion and so when I deployed the app and then tried to link  
public/photos to shared/photos, I remember something screwy happening.  
My quicky hack workaround was to delete the real directory before I did  
the symlink, i.e.:

task :after\_update\_code, :roles =\> :app do  
run “rm -rf #{release\_path}/public/photos”  
run “ln -nfs #{shared\_path}/photos #{release\_path}/public/photos”  
end

HTH,

Jamey

Confidentiality Notice: This email message, including any attachments,  
is for the sole use of the intended recipient(s) and may contain  
confidential and/or privileged information. If you are not the intended  
recipient(s), you are hereby notified that any dissemination,  
unauthorized review, use, disclosure or distribution of this email and  
any materials contained in any attachments is prohibited. If you receive  
this message in error, or are not the intended recipient(s), please  
immediately notify the sender by email and destroy all copies of the  
original message, including attachments.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:49am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/3 "2006-11-07T10:49:58Z")

</div>

On 11/1/06, Jamey C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does your release\_path/public already contain an images/book\_images  
> directory _before_ you symlink?

Yes and adding ‘rm -rf’ to the task fixes the issue.

Many thanks Jamey.

–  
Richard S.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/4 "2006-11-07T10:51:23Z")

</div>

You could link the book\_images/ backwards to …/…/shared/book\_images  
and keep the link under version control. Just an idea.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:50am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/5 "2006-11-07T10:50:18Z")

</div>

Upon closer inspection, the sylink is created fine, but for some  
reason I can’t access the symlinked directory. It’s permissions are  
the same as other directories but if I try and cd into it, I get ‘no  
such file or directory’.

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/6 "2006-11-07T10:51:31Z")

</div>

don’t you mean #{shared\_path}

I do the same thing and it looks like this in my config/deploy.rb :

`
desc “Create the #{shared_dir}/files/production|development|test dirs "
+
“if they don’t exists and add symlink to #{shared_dir}/files from
" +
“the current release path”
task :symlink_files_dir, :roles => :app do
[‘production’,‘development’,‘test’].each do |env|
run “mkdir -p #{shared_path}/files/#{env}” unless
File.exists?(”#{shared_path}/files/#{env}”)
end
change owner and permission of files
sudo “chown --recursive #{user}:#{apache_group} #{shared_path}/files”
sudo “chmod --recursive 774 #{shared_path}/files”
run “mv #{release_path}/files #{release_path}/files.local”
run “ln -s #{shared_path}/files #{release_path}/files”
end
desc “Do these tasks after you update the code”
task :after_update_code do
symlink_files_dir
end
`

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 7, 2006, 11:00am UTC](https://www.ruby-forum.com/t/trouble-with-capistrano-and-custom-symlink-from-shared-direc/74578/7 "2006-11-07T11:00:59Z")

</div>

Yeah - all is working fine now. Many thanks.
