如何安装部署服务器,并做了冷部署与Capistrano的?(How to setup a serve

2019-08-17 05:58发布

什么是正确的方式deploy:setup并做冷部署与Capistrano的?

运用

  • deploy.rb
  • Capistrano的v2.14.2
  • 流浪虚拟化我的服务器,

这是我的情景:

  1. 中运行时deploy:setup ,Capistrano的利用root权限准备的目录结构进行部署:

     $ cap deploy:setup * 2013-02-28 14:50:21 executing `deploy:setup' * executing "sudo -p 'sudo password: ' mkdir -p /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids" servers: ["example.com"] [example.com] executing command command finished in 29ms * executing "sudo -p 'sudo password: ' chmod g+w /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids" servers: ["example.com"] [example.com] executing command command finished in 11ms 
  2. 但在deploy:cold Capistrano的试图签(在这种情况下,GIT),写的vagrant用户-在指定的用户deploy.rb

     $ cap deploy:cold * 2013-02-28 14:50:47 executing `deploy:cold' * 2013-02-28 14:50:47 executing `deploy:update' ** transaction: start * 2013-02-28 14:50:47 executing `deploy:update_code' updating the cached checkout on all servers executing locally: "git ls-remote git@github.com:mariusbutuc/realtime-faye.git master" command finished in 2360ms * executing "if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q git@github.com:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi" servers: ["example.com"] [example.com] executing command ** [example.com :: out] fatal: could not create work tree dir '/home/vagrant/example/shared/cached-copy'.: Permission denied command finished in 26ms *** [deploy:update_code] rolling back * executing "rm -rf /home/vagrant/example/releases/20130228195049; true" servers: ["example.com"] [example.com] executing command command finished in 7ms failed: "sh -c 'if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q git@github.com:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi'" on example.com 
  3. 当然, deploy:check报告剥开没有惊喜: vagrant用户不能在过程中创建的目录写deploy:setup ,因为这两个用户属于不同的群体- root:rootvagrant:vagrant

     $ cap deploy:check [...] The following dependencies failed. Please check them and try again: --> You do not have permissions to write to `/home/vagrant/example'. (example.com) --> You do not have permissions to write to `/home/vagrant/example/releases'. (example.com) --> `/home/vagrant/example/shared' is not writable (example.com) 

这背后的理由,什么先决条件尚未满足,因此通过部署这个问题?

Answer 1:

deploy:setup任务可能不应该使用sudo创建应用程序目录,因为这很可能导致它为所拥有的root

你可以把它们关掉你的deploy.rb与文件:

set :use_sudo, false


Answer 2:

由于有在Capistrano的无组设置我的解决方法是扩大这样的设定,例如:

set :user,  'vagrant'
set :group, 'vagrant'

然后创建一个任务“修复”后运行所有权deploy:setup

after "deploy:setup", :setup_ownership
task :setup_ownership do
  run "#{sudo} chown -R #{user}:#{group} #{deploy_to} && chmod -R g+s #{deploy_to}"
end

但不是解决问题更好的唯一的事情是不是有它摆在首位,所以斯图尔特的回答是聪明了,也更优雅。



文章来源: How to setup a server for deployment and to do a cold deploy with Capistrano?