【问题标题】:Capistrano doesn't obey "within release_path"Capistrano 不遵守“在 release_path 内”
【发布时间】:2014-12-05 04:56:38
【问题描述】:

我有这个任务:

namespace :custom do
  desc "create a symlink to db config already on the server"
  task :symlink_db_config do
    on roles(:web) do
      within release_path do
        execute "pwd"
      end

      within release_path do
        execute "ln -nfs /home/blog/config/database.yml ./database.yml"
      end
    end
  end
end

出于某种令人愤怒的原因,pwd 命令前面有一个cd 到发布路径,但ln 命令不是。这是为什么呢?

这是输出,显示上面的内容:

** Invoke custom:symlink_db_config (first_time)
** Execute custom:symlink_db_config
DEBUG[352cc4bb] Running /usr/bin/env if test ! -d /home/blog/staging/releases/20141010050707; then echo "Directory does not exist '/home/blog/staging/releases/20141010050707'" 1>&2; false; fi on 172.245.32.193
DEBUG[352cc4bb] Command: if test ! -d /home/blog/staging/releases/20141010050707; then echo "Directory does not exist '/home/blog/staging/releases/20141010050707'" 1>&2; false; fi
DEBUG[352cc4bb] Finished in 0.199 seconds with exit status 0 (successful).

// Here's the `pwd`; note the proper `cd` that occurs first:

INFO[67a83a04] Running /usr/bin/env pwd on 172.245.32.193
DEBUG[67a83a04] Command: cd /home/blog/staging/releases/20141010050707 && /usr/bin/env pwd
DEBUG[67a83a04]     /home/blog/staging/releases/20141010050707
INFO[67a83a04] Finished in 0.268 seconds with exit status 0 (successful).
DEBUG[f46f64b3] Running /usr/bin/env if test ! -d /home/blog/staging/releases/20141010050707; then echo "Directory does not exist '/home/blog/staging/releases/20141010050707'" 1>&2; false; fi on 172.245.32.193
DEBUG[f46f64b3] Command: if test ! -d /home/blog/staging/releases/20141010050707; then echo "Directory does not exist '/home/blog/staging/releases/20141010050707'" 1>&2; false; fi
DEBUG[f46f64b3] Finished in 0.243 seconds with exit status 0 (successful).

//And now here's the `ln`... but where is the `cd`?  I said `within release_path`, didn't I?

INFO[afdbd89c] Running /usr/bin/env ln -nfs /home/blog/config/database.yml ./database.yml on 172.245.32.193
DEBUG[afdbd89c] Command: ln -nfs /home/blog/config/database.yml ./database.yml
INFO[afdbd89c] Finished in 0.219 seconds with exit status 0 (successful).

所以我的ln 失败了,因为它不在正确的目录中。为什么 capistrano cd 没有像我告诉它的那样进入发布目录?

(顺便说一句,Capistrano 3.2.1)

【问题讨论】:

    标签: capistrano capistrano3


    【解决方案1】:

    在另一个答案here 中有有用的信息,但简单地说,当您要运行的命令中有空格时,似乎会出现问题。

    我听从了bricker的建议,例如

    within release_path do
      execute *%w[ ln -nfs /home/blog/config/database.yml ./database.yml ]
    end
    

    【讨论】:

    • 谢谢,我已经放弃了这个。 This Github issue (链接自您指出的其他答案)也提供了丰富的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 2016-08-29
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多