capistrano + git部署:无法创建工作树目录:权限被拒绝

时间:2011-06-10 17:38:57

标签: ruby-on-rails passenger capistrano

我正在使用git和capistrano与乘客一起部署。我一直在试图做这项工作几个小时,并没有取得多大进展。 cap deploy:安装程序正常,但是cap部署失败并出现权限问题。我尝试更改切片上的权限/所有权,但它仍然失败。

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

导致以下错误:

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

2 个答案:

答案 0 :(得分:10)

不确定这会有多大帮助,但我在deploy:setup

之后总是遇到权限问题

运行deploy:setup时,它会为您创建初始目录。但是它创建的那些文件夹通常由root拥有(在我的大多数情况下都是如此)。

webapp/
  shared     root:root
  releases   root:root

要解决此问题,我会将这些新文件夹的所有权更改为将要使用的用户。

webapp/
  shared     myuser:myuser
  releases   myuser:myuser

完成此操作后,我将继续使用deploy:update

答案 1 :(得分:0)

我刚刚遇到过这个问题。这是我发现的。

  • 如果您尚未成功部署,可能需要暂时将部署文件夹(在服务器中)移动到其他位置(或只​​是重命名)
  • 确保你的食谱中有这个:set :use_sudo, false
  • 再次运行:cap deploy:setup
  • 然后尝试另一轮cap deploy

如果您使用错误的用户构建了部署文件夹并告诉capistrano它具有sudo权限,那么您肯定会遇到其他有权限的问题。

我希望这对你有用,因为它对我有用。