AWSでのデプロイについて
解決したいこと
ポートフォリオサイトをデプロイしようとしていたのですが、unicornを起動したところ、エラーが出てうまくサーバーが立ち上がりません。
開発環境
aws cloud9
ruby 2.6.3
Rails 6.0.3
unicorn 5.4.1
発生している問題・エラー
/home/ec2-user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=': Already running on PID:29842 (or pid=/var/www/baseball_app/tmp/pids/unicorn.pid is stale) (ArgumentError)
from /home/ec2-user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
from /home/ec2-user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
from /home/ec2-user/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `load'
from /home/ec2-user/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `<main>'
I, [2022-01-10T13:45:25.432870 #29842] INFO -- : reaped #<Process::Status: pid 29844 exit 0> worker=0
I, [2022-01-10T13:45:25.432989 #29842] INFO -- : reaped #<Process::Status: pid 29845 exit 0> worker=1
I, [2022-01-10T13:45:25.433049 #29842] INFO -- : master complete
I, [2022-01-10T13:45:48.639677 #30564] INFO -- : Refreshing Gem list
I, [2022-01-10T13:45:50.888389 #30564] INFO -- : unlinking existing socket=/var/www/baseball_app/tmp/sockets/unicorn.sock
I, [2022-01-10T13:45:50.888602 #30564] INFO -- : listening on addr=/var/www/baseball_app/tmp/sockets/unicorn.sock fd=9
I, [2022-01-10T13:45:50.894775 #30564] INFO -- : master process ready
I, [2022-01-10T13:45:50.898329 #30567] INFO -- : worker=1 ready
I, [2022-01-10T13:45:50.899697 #30566] INFO -- : worker=0 ready
該当するソースコード
unicorn.rb
# rootパスのディレクトリを指定
root_path = File.expand_path('../../', __FILE__)
# アプリケーションサーバの性能を決定する
worker_processes 2
# アプリケーションの設置されているディレクトリを指定
working_directory root_path
# プロセスIDの保存先を指定
pid "#{root_path}/tmp/pids/unicorn.pid"
# ポート番号を指定
listen "#{root_path}/tmp/sockets/unicorn.sock"
# エラーのログを記録するファイルを指定
stderr_path "#{root_path}/log/unicorn.stderr.log"
# 通常のログを記録するファイルを指定
stdout_path "#{root_path}/log/unicorn.stdout.log"
#応答時間を待つ上限時間を設定
timeout 30
# ダウンタイムなしでUnicornを再起動時する
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
database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: baseball_app_production
username: root
password: <%= ENV['DATABASE_PASSWORD'] %>
socket: /var/lib/mysql/mysql.sock
secrets.yml
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
development:
secret_key_base: 9f480ef386f1a6f117fd4338c99ae0c2c9f8ce273e9f0cba06c39f307a77f6e1bd884f3e557caa55fdc3fcee654a679ae4210ce825a1cd78a0d47dde620abbef
test:
secret_key_base: e52bace9b051a540e8dcef4b1696ff1a3ee6789a8aba22330bc541fecf4d0172ec8cc6cb9f9e94e55624eac4e0c62683d59a7cda9e24f427a34b56ae06367060
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
aws:
access_key_id: 123
#=> Rails.application.credentials.aws[:access_key_id]
secret_key_base: 9f480ef386f1a6f117fd4338c99ae0c2c9f8ce273e9f0cba06c39f307a77f6e1bd884f3e557caa55fdc3fcee654a679ae4210ce825a1cd78a0d47dde620abbef
#=> Rails.application.credentials.secret_key_base
自分で試したこと
gemのアップデートやサーバーの再起動を試みましたが、どれも解決には至りませんでした。
初歩的な質問かもしてないですが、何かわかる方がおられましたら、コメントよろしくお願いいたします。
0