重新启动应用程序不再使用Cap 3.1和Rails 4

时间:2014-03-18 19:57:46

标签: ruby-on-rails ruby-on-rails-4 capistrano capistrano3

在我们升级到Rails 4和Cap 3.1

之前,以下任务正在进行
desc 'Restart application'
task :restart do
  on roles(:web), in: :sequence, wait: 5 do
    execute :touch, release_path.join('tmp/restart.txt')
  end
end

首先,我知道Cap 3.1没有隐式调用:重启,所以我添加了以下内容:

after :publishing, :restart

然而,它未能尝试触摸' restart.txt文件,以便Apache重新加载应用程序。

cap aborted!
touch stdout: Nothing written
touch stderr: Nothing written
config/deploy.rb:46:in `block (3 levels) in <top (required)>'
config/deploy.rb:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Command::Failed: touch stdout: Nothing written
touch stderr: Nothing written
>

我还需要重启吗?它通常看起来没问题,但我想知道是否可能因为没有找到办法来解决这个问题。

4 个答案:

答案 0 :(得分:15)

有类似问题,尝试在服务器上运行此命令并出错 touch: cannot touch 'myappdir/releases/20140416074158/tmp/restart.txt': No such file or directory,所以我只需添加一行来创建release_path/tmp目录:

desc 'Restart application'
task :restart do
  on roles(:web), in: :sequence, wait: 5 do
    execute :mkdir, '-p', "#{ release_path }/tmp"
    execute :touch, release_path.join('tmp/restart.txt')
  end
end

答案 1 :(得分:3)

失败的错误信息是什么?

这对我有用:

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app, :web), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end
end

after 'deploy:publishing', 'deploy:restart'

答案 2 :(得分:1)

我修改了给定的答案,以显示对我有用的解决方案

我刚刚输入config/deploy.rb文件末尾的下一行。

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:web), in: :sequence, wait: 5 do
      execute :mkdir, '-p', "#{ release_path }/tmp"
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :deploy, "deploy:restart"
  after :rollback, "deploy:restart"
end

这样做,Passenger将在每次部署/回滚后自动重启。

我认为值得一提的是,每次运行下一行时,您也可以从开发环境手动重启Passenger:

cap production deploy:restart

答案 3 :(得分:0)

在我的上限中,我在多服务器部署上遇到了类似的错误。似乎问题是它在重新启动之前依赖于运行先前的rails命令(生成tmp目录),例如db:migrate。