前提・実現したいこと
Capistranoを用いた自動デプロイをできるようにしたい。
現在自動デプロイを行うためにCapistranoを実装し、デプロイを行いました。
しかしデプロイの途中で止まってしまい、困っています。
発生している問題・エラーメッセージ
00:16 unicorn:start 01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/kirakushare/current/config/unicorn.rb -E deployment -D 01 master failed to start, check stderr log for details Traceback (most recent call last): 1: from /Users/名前/.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/名前/.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.130.49: 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.130.49: 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.130.49: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details
I, [2020-07-13T03:52:52.131759 #27451] INFO -- : Refreshing Gem list I, [2020-07-13T03:52:54.316008 #27451] INFO -- : listening on addr=0.0.0.0:3000 fd=10 E, [2020-07-13T03:52:54.378921 #27451] ERROR -- : Unknown database 'kirakushare_production' (ActiveRecord::NoDatabaseError) /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/mysql2_adapter.rb:26:in `rescue in mysql2_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/mysql2_adapter.rb:12:in `mysql2_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.4.3/lib/active_record/connection_handling.rb:90:in `connection' config/unicorn.rb:35:in `block in reload' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:543:in `spawn_missing_workers' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:142:in `start' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>' /home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn_rails:23:in `load' /home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn_rails:23:in `<top (required)>' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
該当のソースコード
ruby
1app_path = File.expand_path('../../../', __FILE__) 2 3worker_processes 1 4 5working_directory "#{app_path}/current" 6pid "#{app_path}/shared/tmp/pids/unicorn.pid" 7listen "#{app_path}/shared/tmp/sockets/unicorn.sock" 8stderr_path "#{app_path}/shared/log/unicorn.stderr.log" 9stdout_path "#{app_path}/shared/log/unicorn.stdout.log" 10 11timeout 60 12 13 14preload_app true 15GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true 16 17check_client_connection false 18 19run_once = true 20 21before_fork do |server, worker| 22 defined?(ActiveRecord::Base) && 23 ActiveRecord::Base.connection.disconnect! 24 25 if run_once 26 run_once = false # prevent from firing again 27 end 28 29 old_pid = "#{server.config[:pid]}.oldbin" 30 if File.exist?(old_pid) && server.pid != old_pid 31 begin 32 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU 33 Process.kill(sig, File.read(old_pid).to_i) 34 rescue Errno::ENOENT, Errno::ESRCH => e 35 logger.error e 36 end 37 end 38end 39 40after_fork do |_server, _worker| 41 defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection 42end
試したこと
エラーログに
Unknown database 'kirakushare_production' (ActiveRecord::NoDatabaseError)
との記載があるので、
AILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rake db:drop ```を実行し、削除して再度 ```ruby rails db:create RAILS_ENV=production ```を行った。 ### 補足情報(FW/ツールのバージョンなど)
あなたの回答
tips
プレビュー