我正在修改一个功能性的Capistrano脚本试图加快速度,因为我的家庭上网速度非常可怕。我有一个git服务器(不是github)和一个ubuntu开发服务器,当我运行cap部署时,它当前从我的git repo抓取最新的并制作本地副本然后将其上传到我的ubuntu服务器并重新启动乘客而没有问题。我的capistrano代码包含...
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://gitadmin@sub.example.com/opt/git/hub/app.git master"←[0m
gitadmin@sub.example.com'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://gitadmin@sub.example.com/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密码 - gitadmin@sub.example.com' s密码:
我输入然后它继续正常,然后它似乎在上面的下一个命令出错。我猜我需要以某种方式设置一些ssh密钥?同样,这不是托管在github上,repo和dev服务器是我公司服务器上的两个独立的盒子。本地我正在运行Windows 7.如果我尝试添加...
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
我得到相同的距离,但这次不是自动说拒绝权限,而是提示输入gitadmin密码,我输入正确的密码,然后说'#34;权限被拒绝"。
答案 0 :(得分:2)
如果您发布了完整的capistrano scipt(减去任何密码,IP地址)会有所帮助,但我怀疑您需要将您的服务器引入远程存储库。 您根本不需要deploy_via选项
要将您的服务器引入您的repo ssh到您的服务器,并从那里ssh到存储库服务,应该有用于此的URL的文档。您将收到拒绝访问的消息,但关键是此进程将ssh公钥添加到您的服务器
在部署时可能还值得观看Ryan Bates Railscast,他使用github,但任何远程仓库的过程都非常相似
http://railscasts.com/episodes/335-deploying-to-a-vps 注意他如何将他的服务器引入github,就像我说的那样,你的服务应该为你提供类似介绍的说明
有一个修改过的(专业)演员阵容需要订阅,但Ryan正处于延长休息时间(可能现在无限期),因此订阅将是非常有价值的,值得考虑。
关于capstrano的修订(专业)演员,如何设置变量等......在这里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, "git@bitbucket.org: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