Capistrano 3. shared_pa​​th变量中的路径错误

dim*_*oss 1 capistrano ruby-on-rails unicorn capistrano3

我试图用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
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时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 ]
Run Code Online (Sandbox Code Playgroud)

所以,而不是/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`
Run Code Online (Sandbox Code Playgroud)

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

谢谢.

Phi*_*rom 5

我认为问题在于你打电话给我:

set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
Run Code Online (Sandbox Code Playgroud)

它被评价为行的处理的时刻,取为-则-当前值的shared_path是/var/www/shared.

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

set :unicorn_pid, -> {"#{shared_path}/tmp/pids/unicorn.pid"}
Run Code Online (Sandbox Code Playgroud)