[英]Rails deploy by Capistrano can't find installed bundler version
[英]Unicorn can't find bundler using capistrano
在部署時,我似乎無法讓捆綁器與unicorn一起工作。 我正在使用capistrano進行部署。
在部署時查看unicorn日志,我收到以下錯誤:
/home/deployer/apps/my-app/releases/20130417145122)
I, [2013-04-17T14:53:04.982369 #6565] INFO -- : forked child re-executing...
/home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler/definition.rb:16:in `build': /home/deployer/apps/my-app/releases/20130417020329/Gemfile not found (Bundler::GemfileNotFound)
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler.rb:148:in `definition'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
from /home/deployer/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
from /home/deployer/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/deployer/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
E, [2013-04-17T14:53:05.054942 #18166] ERROR -- : reaped #<Process::Status: pid 6565 exit 1> exec()-ed
Capistrano正在清理應用程序的最后5個版本,我看到Bundler正在嘗試訪問不存在的(最后刪除的)版本。
我發現這個代碼放在unicorn.rb.erb中,但它沒有幫助(我也試過硬編碼): http ://davidvollbracht.com/blog/headachenewunicorn-capistrano-bundler-usr2
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile"
end
在部署我的代碼之后,我啟動並停止了NGINX,並啟動並停止了獨角獸,但我遇到了同樣的問題。
關於堆棧溢出的原始帖子在這里,但我認為它與資產管道有關: 資產管道在rails生產環境中不起作用
思考?
這是我的unicorn.rb.erb文件:
working_directory "<%= current_path %>"
pid "<%= unicorn_pid %>"
stderr_path "<%= unicorn_log %>"
stdout_path "<%= unicorn_log %>"
listen "/tmp/unicorn.<%= application %>.sock"
worker_processes <%= unicorn_workers %>
timeout 30
preload_app true
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "<%= current_path %>/Gemfile"
end
before_fork do |server, worker|
# Disconnect since the database connection will not carry over
if defined? ActiveRecord::Base
ActiveRecord::Base.connection.disconnect!
end
# Quit the old unicorn process
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
# Start up the database connection again in the worker
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
這是我的unicorn_init.sh文件:
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/my-app/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 USR2 && 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
你應該使用Capistrano的bundler安裝任務,如果你還沒有: https : //github.com/carlhuda/bundler/blob/master/lib/bundler/capistrano.rb
gem部署將在部署時自動安裝在/ home / deployer / apps / my-app / shared / bundle目錄中,並在各個版本中保持不變。
我遇到了類似的問題,使用“before_fork”塊來設置BUNDLE_GEMFILE並沒有真正解決問題,盡管Rails應用程序認為ENV ['BUNDLE_GEMFILE']通過當前/符號鏈接指向Gemfile。
我仍然不完全理解它,但我們也在生產中使用RVM。 我設法通過添加以下內容來解決問題:
export BUNDLE_GEMFILE="${APP_ROOT}/Gemfile"
到init腳本。 這會解決你的問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.