0

按照这里的答案,我有以下部署:

$ 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"

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

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

但是当 Capistrano 尝试触发命令时:

** [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

我曾尝试更改tounicorn_init_include.sh中的unicorn_init_staging.shto ./unicorn_init_include.sh,符号链接unicorn_abcto /etc/init.d/(如上所示),但它不起作用。

我做错了什么?

4

2 回答 2

0

尝试完整路径

改变

export RAILS_ENV
unicorn_init_include.sh

export RAILS_ENV
/etc/init.d/unicorn_init_include.sh
于 2013-10-11T19:54:59.753 回答
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

从内部获取 Bash 脚本的源目录

于 2013-10-11T19:56:37.603 回答