前提・実現したいこと
capistrano自動デプロイを実行するとユニコーンの起動に失敗します。
初心者なので、エラーログを見てもよくわかりません。どのあたりに問題がありそうでしょうか?
###エラーに至るまでの経緯
始めはローカルで変更した箇所も本番に反映されていたのですが、途中から自動デプロイをしてもローカルのコードが本番で反映されなくなリました。
ユニコーンを再起動したらうまくいくと思ったので、ユニコーンのプロセスをキルしたらユニコーンが起動しなくなリました。
自動デプロイ時のエラーメッセージ
00:18 unicorn:start 01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/fleamarket-app_team-a/current/config/unicorn.rb -E production -D 01 master failed to start, check stderr log for details #<Thread:0x00007fb70c2d3708@/Users/shopuroguramingu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/shopuroguramingu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/shopuroguramingu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@54.150.222.152: bundle exit status: 1 (SSHKit::Runner::ExecuteError) bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@54.150.222.152: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details Caused by: SSHKit::Command::Failed: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details Tasks: TOP => unicorn:start (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@54.150.222.152: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: DEBUG [f087232e] Finished in 0.126 seconds with exit status 0 (successful). INFO [c1ccba0e] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate as ec2-user@54.150.222.152 DEBUG [c1ccba0e] Command: cd /var/www/fleamarket-app_team-a/releases/20200603130425 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate ) INFO [c1ccba0e] Finished in 2.387 seconds with exit status 0 (successful). INFO [5f1adf88] Running /usr/bin/env ln -s /var/www/fleamarket-app_team-a/releases/20200603130425 /var/www/fleamarket-app_team-a/releases/current as ec2-user@54.150.222.152 DEBUG [5f1adf88] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; /usr/bin/env ln -s /var/www/fleamarket-app_team-a/releases/20200603130425 /var/www/fleamarket-app_team-a/releases/current ) INFO [5f1adf88] Finished in 0.119 seconds with exit status 0 (successful). INFO [bcf905d8] Running /usr/bin/env mv /var/www/fleamarket-app_team-a/releases/current /var/www/fleamarket-app_team-a as ec2-user@54.150.222.152 DEBUG [bcf905d8] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; /usr/bin/env mv /var/www/fleamarket-app_team-a/releases/current /var/www/fleamarket-app_team-a ) INFO [bcf905d8] Finished in 0.134 seconds with exit status 0 (successful). DEBUG [eb50ee8c] Running if test ! -d /var/www/fleamarket-app_team-a/current; then echo "Directory does not exist '/var/www/fleamarket-app_team-a/current'" 1>&2; false; fi as ec2-user@54.150.222.152 DEBUG [eb50ee8c] Command: if test ! -d /var/www/fleamarket-app_team-a/current; then echo "Directory does not exist '/var/www/fleamarket-app_team-a/current'" 1>&2; false; fi DEBUG [eb50ee8c] Finished in 0.130 seconds with exit status 0 (successful). DEBUG [bcd0a582] Running [ -e /var/www/fleamarket-app_team-a/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/fleamarket-app_team-a/shared/tmp/pids/unicorn.pid` as ec2-user@54.150.222.152 DEBUG [bcd0a582] Command: [ -e /var/www/fleamarket-app_team-a/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/fleamarket-app_team-a/shared/tmp/pids/unicorn.pid` DEBUG [bcd0a582] bash: 0 行: kill: (23265) - そのようなプロセスはありません DEBUG [bcd0a582] Finished in 0.125 seconds with exit status 1 (failed). INFO [3cbf4ada] Running $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/fleamarket-app_team-a/current/config/unicorn.rb -E production -D as ec2-user@54.150.222.152 DEBUG [3cbf4ada] Command: cd /var/www/fleamarket-app_team-a/current && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/fleamarket-app_team-a/current/config/unicorn.rb -E production -D ) DEBUG [3cbf4ada] master failed to start, check stderr log for details
ユニコーンエラーログ/unicorn.stderr.log
I, [2020-05-29T02:25:49.185869 #27855] INFO -- : Refreshing Gem list bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn_rails) NoMethodError: undefined method `[]' for nil:NilClass 〜省略〜 I, [2020-05-29T07:55:24.503164 #4215] INFO -- : Refreshing Gem list I, [2020-05-29T07:55:26.863918 #4215] INFO -- : listening on addr=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock fd=11 I, [2020-05-29T07:55:26.869333 #4215] INFO -- : master process ready I, [2020-05-29T07:55:26.876546 #4224] INFO -- : worker=0 ready I, [2020-05-29T08:00:53.933953 #4215] INFO -- : reaped #<Process::Status: pid 4224 exit 0> worker=0 I, [2020-05-29T08:00:53.934411 #4215] INFO -- : master complete I, [2020-05-29T08:02:21.763422 #4336] INFO -- : Refreshing Gem list I, [2020-05-29T08:02:24.119314 #4336] INFO -- : unlinking existing socket=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock I, [2020-05-29T08:02:24.119471 #4336] INFO -- : listening on addr=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock fd=11 I, [2020-05-29T08:02:24.125424 #4336] INFO -- : master process ready I, [2020-05-29T08:02:24.130421 #4345] INFO -- : worker=0 ready I, [2020-05-29T08:06:59.601837 #4336] INFO -- : reaped #<Process::Status: pid 4345 exit 0> worker=0 I, [2020-05-29T08:06:59.602169 #4336] INFO -- : master complete I, [2020-05-29T08:07:48.364014 #4522] INFO -- : Refreshing Gem list I, [2020-05-29T08:07:50.739380 #4522] INFO -- : unlinking existing socket=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock I, [2020-05-29T08:07:50.739535 #4522] INFO -- : listening on addr=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock fd=11 I, [2020-05-29T08:07:50.745695 #4522] INFO -- : master process ready I, [2020-05-29T08:07:50.750820 #4531] INFO -- : worker=0 ready I, [2020-05-29T08:47:18.184987 #4522] INFO -- : reaped #<Process::Status: pid 4531 exit 0> worker=0 I, [2020-05-29T08:47:18.185318 #4522] INFO -- : master complete I, [2020-05-29T08:58:11.457875 #3275] INFO -- : Refreshing Gem list I, [2020-05-29T08:58:15.046829 #3275] INFO -- : unlinking existing socket=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock I, [2020-05-29T08:58:15.046999 #3275] INFO -- : listening on addr=/var/www/fleamarket-app_team-a/tmp/sockets/unicorn.sock fd=11 I, [2020-05-29T08:58:15.058898 #3275] INFO -- : master process ready I, [2020-05-29T08:58:15.065849 #3284] INFO -- : worker=0 ready I, [2020-05-29T12:54:56.504366 #3275] INFO -- : reaped #<Process::Status: pid 3284 exit 0> worker=0 I, [2020-05-29T12:54:56.504611 #3275] INFO -- : master complete
試したこと
・EC2サーバーでrails assets:precompile RAILS_ENV=production
をしてもユニコーンは起動しません。これは、恐らくcapistranoが邪魔してるだけかと思います。以前はcapistranoではユニコーンは起動できていました。
・本番環境のデーターベースは RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rake db:dropでリセットして、 rails db:create RAILS_ENV=productionで作り直したので、マイグレーションも通り、問題なさそうです。
・NginxやMySQLも再起動してみましたが、変化はなかったです。
・rubyのバージョンはローカルと本番環境共に2.0.2です。
あなたの回答
tips
プレビュー