我有这个任务:
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)
答案 0 :(得分:8)
在另一个答案here中有一些有用的信息,但是当您想要运行命令中有空格时,似乎会出现问题。
我遵循了砖块的建议,例如
within release_path do
execute *%w[ ln -nfs /home/blog/config/database.yml ./database.yml ]
end