前提
Ruby on RailsのアプリをAWSのEC2にデプロイしています。
以前までIPアドレスにアクセスできていたのですが、Capistranoでデプロイしたりインスタンスの再起動をした後、アクセスできなくなってしまいました。
実現したいこと
アクセスできるようにしたい
発生している問題・エラーメッセージ
RAILS_SERVE_STATIC_FILES=1 unicorn_rails -c config/unicorn.rb -E production -D
$ less log/production.log D, [2022-07-01T21:10:08.488393 #15137] DEBUG -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] ESC[1mESC[35mCACHE (0.0ms)ESC[0m ESC[1mESC[34mSELECT `habits`.`id` FROM `habits`ESC[0m D, [2022-07-01T21:10:08.489166 #15137] DEBUG -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] ESC[1mESC[35m (0.2ms)ESC[0m ESC[1mESC[34mSELECT COUNT(*) FROM `likes` WHERE `likes`.`record_id` = 1ESC[0m I, [2022-07-01T21:10:08.489289 #15137] INFO -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] Rendered likes/_like.html.erb (Duration: 2.7ms | Allocations: 1052) I, [2022-07-01T21:10:08.489352 #15137] INFO -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] Rendered records/_record.html.erb (Duration: 6.4ms | Allocations: 2274) D, [2022-07-01T21:10:08.489560 #15137] DEBUG -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] ESC[1mESC[35mCACHE (0.0ms)ESC[0m ESC[1mESC[34mSELECT `habits`.`id` FROM `habits`ESC[0m D, [2022-07-01T21:10:08.489768 #15137] DEBUG -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] ESC[1mESC[35mCACHE (0.0ms)ESC[0m ESC[1mESC[34mSELECT `habits`.`id` FROM `habits`ESC[0m I, [2022-07-01T21:10:08.490098 #15137] INFO -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] Rendered habits/index.html.erb within layouts/application (Duration: 8.1ms | Allocations: 2762) I, [2022-07-01T21:10:08.491051 #15137] INFO -- : [2c2a1459-f6a9-4aa6-8765-9e9d7d14055c] Completed 200 OK in 10ms (Views: 7.5ms | ActiveRecord: 1.8ms | Allocations: 3825) I, [2022-07-01T21:10:08.616886 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Started GET "/habits.json?start=2022-06-26T00%3A00%3A00%2B09%3A00&end=2022-08-07T00%3A00%3A00%2B09%3A00" for 115.162.105.134 at 2022-07-01 21:10:08 +0000 I, [2022-07-01T21:10:08.617596 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Processing by HabitsController#index as JSON I, [2022-07-01T21:10:08.617663 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Parameters: {"start"=>"2022-06-26T00:00:00+09:00", "end"=>"2022-08-07T00:00:00+09:00"} I, [2022-07-01T21:10:08.618993 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Rendering habits/index.json.jbuilder D, [2022-07-01T21:10:08.619711 #15137] DEBUG -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] ESC[1mESC[36mRecord Load (0.3ms)ESC[0m ESC[1mESC[34mSELECT `records`.* FROM `records` ORDER BY created_at DESCESC[0m I, [2022-07-01T21:10:08.620090 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Rendered habits/index.json.jbuilder (Duration: 1.0ms | Allocations: 211) I, [2022-07-01T21:10:08.620289 #15137] INFO -- : [fff38768-f1df-4a39-b7da-226d9ed30efe] Completed 200 OK in 3ms (Views: 1.2ms | ActiveRecord: 0.3ms | Allocations: 820) (END)
該当のソースコード
unicorn.rb
#サーバ上でのアプリケーションコードが設置されているディレクトリを変数に入れておく app_path = File.expand_path('../../../', __FILE__) #アプリケーションサーバの性能を決定する worker_processes 1 #アプリケーションの設置されているディレクトリを指定 working_directory "#{app_path}/current" #Unicornの起動に必要なファイルの設置場所を指定 pid "#{app_path}/shared/tmp/pids/unicorn.pid" #ポート番号を指定 listen "#{app_path}/shared/tmp/sockets/unicorn.sock" #エラーのログを記録するファイルを指定 stderr_path "#{app_path}/shared/log/unicorn.stderr.log" #通常のログを記録するファイルを指定 stdout_path "#{app_path}/shared/log/unicorn.stdout.log" #Railsアプリケーションの応答を待つ上限時間を設定 timeout 60 #以下は応用的な設定なので説明は割愛 preload_app true GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true check_client_connection false run_once = true before_fork do |server, worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! if run_once run_once = false # prevent from firing again end old_pid = "#{server.config[:pid]}.oldbin" if File.exist?(old_pid) && server.pid != old_pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH => e logger.error e end end end after_fork do |_server, _worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection end
Capfile
require "capistrano/setup" require "capistrano/deploy" require 'capistrano/rbenv' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' require 'capistrano3/unicorn' Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
試したこと
・インスタンスの再起動
・他デバイスでのアクセス
補足情報(FW/ツールのバージョンなど)
Rails 6.0.4.1
EC2
Unicorn
Nginx
デプロイとunicornの起動も異常なくできていると思っているのですが、エラーを見落としているのでしょうか?または- リストEC2の設定に問題があるのでしょうか?
回答1件
あなたの回答
tips
プレビュー