我怎样才能让Capistrano在部署时停止失败:create_symlink?

时间:2012-05-25 20:31:24

标签: ruby-on-rails-3 capistrano

至少那个看起来像卡皮斯特拉诺失败的地方。它一直贯穿整个部署并最终完成。这是输出。

* executing `deploy:create_symlink'
* executing "rm -f ~/xxx.xx.xx/test/current && ln -s ~/xxx.xx.xx/test/releases/20120525193307 ~/xxx.xx.xx/test/current"
servers: ["test.xxx.xx.xx"]
["test.xxx.xx.xx"] executing command
 ** [out :: test.xxx.xx.xx] rm: cannot remove `/var/www/vhosts/xxx.xx.xx/test/current': I command finished in 460ms
*** [deploy:create_symlink] rolling back
*** no previous release to rollback to, rollback of symlink skipped
* executing "rm -rf /var/www/vhosts/xxx.xx.xx/test/releases/20120525195909; true"
servers: ["test.xxx.xx.xx"]
[test.xxx.xx.xx] executing command
command finished in 524ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'default' -c 'rm -f /var/www/vhosts/xxx.xx.xx/test/current && ln -s /var/www/vhosts/xxx.xx.xx/test/releases/20120525195909 /var/www/vhosts/xxx.xx.xx/test/current'" on xxx.xx.xx

该应用正在使用     卡皮斯特拉诺(2.12.0)     capistrano-ext(1.2.1) 显然有更多的宝石只是试图把看似相关的东西,如果有更多的信息会有帮助,请告诉我。

这是deploy.rb

require "rvm/capistrano"
require 'bundler/capistrano'
require 'capistrano/ext/multistage'

set :stages, %w(staging production)
set :default_stage, 'staging'

set :application, 'xxx'

# trying to not use sudo on the deployment
#set :use_sudo, false

#set :copy_exclude, [".git", "spec"]

set :repository,  '~/git/xxx.git'
set :local_repository, "~/rorwork/xxx/.git"
set :scm, :git
set :user, 'xxx'
set :group, 'xxxx'
ssh_options[:forward_agent] = true
set :branch, 'master'
set :deploy_via, :remote_cache
set :scm_command, "/usr/local/bin/git"
set :local_scm_command, :default
default_run_options[:pty] = true
set :normalize_asset_timestamps, false #for asset piple

set :dbuser, 'xxx'
set :dbpass, 'xxx'

# 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
   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

和staging.rb

set :domain, 'test.xxx.xx.xx'

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

set :deploy_to, "/var/www/vhosts/xxx.xx.xx/test"
set :rails_env, 'staging'
set :rack_env, rails_env

set :dbname, "xxx_staging"

#set :bundle_without, [:test, :development, :production]

我在部署目录中手动创建“当前”,“共享”和“发布”文件夹,并分配相应的用户:组。最初是在dirs上获得权限问题,但得到了整理。在这里有点不知所措,很多寻求解决方案的目标都没有。任何建议或经验非常感谢!

在测试中cap staging deploy以为我会同时尝试生产cap production deploy保释...一致的聪明一点。

2 个答案:

答案 0 :(得分:6)

更新:找到它

删除'当前'目录并让capistrano创建最新版本的'当前'符号链接修复它。

我会尝试清理一下。我实际上创建了文件夹'current',比如'mkdir current'。这恰好妨碍了capistrano创建符号链接的方式。尝试一下,创建一个名为'bob'的文件夹,然后在同一目录下创建一个名为'bob'的符号链接,并将其指向某处,它可能会将符号链接'bob'放在目录'bob'中。

当我删除'当前''共享'等目录时,capistrano可以创建'当前'和其他必要的符号链接。因此,具体删除'当前'目录允许capistrano创建'当前'符号链接,只指向'版本'目录下的最新部署。

请注意以下错误,这也是问题所在。

** [out :: test.xxx.xx.xx] rm: cannot remove `/var/www/vhosts/xxx.xx.xx/test/current': I command finished in 460ms

失败的原因。我创建了名为“current”的文件夹。这就是问题。它不应该是一个目录,它应该是capistrano创建的符号链接。

通过创建这些文件夹,它破坏了部署。删除这些文件夹允许capistrano创建相同名称的符号链接。从那以后航行顺利。

答案 1 :(得分:0)

我刚刚找到了类似的问题。

这是我遇到的错误第一个错误:

cap aborted! Errno::ECONNREFUSED: Connection refused - connect(2) for "{my-ip-address}" port {my-ssh-port}

我也会得到类似的错误:

Tasks: TOP => git:create_release (See full trace by running task with --trace) The deploy has failed with an error: #<Errno::ECONNREFUSED: Connection refused - connect(2) for "my-ip-address" port {my-port}>

事实证明,当我的服务器运行Fail2Ban时,这是并发SSH会话的问题。为了解决这个问题,我只做了以下几点:

编辑包含SSH配置的jail

$ sudo nano /etc/fail2ban/jail.local

查找[SSH]并设置enabled = false 找到[ssh-ddos]并设置enabled = false

请记住在更改后重新启动Fail2Ban并打开-sh(如果那就是你使用的那个)

$ sudo service fail2ban reload
$ sudo /etc/init.d/ssh reload

值得注意的是,部署中的不同步骤(任务)将拒绝连接。例如,重启后快速bundle exec cap production deploy:check一切都很好。然后我尝试部署并收到相同的错误,但在执行不同的任务期间。我也使用UFW,我禁用并重新启用没有问题。 UFW不是导致上述问题的原因。

解决了这个问题后,Capistrano将无法创建从当前目录到最新版本的符号链接。错误如下:

Tasks: TOP => deploy:symlink:release The deploy has failed with an error: #<SSHKit::Command::Failed: rm exit status: 1 rm stdout: Nothing written rm stderr: Nothing written > ** Invoke deploy:failed (first_time) ** Execute deploy:failed

在广泛阅读,更改sshkit版本,降级capistrano,消除宝石等之后,我导航到我的文档根目录并列出目录内容ls -la我注意到current目录不在部署用户的组,我删除了当前文件夹(sudo rm -rf current),一切正常。祝你好运。