2014-03-13 89 views
2

我正在修改功能Capistrano脚本试图加快它,因为我的家庭互联网上传速度是可怕的。我有一个git服务器(不是github)和一个ubuntu dev服务器,当我运行cap部署时,它当前从我的git repo中获取最新的内容,并制作一个本地副本,然后将其上传到我的ubuntu服务器,并重新启动乘客而没有问题。我Capistrano的代码包含...Capistrano部署使用remote_cache - 权限被拒绝

set :deploy_via, :copy 

但是,如果我尝试使用这个,而不是...

set :deploy_via, :remote_cache 

我得到这个错误...

** transaction: start 
    * ←[32m2014-03-13 08:43:36 executing `deploy:update_code'←[0m 
    updating the cached checkout on all servers 
    ←[33mexecuting locally: "git ls-remote ssh://[email protected]/opt/git/hub/app.git master"←[0m 
[email protected]'s password: 
    ←[2;37mcommand finished in 6880ms←[0m 
    * ←[33mexecuting "if [ -d /srv/www/app/shared/cached-copy ]; then cd /srv/www/app/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset 
-q --hard efe4a94f5a4f1354edb0f4b516e9ea1d627e5101 && git clean -q -d -x -f; else git clone -q -b master ssh://[email protected]/opt/git/hub/app.git /s 
rv/www/app/shared/cached-copy && cd /srv/www/app/shared/cached-copy && git checkout -q -b deploy efe4a94f5a4f1354edb0f4b516e9ea1d627e5101; fi"←[0m 
    servers: ["12.34.56.78"] 
    [12.34.56.78] executing command 
** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m 
** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m 
** ←[31m[12.34.56.78 :: err] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).←[0m 
** [12.34.56.78 :: err] fatal: The remote end hung up unexpectedly 

它会提示git密码 - [email protected]的密码:

我输入并且进行正常,那么它似乎错误地出现在下一个通信以上。我猜我需要设置一些SSH密钥?再次,这不是托管在github上,repo和dev服务器是我公司服务器上的两个单独的框。本地我运行Windows 7,如果我尝试添加...

set :ssh_options, { :forward_agent => true } 
default_run_options[:pty] = true 

我得到同样的距离,但这个时候,而不是说自动拒绝的权限,它会提示输入密码gitadmin,我输入正确,它说“没有权限”。

+0

你解决了吗? – jamesc

+0

@jamesw:对不起,我被拉到了我们项目的另一部分,我的脚本脚本与您提供的脚本类似,只是它对于多个环境稍微复杂一些。我试图从部署服务器sshing到git服务器,但它只是在询问密码后挂起。使用您提供的上限脚本给了我同样的问题,我没有时间查看您链接到的railscast。 – HelloWorld

+0

你使用的是什么git服务器? – jamesc

回答

2

如果您发布了完整的capistrano scipt(减去任何密码,ip地址),这将有所帮助,但我怀疑您需要将您的服务器引入远程存储库。 你根本不需要deploy_via选项

要将你的服务器引入你的服务器到你的服务器并从那里ssh进入版本库服务,应该有关于这个url的文档。你会得到一个访问被拒绝的消息,但重点是,这个过程添加ssh公钥到你的服务器

它也许值得关注部署Ryan Bates Railscast,他使用github但这个过程是非常类似的任何远程repo

http://railscasts.com/episodes/335-deploying-to-a-vps 注重他是如何介绍他的服务器到github上,就像我说的,你的服务应该为您提供类似的介绍说明

有一个修订(PRO)铸,你会需要一个订阅但瑞安正处于延期休息期(现在可能无限期),所以订阅价值非常高现在,值得思考。

上capstrano修订(PRO)铸,如何设置变量等等......在这里http://railscasts.com/episodes/133-capistrano-tasks-revised

这是我的应用程序的一个工作脚本只是代替xxx和路径,你认为合适,我承担你有所有的启动和重新启动的东西已经建立,但这应该指出你至少需要的最低设置。我这样说是因为你可能有其他你不需要的设置,但是因为你没有发布你的脚本,所以不可能说出来。

require "bundler/capistrano" 

server "146.185.182.228", :web, :app, :db, primary: true 
set :application, "xxx" 
set :user, "xxxx" 

# adjust if you are using RVM, remove if you are not 
set :rvm_type, :user 
set :rvm_ruby_string, 'ruby-2.0.0-p353' 
set :ssh_options, {:forward_agent => true} 

default_run_options[:pty] = true 


# file paths 
set :repository, "[email protected]:xxxx.git" 
set :deploy_to, "/home/#{user}/apps/#{application}" 
# 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 :scm, :git 
set :use_sudo, false 
set :rails_env, :production 
set :password, "xxxxxxx" 

#role :web, "your web-server here"       # Your HTTP server, Apache/etc 
#role :app, "your app-server here"       # This may be the same as your `Web` server 
#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run 
#role :db, "your slave db-server here" 

# 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 
    %w[start stop restart].each do |command| 
    desc "#{command} unicorn server" 
    task command, roles: :app, except: {no_release: true} do 
     run "cd #{release_path} && bundle install" 
     run "/etc/init.d/unicorn_#{application} #{command}" 
     run "#{sudo} service nginx #{command}" 
    end 
    end 

    task :setup_config, roles: :app do 
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}" 
    sudo "ln -nfs #{current_path}/config/init_unicorn.sh /etc/init.d/unicorn_#{application}" 
    sudo "ln -nfs #{current_path}/config/sidekiq.conf /etc/init/sidekiq.conf" 
    run "mkdir -p #{shared_path}/config" 
    end 
    after "deploy:setup", "deploy:setup_config" 

    desc "Make sure local git is in sync with remote." 
    task :check_revision, roles: :web do 
    unless `git rev-parse HEAD` == `git rev-parse origin/master` 
     puts "WARNING: HEAD is not the same as origin/master" 
     puts "Run `git push` to sync changes." 
     exit 
    end 
    end 

    before "deploy", "deploy:check_revision" 
    after "deploy:update_code", "deploy:symlink_shared" 

end 
+0

+ +1努力:) – HelloWorld

+0

@HelloWorld :) Ta! – jamesc