Capistrano 3 has slightly changed its symlink implementation

Posted Almost 9 years ago. Visible to the public.

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

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.

Dominik Schöler
Last edit
Over 8 years ago
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2015-07-27 12:40)