Ruby-on-rails – capistrano + git deployment: could not create work tree dir : Permission denied

capistranopassengerruby-on-rails

I'm deploying using git and capistrano with passenger. I've been banging my head for a few hours trying to make this work, and haven't made much progress. cap deploy:setup works ok, but cap deploy is failing with Permission issues. I tried changing permissions/ownership on my slice, but it's still failing.

require 'bundler/capistrano'
set :user, 'some_user'
set :domain, 'example.com'
set :applicationdir, "/home/some_user/public_html/example"
set :port, 30000

set :scm, 'git'
set :repository,  "ssh://git@123.45.678.910:50000/home/git/example"
set :branch, 'master'
set :scm_verbose, true

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true

# deploy config
set :deploy_to, applicationdir
set :deploy_via, :remote_cache

# additional settings
default_run_options[:pty] = true  
ssh_options[:forward_agent] = true

# Passenger
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

results in the following error:

executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote ssh://git@123.45.678.910:50000/home/git/example.com master"
/Users/some_user/.rvm/gems/ruby-1.9.2-p0/gems/capistrano-2.6.0/lib/capistrano/recipes/deploy.rb:104: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
    command finished in 78068ms
  * executing "if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch  origin && git fetch --tags  origin && git reset  --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean  -d -x -f; else git clone   ssh://git@123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout  -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi"
    servers: ["example.com"]
    [example.com] executing command
 ** [example.com :: out] fatal: could not create work tree dir '/home/some_user/public_html/example.com/shared/cached-copy'.: Permission denied
    command finished in 353ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/some_user/public_html/example.com/releases/20110610173027; true"
    servers: ["example.com"]
    [example.com] executing command
    command finished in 218ms
failed: "sh -c 'if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch  origin && git fetch --tags  origin && git reset  --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean  -d -x -f; else git clone   ssh://git@123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout  -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi'" on example.com

Best Answer

Not sure how much this will help, but I always have a permissions issue after a deploy:setup

When you run deploy:setup it creates the initial directories for you. However those folders it creates are usually owned by root (In most of my situations anyway).

webapp/
  shared     root:root
  releases   root:root

To remedy this I will change ownership of those new folders to the user that will be using.

webapp/
  shared     myuser:myuser
  releases   myuser:myuser

Once this is done, I'll continue with my deploy:update

Related Topic