0

Following the answer here, I have the following for deployment:

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

You will notice it's all symlinked when I deploy:setup with 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

But when Capistrano tries to fire the command:

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

I have tried changing the unicorn_init_include.sh in the unicorn_init_staging.sh to ./unicorn_init_include.sh, symlinked the unicorn_abc to /etc/init.d/ (as shown above), but it doesn't work.

What have I done wrong?

Community
  • 1
  • 1
Victor
  • 13,010
  • 18
  • 83
  • 146

2 Answers2

0

Try full path

change

export RAILS_ENV
unicorn_init_include.sh

to

export RAILS_ENV
/etc/init.d/unicorn_init_include.sh
flashvoid
  • 118
  • 7
0

The error is in your unicorn_init_staging.sh, 4th line. When the unicorn_abc is called it's not calling from the working directory /home/deployer/abc/current/config, but somewhere else, like /etc/init.d . So it won't find your unicorn_init_include.sh.

You can troubleshoot by adding

echo 'pwd'

to the staging.sh file

What is probably is needed is changing the staging file to (not tested)

#!/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

Community
  • 1
  • 1
Electrawn
  • 2,254
  • 18
  • 24