Capistrano不遵守"在release_path内"

Gra*_*ier 4 capistrano capistrano3

我有这个任务:

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
Run Code Online (Sandbox Code Playgroud)

出于某些令人愤怒的原因,该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).
Run Code Online (Sandbox Code Playgroud)

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

(顺便说一句,Capistrano 3.2.1)

Leo*_*Leo 8

还有另一种回答有用的信息,在这里,但短暂,似乎当有要运行的命令空间问题就出现了.

我遵循了砖块的建议,例如

within release_path do
  execute *%w[ ln -nfs /home/blog/config/database.yml ./database.yml ]
end
Run Code Online (Sandbox Code Playgroud)