Capistranoでデプロイしているときにunicornが起動しません
タイトルのエラーが発生しています
###unicorn.stderr.logのエラーログ
4行目にエラー
I, [2021-05-24T01:19:39.291927 #22137] INFO -- : Refreshing Gem list I, [2021-05-24T01:19:41.769613 #22137] INFO -- : unlinking existing socket=/var/www/baseball-app/current/tmp/sockets/unicorn.sock I, [2021-05-24T01:19:41.770129 #22137] INFO -- : listening on addr=/var/www/baseball-app/current/tmp/sockets/unicorn.sock fd=10 E, [2021-05-24T01:19:41.774618 #22137] ERROR -- : wrong number of arguments (given 0, expected 1) (ArgumentError) /var/www/baseball-app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:139:in `logger' /var/www/baseball-app/current/config/unicorn.rb:41:in `rescue in block in reload' /var/www/baseball-app/current/config/unicorn.rb:37:in `block in reload' /var/www/baseball-app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:543:in `spawn_missing_workers' /var/www/baseball-app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:142:in `start' /var/www/baseball-app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>' /var/www/baseball-app/shared/bundle/ruby/2.5.0/bin/unicorn:23:in `load' /var/www/baseball-app/shared/bundle/ruby/2.5.0/bin/unicorn: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' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>' /home/ec2-user/.rbenv/versions/2.5.1/bin/bundle:23:in `load' /home/ec2-user/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
調べたこと
こちらを見てみたのですが、バージョンは最初から5.4.1なので当てはまらないのではと思います
###デプロイ失敗のエラー
02:52 unicorn:start 01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/baseball-app/current/config/unicorn.rb -E deployment -D 01 master failed to start, check stderr log for details #<Thread:0x00007fd563925528@/Users/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@18.180.246.163: 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@18.180.246.163: 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@18.180.246.163: 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 [c054cc75] Finished in 0.564 seconds with exit status 0 (successful). INFO [e8e707f7] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate as ec2-user@18.180.246.163 DEBUG [e8e707f7] Command: cd /var/www/baseball-app/releases/20210524090514 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate ) INFO [e8e707f7] Finished in 4.744 seconds with exit status 0 (successful). INFO [149f9e8b] Running /usr/bin/env ln -s /var/www/baseball-app/releases/20210524090514 /var/www/baseball-app/releases/current as ec2-user@18.180.246.163 DEBUG [149f9e8b] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; /usr/bin/env ln -s /var/www/baseball-app/releases/20210524090514 /var/www/baseball-app/releases/current ) INFO [149f9e8b] Finished in 0.503 seconds with exit status 0 (successful). INFO [12ea3a08] Running /usr/bin/env mv /var/www/baseball-app/releases/current /var/www/baseball-app as ec2-user@18.180.246.163 DEBUG [12ea3a08] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; /usr/bin/env mv /var/www/baseball-app/releases/current /var/www/baseball-app ) INFO [12ea3a08] Finished in 0.532 seconds with exit status 0 (successful). DEBUG [b32625b8] Running if test ! -d /var/www/baseball-app/current; then echo "Directory does not exist '/var/www/baseball-app/current'" 1>&2; false; fi as ec2-user@18.180.246.163 DEBUG [b32625b8] Command: if test ! -d /var/www/baseball-app/current; then echo "Directory does not exist '/var/www/baseball-app/current'" 1>&2; false; fi DEBUG [b32625b8] Finished in 0.551 seconds with exit status 0 (successful). DEBUG [4a38b76e] Running [ -e /var/www/baseball-app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/baseball-app/shared/tmp/pids/unicorn.pid` as ec2-user@18.180.246.163
追記
k
cat unicorn.rb
#サーバ上でのアプリケーションコードが設置されているディレクトリを変数に入れておく app_path = File.expand_path('../../../', __FILE__) #アプリケーションサーバの性能を決定する worker_processes 1 #アプリケーションの設置されているディレクトリを指定 working_directory "#{app_path}/current" #Unicornの起動に必要なファイルの設置場所を指定 listen "#{app_path}/shared/tmp/sockets/unicorn.sock" pid "#{app_path}/shared/tmp/pids/unicorn.pid" stderr_path "#{app_path}/shared/log/unicorn.stderr.log" stdout_path "#{app_path}/shared/log/unicorn.stdout.log" 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
Nginx
upstream app_server { # sharedの中を参照するよう変更 server unix:/var/www/baseball-app/shared/tmp/sockets/unicorn.sock; } server { listen 80; server_name ***伏せ字; # クライアントからアップロードされてくるファイルの容量の上限を2ギガに設定。デフォルトは1メガなので大きめにしておく client_max_body_size 2g; # currentの中を参照するよう変更 root /var/www/baseball-app/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; # currentの中を参照するよう変更 root /var/www/baseball-app/current/public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } error_page 500 502 503 504 /500.html; }
deploy.rb
# config valid only for current version of Capistrano # capistranoのバージョンを記載。固定のバージョンを利用し続け、バージョン変更によるトラブルを防止する # lock '3.14.1' lock '3.16.0' # Capistranoのログの表示に利用する set :application, '***' # どのリポジトリからアプリをpullするかを指定する set :repo_url, 'git@github.com:***' # バージョンが変わっても共通で参照するディレクトリを指定 set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') set :rbenv_type, :user set :rbenv_ruby, '2.5.1' # どの公開鍵を利用してデプロイするか set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/***.pem'] # プロセス番号を記載したファイルの場所 set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } # Unicornの設定ファイルの場所 set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } set :keep_releases, 5 # デプロイ処理が終わった後、Unicornを再起動するための記述 after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:stop' invoke 'unicorn:start' end end
あなたの回答
tips
プレビュー