Shell包含路径无法找到

时间:2013-10-11 19:34:14

标签: ruby-on-rails shell capistrano

answer here之后,我有以下部署:

$ ls -alh /etc/init.d
# unicorn_init_include.sh -> /home/deployer/abc/current/config/unicorn_init_include.sh
# unicorn_abc -> /home/deployer/abc/current/config/unicorn_init_staging.sh

# /home/deployer/abc/current/config/unicorn_init_staging.sh
#!/bin/sh
RAILS_ENV="staging"
export RAILS_ENV
unicorn_init_include.sh

# /home/deployer/abc/current/config/unicorn_init_include.sh
#!/bin/sh
set -e

TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/abc/current
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E $RAILS_ENV"

当我使用Capistrano deploy:setup时,你会注意到它都是符号链接的:

executing "sudo -p 'sudo password: ' ln -nfs /home/deployer/abc/current/config/unicorn_init_staging.sh /etc/init.d/unicorn_abc"
servers: ["192.168.33.10"]
[192.168.33.10] executing command
[out :: 192.168.33.10] 
command finished in 611ms
executing "sudo -p 'sudo password: ' ln -nfs /home/deployer/abc/current/config/unicorn_init_include.sh /etc/init.d/unicorn_init_include.sh"
servers: ["192.168.33.10"]
[192.168.33.10] executing command
[out :: 192.168.33.10] 
command finished in 602ms

但是当卡皮斯特拉诺试图解雇命令时:

** [out :: 192.168.33.10] /etc/init.d/unicorn_abc: 4: /etc/init.d/unicorn_abc:
** [out :: 192.168.33.10] unicorn_init_include.sh: not found

我尝试将unicorn_init_include.sh中的unicorn_init_staging.sh更改为./unicorn_init_include.sh,将unicorn_abc符号链接到/etc/init.d/(如上所示),但它没有'工作。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

尝试完整路径

变化

export RAILS_ENV
unicorn_init_include.sh

export RAILS_ENV
/etc/init.d/unicorn_init_include.sh

答案 1 :(得分:0)

错误发生在你的unicorn_init_staging.sh第4行。调用unicorn_abc时,它不是从工作目录/ home / deployer / abc / current / config调用,而是在其他地方调用,比如/etc/init.d。所以它找不到你的unicorn_init_include.sh。

您可以通过添加

进行问题排查
echo 'pwd'

到staging.sh文件

可能需要将暂存文件更改为(未测试)

#!/bin/bash
RAILS_ENV="staging"
export RAILS_ENV
`dirname ${BASH_SOURCE[0]}`/unicorn_init_include.sh

Getting the source directory of a Bash script from within