【问题标题】:Restart application no longer working with Cap 3.1 and Rails 4重新启动应用程序不再使用 Cap 3.1 和 Rails 4
【发布时间】:2014-03-18 19:57:46
【问题描述】:

在我们升级到 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 不再隐式调用 :restart 所以我添加了以下内容:

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
>

我还需要重新启动吗?通常看起来没问题,但我想知道是否会因为找不到方法而出现问题。

【问题讨论】:

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


    【解决方案1】:

    遇到类似问题,尝试在服务器上运行此命令并出现错误 touch: cannot touch 'myappdir/releases/20140416074158/tmp/restart.txt': No such file or directory,所以我简单地添加了一行来创建一个release_path/tmp dir:

    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
    

    【讨论】:

    • 是的,我会尽快检查。
    【解决方案2】:

    失败的错误信息是什么?

    这对我有用:

    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'
    

    【讨论】:

    • 如何使用 cap 变得冗长?错误消息中没有太多价值。
    • 是的,cap -v 并没有给我更多。已经将日志级别设置为 DEBUG。
    • 很确定这个建议在语法上与我的相同。据我了解,显式“部署:...”的用法与“:...”相同。
    • 可能。只是想表明您可能还有其他问题,因为上述方法确实有效。奇怪的上限不会为您提供更多错误信息。
    【解决方案3】:

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

    我刚刚在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
    

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2014-11-19
        • 1970-01-01
        • 2015-11-14
        • 2018-10-07
        • 2014-03-25
        • 1970-01-01
        • 1970-01-01
        • 2016-11-13
        • 1970-01-01
        相关资源
        最近更新 更多