質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

0回答

751閲覧

Unicornでwrong number of arguments (given 0, expected 1) (ArgumentError)

Meitoku

総合スコア44

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2021/05/24 09:17

編集2021/05/29 11:30

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2021/05/28 13:33

/var/www/baseball-app/current/config/unicorn.rb と unicorn起動のshellがあればそれも 見せてください。 [ -e /var/www/baseball-app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/baseball-app/shared/tmp/pids/unicorn.pid` の書かれているやつ
Meitoku

2021/05/29 00:14

ありがとうございます 追記しました
winterboum

2021/05/29 00:43

追記頂いたものがともに cat unicorn.pid とあるのですが、 下が cat unicorn.rb ですか? 上のは pid を表示されてるのでほしいものではないです。unicorn起動のshell はない? [ -e /var/www/baseball-app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/baseball-app/shared/tmp/pids/unicorn.pid` の書かれているやつ /var/www/baseball-app/shared か /var/www/baseball-app 部分は変数になっているかも、ですが
Meitoku

2021/05/29 04:23

すみません、初学者でよくわからないのですがNginxを使用しています Nginxの設定を貼り付けてみました 下がunicorn.rbです
winterboum

2021/05/29 08:05

deployの設定に書かれているのかな
Meitoku

2021/05/29 11:30

deploy.rbを追記しました
winterboum

2021/05/29 12:00

deployではなく、手動でunicorn起動するとどうなります?
Meitoku

2021/05/29 12:09

以下になります $bundle exec unicorn -E production -c config/unicorn.rb -D ArgumentError: config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/baseball-app/releases/current /var/www/baseball-app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory' config/unicorn.rb:8:in `reload'
winterboum

2021/05/29 12:11

気にしているのは、 [ -e /var/www/baseball-app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/baseball-app/shared/tmp/pids/unicorn.pid` がで終わっていることです。 「killしようとしたが該当するproccessがなくて失敗」 途中で失敗したので打ち切り になっているのでは?と ですので、killに失敗したときはそのあとどうしているのか?を見ようとしたのですが該当shell scriptを探し出すのが大変みたい なので、本質解決ではないですが、対症療法として /var/www/baseball-app/shared/tmp/pids/unicorn.pid を削除してからやり直してみてください
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問