Search code examples
capistranoshunicorncapistrano3

Error during Capistrano deploy


When I run cap production deploy:start, Capistrano throws an error while starting the Unicorn server, however if I SSH into the server and run ./home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start, the server starts as it should (however, there is no output to say that the server has started in the terminal).

The error I get is the following:

INFO[fc27be26] Running /usr/bin/env /home/deployer/apps/explorelocal/current/config/unicorn_init.sh start on explore.jackhughesweb.com
DEBUG[fc27be26] Command: /home/deployer/apps/explorelocal/current/config/unicorn_init.sh start
DEBUG[fc27be26]     /home/deployer/apps/explorelocal/current/config/unicorn_init.sh: 1: eval:
DEBUG[fc27be26]     bundle: not found
DEBUG[fc27be26]
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <SERVER HOST>: /home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start exit status: 127
/home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start stdout: Nothing written
/home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start stderr: Nothing written
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
config/deploy.rb:35:in `block (3 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:10:in `block in execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:8:in `each'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:8:in `execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/coordinator.rb:21:in `each'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/dsl.rb:6:in `on'
config/deploy.rb:32:in `block (2 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/cap:23:in `load'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/cap:23:in `<main>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `eval'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `<main>'
SSHKit::Command::Failed: /home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start exit status: 127
/home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start stdout: Nothing written
/home/deployer/apps/<APPNAME>/current/config/unicorn_init.sh start stderr: Nothing written
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:170:in `block (3 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:172:in `block (2 levels) in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:186:in `with_ssh'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
config/deploy.rb:35:in `block (3 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:10:in `block in execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:8:in `each'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/runners/sequential.rb:8:in `execute'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/coordinator.rb:21:in `each'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/sshkit-1.5.1/lib/sshkit/dsl.rb:6:in `on'
config/deploy.rb:32:in `block (2 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/cap:23:in `load'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/cap:23:in `<main>'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `eval'
/Users/Jack/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => deploy:start
(See full trace by running task with --trace)

My unicorn_init.sh file has the following contents:

#!/bin/sh
set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/<APPNAME>/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=deployer
set -u

OLD_PIN="$PID.oldbin"

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  run "$CMD"
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  run "$CMD"
  ;;
upgrade)
  if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  then
    n=$TIMEOUT
    while test -s $OLD_PIN && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    echo

    if test $n -lt 0 && test -s $OLD_PIN
    then
      echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
      exit 1
    fi
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  run "$CMD"
  ;;
reopen-logs)
  sig USR1
  ;;
*)
  echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  exit 1
  ;;
esac

Solution

  • I fixed my issue by adding the following to the top of my .bashrc:

    export PATH="$PATH:$HOME/.rvm/bin"
    
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"