【问题标题】:Capistrano 3. Wrong path in the shared_path variableCapistrano 3. shared_pa​​th 变量中的路径错误
【发布时间】:2013-12-26 17:59:10
【问题描述】:

我正在尝试使用 Capistrano 3 创建 Unicorn 重启任务:

首先,我设置 *unicorn_pid* 变量:

set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"

然后我将它传递给重启任务:

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :kill, "-USR2 `cat #{fetch(:unicorn_pid)}`" if test "[ -f #{fetch(:unicorn_pid)} ]"
      within release_path do
        execute :bundle, "exec unicorn -D -c config/unicorn.rb -E #{fetch(:stage)}"
      end
    end
  end

但是当我运行cap production deploy:restart 时,我看到了:

DEBUG [f4159760] Running /usr/bin/env [ -f /var/www/shared/tmp/pids/unicorn.pid ] on dev.project.net
DEBUG [f4159760] Command: [ -f /var/www/shared/tmp/pids/unicorn.pid ]

所以,而不是 /home/user/project/shared/ 路径,#{shared_pa​​th} 转换为 /var/www/shared/

但是当我直接在任务中指定此路径时,我在输出中看到没有 unicorn_pid 变量:

 INFO [567856e3] Running /usr/bin/env kill -USR2 `cat /home/user/project/shared/tmp/pids/unicorn.pid` on dev.educapsule.net
DEBUG [567856e3] Command: /usr/bin/env kill -USR2 `cat /home/user/project/shared/tmp/pids/unicorn.pid`

为什么当我在“自定义”变量中传递路径时,路径会更改为/var/www/shared/

谢谢。

【问题讨论】:

    标签: ruby-on-rails capistrano unicorn capistrano3


    【解决方案1】:

    我认为问题在于当你调用这个时:

    set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
    

    在处理该行的那一刻对其进行评估,采用shared_path 的当前值,即/var/www/shared

    尝试将该行更改为这应该会延迟它的执行,直到您实际引用 unicorn_pid

    set :unicorn_pid, -> {"#{shared_path}/tmp/pids/unicorn.pid"}
    

    【讨论】:

    • 我指定了set :unicorn_pid, -> {"#{shared_path}/tmp/pids/unicorn.pid"} 并且它有效。谢谢。
    • 实际上 shared_pa​​th 在 capistrano 3 中不是 var,它是 DSL 方法。所以建议的解决方案是不正确的,fetch :shared_path 将返回 nil。作者的评论是对的。见source
    • 所以@philip-hallstrom,请编辑您的答案,否则我们将删除该答案并发布正确的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 2011-04-13
    • 2015-07-22
    相关资源
    最近更新 更多