gpt4 book ai didi

ruby-on-rails - Capistrano 3. shared_pa​​th 变量中的错误路径

转载 作者:行者123 更新时间:2023-12-04 07:29:13 25 4
gpt4 key购买 nike

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

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

设置:unicorn_pid, "#{shared_pa​​th}/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/

谢谢。

最佳答案

我认为问题是当你调用它时:

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

在处理该行时对其进行评估,采用 shared_pa​​th 的当前值,即 /var/www/shared

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

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

关于ruby-on-rails - Capistrano 3. shared_pa​​th 变量中的错误路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20789080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com