尝试使用 Capistrano 部署 Rails 应用程序时,如何避免权限被拒绝错误?

尝试使用 Capistrano 部署 Rails 应用程序时,如何避免权限被拒绝错误?

我完全是个菜鸟。我正尝试通过 Capistrano 部署一个应用程序。当我尝试运行 cap deploy:update 时,我不断收到权限被拒绝的错误。似乎至少其中一些错误是由于缺少触发“权限被拒绝”错误的目录造成的。(我只是暂时以 root 身份进行设置。)

set :user, 'root'
set :domain, 'domainname.com'
set :application, 'appname'
# adjust if you are using RVM, remove if you are not
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.2'
# file paths
set :repository, "ssh://[email protected]/~/git/appname.git"
set :deploy_to, "/var/rails/appname"
# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)
role :app, domain 
role :web, domain
role :db, domain, :primary => true
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, :production
namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
desc "reload the database with seed data"
task :seed do
run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
end
end
after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end

这是我的结果:

** [domainname.com :: out] Cloning into '/var/rails/appname/shared/cached-copy'...
** [domainname.com :: err] Permission denied, please try again.
** [domainname.com :: err] Permission denied, please try again.
** [domainname.com :: err] Permission denied (publickey,gssapi-with-mic,password).
** [domainname.com :: err] fatal: The remote end hung up unexpectedly

我可以不使用密码进行 ssh,因此不确定是否存在公钥错误。

顺便说一句,如果我cap deploy:update没有运行set :deploy_via, :remote_cache,结果如下:

 ** [domainname.com :: out] Cloning into '/var/rails/appname/releases/20120326204237'...
 ** [domainname.com :: err] Permission denied, please try again.
 ** [domainname.com :: err] Permission denied, please try again.
 ** [domainname.com :: err] Permission denied (publickey,gssapi-with-mic,password).
 ** [domainname.com :: err] fatal: The remote end hung up unexpectedly
command finished

非常感谢您对此的帮助。

更新 添加ssh_options[:forward_agent] = true到 deploy.rb 似乎可以在一定程度上改善情况。

答案1

你可以加

set :admin_runner, "my_apps_username"

在 config/deploy.rb 中。或者,你可以像这样覆盖 deploy:setup 任务:

namespace :deploy do
  task :setup, :except => { :no_release => true } do
    dirs = [deploy_to, releases_path, shared_path]
    dirs += shared_children.map { |d| File.join(shared_path, d.split('/').last) }
    run "mkdir -p #{dirs.join(' ')}"
    run "chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
  end
end

相关内容