Read more

Capistrano 3 has slightly changed its symlink implementation

Dominik Schöler
July 27, 2015Software engineer at makandra GmbH

In Capistrano 2, directories in shared_children used to be symlinked to the shared directory during the finalize_update task Show archive.org snapshot .

# <capistrano>/lib/capistrano/recipes/deploy.rb

_cset :shared_children,   %w(public/system log tmp/pids)
# ...
task :finalize_update, :except => { :no_release => true } do
  # ...
  shared_children.map do |d|
    run "ln -s #{shared_path}/#{d.split('/').last} #{latest_release}/#{d}" # <-- symlinks only the last segment here
  end
  # ...
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

This would symlink current/public/system to shared/system.

Capistrano 3 (which is almost a complete rewrite of the project) now properly expands paths to symlink Show archive.org snapshot . current/public/system is now symlinked to shared/public/system.

# <your project>/config/deploy.rb
set :linked_dirs, %w(log public/system)

# <capistrano>/lib/capistrano/tasks/deploy.rake
desc 'Symlink linked directories'
task :linked_dirs do
  # ...
  fetch(:linked_dirs).each do |dir|
    target = release_path.join(dir) # <-- symlinks the whole path
    source = shared_path.join(dir)
    # ...
    execute :ln, '-s', source, target
  end
end

This may bite you when you were backing up the shared/system directory. After upgrading to Capistrano 3, you will need to back up the shared/public/system directory instead. For our own projects we already do so.

Posted by Dominik Schöler to makandra dev (2015-07-27 14:40)