当我尝试使用 Capistrano 重新启动独角兽时:
$ cap production deploy:restart_unicorn
我收到了这个错误:
DEBUG [c65b4a92] /usr/bin/env:
DEBUG [c65b4a92] ruby
DEBUG [c65b4a92] : No such file or directory
我的环境:
我的服务器环境:
我的config / deploy.rb:
lock '3.2.1'
set :application, 'my_app'
set :repo_url, 'git@gitrepo.com: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
我的独角兽初始化脚本:
#!/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
我的Gemfile:
# ...
gem 'capistrano', '~> 3.2.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rvm'
# ...
我的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 }
答案 0 :(得分:1)
我已经修复了问题,只需将 PATH 变量添加到我的unicorn init脚本中:
#!/bin/sh
set -e
. /etc/environment
PATH=/usr/local/rvm/rubies/ruby-2.1.2/bin:$PATH
TIMEOUT=${TIMEOUT-60}
# ...
答案 1 :(得分:0)
如果您使用rvm选择其中一个红宝石,则可能需要使用Capistrano's或RVM's宝石,因为它们会设置您错过的任何其他必要的红宝石路径。
并允许您根据需要使用rvm更新ruby。