Quantcast
Channel: Lasse Bunk's weblog
Viewing all articles
Browse latest Browse all 14

Creating a public symlink using Capistrano

$
0
0

So, I have a folder containing static sitemap files for my site. These sitemaps are generated and saved in my public/sitemap folder. However, I want to keep these sitemap files between deployments.

What I need is a symlink from public/sitemap that’s pointing to shared/sitemap.

I use Capistrano for my deployments, so I need the following task (I renamed my sitemap namespace and folder to better reflect other needs you might have):

after "deploy:update_code", "my_namespace:symlink"

namespace :my_namespace do
  desc "Create symlink"
  task :symlink do
    run "rm -rf #{release_path}/public/my_folder"
    run "mkdir -p #{shared_path}/my_folder"
    run "ln -nfs #{shared_path}/my_folder #{release_path}/public/my_folder"
  end
end

This will remove any existing public/my_folder folder (e.g. if it was deployed from your development repository), create the shared/my_folder folder (if it doesn’t exist), and at last create the symlink from public/my_folder to shared/my_folder.

As easy as that :-) Hope you can use it.


Viewing all articles
Browse latest Browse all 14

Trending Articles