1
votes

When I try to restart unicorn using Capistrano:

$ cap production deploy:restart_unicorn

I got this error:

DEBUG [c65b4a92]  /usr/bin/env:
DEBUG [c65b4a92]  ruby
DEBUG [c65b4a92]  : No such file or directory

My environment:

  • Mac OSX 10.9.2
  • Capistrano Version: 3.2.1 (Rake Version: 10.3.1)
  • rvm 1.25.25 (stable)
  • ruby 2.1.2p95
  • Rails 4.1.1
  • Bundler 1.6.2

My server environment:

  • Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

My config/deploy.rb:

lock '3.2.1'

set :application, 'my_app'
set :repo_url,    '[email protected]:my_app.git'
set :deploy_to,   '/var/www/my_app'

set :linked_files, %w{.env}
set :linked_dirs, %w{bin log tmp/pids tmp/cache public/system}
set :rvm_ruby_version, '2.1.2'

namespace :deploy do
  desc 'Restart application'
  task :restart_unicorn do
    on roles :app, in: :sequence, wait: 5 do
      execute 'service unicorn upgrade'
    end
  end

  after :publishing, :restart_unicorn
end

My unicorn init script:

#!/bin/sh
set -e
. /etc/environment

TIMEOUT=${TIMEOUT-60}
APP_ROOT=/var/www/my_app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="$APP_ROOT/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb -E $RAILS_ENV"
action="$1"
set -u

cd $APP_ROOT || exit 1

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

case $action in
restart)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  $CMD
  ;;
esac

My Gemfile:

# ...
gem 'capistrano', '~> 3.2.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rvm'
# ...

My Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'

require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
2

2 Answers

1
votes

I've fixed the problem just adding the PATH variable to my unicorn init script:

#!/bin/sh
set -e
. /etc/environment

PATH=/usr/local/rvm/rubies/ruby-2.1.2/bin:$PATH
TIMEOUT=${TIMEOUT-60}
# ...
0
votes

If you are using rvm to select one of your rubies you might want to use Capistrano's or RVM's gems as they will set up any other necessary ruby paths you missed.

And allow you to update ruby using rvm, as needed.