I'm currently in the process of attempting my first Rails deployment using Capistrano, and I've run into a roadblock I haven't been able to overcome. During the cap deploy
I'm getting an error "mkdir: cannot create directory
/public'`".
Pertinent Details:
- Rails Version: 3.2.6
- Capistrano Version: 2.13.5
- Running on Dreamhost
- I'm precompiling my assets (I suspect this is part of the problem), so I've got
load 'deploy/assets'
in my Capfile.
I've followed the directions here: http://wiki.dreamhost.com/Capistrano for the most part, as well as scouring the web for a number of other articles on Capistrano.
deploy.rb
require "bundler/capistrano"
ssh_options[:forward_agent] = true
ssh_options[File.join(ENV["HOME"], ".ssh", "id_rsa-dreamhost")]
set :application, "<app>"
set :repository, "git@bitbucket.org:<gituser>/#{application}.git"
set :server_name, "<host>"
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :checkout, "export"
set :deploy_via, :remote_cache
set :branch, "master"
set :base_path, "/home/<user>/<domain>"
set :deploy_to, "#{base_path}/#{application}"
set :keep_releases, 3
set :user, '<user>'
set :runner, '<user>'
set :use_sudo, false
default_run_options[:pty] = true
set :shared_path, "/home/<user>/<shared_folder>"
set :release_path, "#{base_path}/#{application}"
role :web, "<host>" # Your HTTP server, Apache/etc
role :app, "<host>" # This may be the same as your `Web` server
role :db, "<host>", :primary => true # This is where Rails migrations will run
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
desc "Restart the app by touching the restart.txt file."
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
desc "Update the environment-specific files from the shared folder."
task :symlink_shared, :roles => [:app] do
run "ln -s #{shared_path}/app_config.yml #{release_path}/config/"
run "rm #{release_path}/config/database.yml"
run "ln -s #{shared_path}/database.yml #{release_path}/config/"
run "rm #{release_path}/public/.htaccess"
run "ln -s #{shared_path}/.htaccess #{release_path}/public/"
end
end
before "deploy:restart", "deploy:symlink_shared"
after "deploy:update_code", "deploy:migrate"
Output of cap deploy:setup
* 2012-12-23 16:49:27 executing `deploy:setup'
* executing "mkdir -p /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
servers: ["<host>"]
[<host>] executing command
command finished in 263ms
* executing "chmod g+w /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
servers: ["<host>"]
[<host>] executing command
command finished in 261ms
Output of cap deploy:check
* 2012-12-23 16:49:45 executing `deploy:check'
* executing "test -d /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 265ms
* executing "test -w /home/<user>/<domain>/<app>"
servers: ["<host>"]
[<host>] executing command
command finished in 256ms
* executing "test -w /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 256ms
* executing "which git"
servers: ["<host>"]
[<host>] executing command
command finished in 259ms
* executing "test -w /home/<user>/<shared_folder>"
servers: ["<host>"]
[<host>] executing command
command finished in 263ms
You appear to have all necessary dependencies installed
Output of cap:deploy
* 2012-12-23 16:51:41 executing `deploy'
* 2012-12-23 16:51:41 executing `deploy:update'
** transaction: start
* 2012-12-23 16:51:41 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@bitbucket.org:<gituser>/<app>.git master"
command finished in 1102ms
* executing "if [ -d /home/<user>/<shared_folder>/cached-copy ]; then cd /home/<user>/<shared_folder>/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 && git clean -q -d -x -f; else git clone -q git@bitbucket.org:<gituser>/<app>.git /home/<user>/<shared_folder>/cached-copy && cd /home/<user>/<shared_folder>/cached-copy && git checkout -q -b deploy 42dfb6a3f529e2293192f5e22c3214b7da55c9b4; fi"
servers: ["<host>"]
[<host>] executing command
command finished in 3233ms
copying the cached version to /home/<user>/<domain>/<app>
* executing "cp -RPp /home/<user>/<shared_folder>/cached-copy /home/<user>/<domain>/<app> && (echo 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 > /home/<user>/<domain>/<app>/REVISION)"
servers: ["<host>"]
[<host>] executing command
command finished in 338ms
* 2012-12-23 16:51:47 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2012-12-23 16:51:47 executing `deploy:assets:symlink'
* executing "ls -x /home/<user>/<domain>/<app>/releases"
servers: ["<host>"]
[<host>] executing command
command finished in 252ms
* executing "rm -rf /public/assets &&\\\n mkdir -p /public &&\\\n mkdir -p /home/<user>/<shared_folder>/assets &&\\\n ln -s /home/<user>/<shared_folder>/assets /public/assets"
servers: ["<host>"]
[<host>] executing command
** [out :: <host>] mkdir: cannot create directory `/public'
** [out :: <host>] : Permission denied
command finished in 268ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/<user>/<domain>/<app>; true"
servers: ["<host>"]
[<host>] executing command
command finished in 265ms
failed: "sh -c 'rm -rf /public/assets &&\\\n mkdir -p /public &&\\\n mkdir -p /home/<user>/<shared_folder>/assets &&\\\n ln -s /home/<user>/<shared_folder>/assets /public/assets'" on <host>
You can see the Permission denied error near the bottom of the output, as well as the failed shell command at the end. I can't figure out why it is attempting to do anything with /public
, as I would expect a relative path to public
in my web folder, rather than referring to what appears to be a public folder on root. I feel like I'm missing a variable reference somewhere which should get prepended to the mkdir command, but none of of the documentation I've read indicates this.
I'd appreciate any help I can get, and thanks in advance.