2014-10-10 43 views
3

服從我有這樣的任務:Capistrano的不「內release_path」

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,順便說一句)

回答

7

還有另一種回答here有用的信息,但簡要地似乎當有要運行的命令空間問題就出現了。

我跟着磚匠的建議,例如

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

謝謝,我放棄了這一個。 [這Github問題](https://github.com/capistrano/capistrano/issues/719)(從你指出的其他答案鏈接)也是信息。 – 2015-01-13 03:14:54