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

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

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

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

Q&A

解決済

1回答

1246閲覧

bundle exec unicorn時にエラーが発生してunicornを立ち上げる事ができなくなってしまいました。

emon2943

総合スコア4

unicorn

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

0グッド

0クリップ

投稿2020/04/02 01:57

前提・実現したいこと

ここに質問の内容を詳しく書いてください。

unicornrails/Nginx/capistranoを利用して本番環境への自動デプロイを行いました。
一度は、正常にアクセスできるようになりましたが、背景画像が正しく反映されておらず
ファイルを更新する必要があったため、ローカルで作業を更新を行いました。

その後、本番環境ターミナルでgit pull origin maseter 後、bundle installを行い、
unicorn rails のプロセスを切断し、再度立ち上げようとした所bundler: failed to load command: unicorn (/home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn)というエラーが発生し解消ができなくなってしまいました。

ArgumentError: config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current とでていた為、コマンド入力をしている場所がよくないと思い、cd /var/レポじとり名/を行い再度bundle exec unicorn -c config/unicorn.rb -E production -D を入力しましたが解消にいたりませんでした。

デプロイ経験が浅い為、英文内容の理解が薄かったり、必要情報がかけている部分がある可能性がありますが、
解消方法についてご教示いただけいただけますと幸いです。

どうぞよろしくおねがいいたします。

発生している問題・エラーメッセージ

本番環境ターミナル(ec2-user@)

[ec2-user@ip-172-31-47-102 English_App3]$ bundle exec unicorn -c config/unicorn.rb -E production -D bundler: failed to load command: unicorn (/home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn) ArgumentError: config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory' config/unicorn.rb:8:in `reload' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `instance_eval' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `reload' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:77:in `initialize' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `new' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `initialize' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/bin/unicorn:126:in `new' /home/ec2-user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>' /home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn:23:in `load' /home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn:23:in `<top (required)>' master failed to start, check stderr log for details

該当のソースコード

本番環境ターミナル(ec2-user@)budle install時

https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/ [ec2-user@ip-172-31-47-102 ~]$ cd /var/www/ [ec2-user@ip-172-31-47-102 www]$ cd /var/www/English_App3/ [ec2-user@ip-172-31-47-102 English_App3]$ bundle exec rake assets:precompile RAILS_ENV=production Yarn executable was not detected in the system. Download Yarn at https://yarnpkg.com/en/docs/install [ec2-user@ip-172-31-47-102 English_App3]$ git pull origin master remote: Enumerating objects: 27, done. remote: Counting objects: 100% (27/27), done. remote: Compressing objects: 100% (13/13), done. remote: Total 20 (delta 10), reused 15 (delta 7), pack-reused 0 Unpacking objects: 100% (20/20), done. From https://github.com/holy2943/English_App3 * branch master -> FETCH_HEAD d8192d1..638bb9c master -> origin/master Updating d8192d1..638bb9c Fast-forward Capfile | 9 +++++++++ Gemfile | 9 +++++++++ Gemfile.lock | 28 ++++++++++++++++++++++++++++ README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++--------------------- config/deploy.rb | 34 ++++++++++++++++++++++++++++++++++ config/deploy/production.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config/deploy/staging.rb | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config/environments/production.rb | 2 +- config/unicorn.rb | 13 ++++++------- 9 files changed, 254 insertions(+), 29 deletions(-) create mode 100644 Capfile create mode 100644 config/deploy.rb create mode 100644 config/deploy/production.rb create mode 100644 config/deploy/staging.rb [ec2-user@ip-172-31-47-102 English_App3]$ bundle exec rake assets:precompile RAILS_ENV=production Could not find net-ssh-5.2.0 in any of the sources Run `bundle install` to install missing gems. [ec2-user@ip-172-31-47-102 English_App3]$ bundle install The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Fetching gem metadata from https://rubygems.org/......... Using rake 13.0.1 Using concurrent-ruby 1.1.6 Using i18n 1.8.2 Using minitest 5.14.0 Using thread_safe 0.3.6 Using tzinfo 1.2.6 Using activesupport 5.2.4.1 Using builder 3.2.4 Using erubi 1.9.0 Using mini_portile2 2.4.0 Using nokogiri 1.10.8 Using rails-dom-testing 2.0.3 Using crass 1.0.6 Using loofah 2.4.0 Using rails-html-sanitizer 1.3.0 Using actionview 5.2.4.1 Using rack 2.2.2 Using rack-test 1.1.0 Using actionpack 5.2.4.1 Using nio4r 2.5.2 Using websocket-extensions 0.1.4 Using websocket-driver 0.7.1 Using actioncable 5.2.4.1 Using globalid 0.4.2 Using activejob 5.2.4.1 Using mini_mime 1.0.2 Using mail 2.7.1 Using actionmailer 5.2.4.1 Using activemodel 5.2.4.1 Using arel 9.0.0 Using activerecord 5.2.4.1 Using mimemagic 0.3.4 Using marcel 0.3.3 Using activestorage 5.2.4.1 Using public_suffix 4.0.3 Using addressable 2.7.0 Fetching net-ssh 5.2.0 Installing net-ssh 5.2.0 Fetching net-scp 2.0.0 Installing net-scp 2.0.0 Fetching sshkit 1.21.0 Installing sshkit 1.21.0 Fetching airbrussh 1.4.0 Installing airbrussh 1.4.0 Using io-like 0.3.1 Using archive-zip 0.12.0 Using bindex 0.8.1 Using msgpack 1.3.3 Using bootsnap 1.4.5 Using bundler 2.1.0 Using byebug 11.1.1 Fetching capistrano 3.12.1 Installing capistrano 3.12.1 Fetching capistrano-bundler 1.6.0 Installing capistrano-bundler 1.6.0 Fetching capistrano-rails 1.4.0 Installing capistrano-rails 1.4.0 Fetching capistrano-rbenv 2.1.6 Installing capistrano-rbenv 2.1.6 Fetching capistrano3-unicorn 0.2.1 Installing capistrano3-unicorn 0.2.1 Using regexp_parser 1.6.0 Using xpath 3.2.0 Using capybara 3.31.0 Using childprocess 3.0.0 Using chromedriver-helper 2.1.1 Using coderay 1.1.2 Using coffee-script-source 1.12.2 Using execjs 2.7.0 Using coffee-script 2.4.1 Using method_source 0.9.2 Using thor 1.0.1 Using railties 5.2.4.1 Using coffee-rails 4.2.2 Using declarative 0.0.10 Using declarative-option 0.1.0 Using multipart-post 2.1.1 Using faraday 1.0.0 Using ffi 1.12.2 Using jwt 2.2.1 Using memoist 0.16.2 Using multi_json 1.14.1 Using os 1.0.1 Using signet 0.13.0 Using googleauth 0.11.0 Using httpclient 2.8.3 Using uber 0.1.0 Using representable 3.0.4 Using retriable 3.1.2 Using google-api-client 0.37.1 Using jbuilder 2.10.0 Using jquery-rails 4.3.5 Using kgio 2.11.3 Using rb-fsevent 0.10.3 Using rb-inotify 0.10.1 Using ruby_dep 1.5.0 Using listen 3.1.5 Using mysql2 0.5.3 Using pry 0.12.2 Using pry-rails 0.3.9 Using puma 3.12.4 Using sprockets 3.7.2 Using sprockets-rails 3.2.1 Using rails 5.2.4.1 Using raindrops 0.19.1 Using rubyzip 2.2.0 Using sass-listen 4.0.0 Using sass 3.7.4 Using tilt 2.0.10 Using sass-rails 5.1.0 Using selenium-webdriver 3.142.7 Using spring 2.1.0 Using spring-watcher-listen 2.0.1 Using uglifier 4.2.0 Using unicorn 5.4.1 Using web-console 3.7.0 Bundle complete! 26 Gemfile dependencies, 107 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed.

試したこと


英文エラーbundler: failed to load command: unicorn (/home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn)から本番環境にインストールされているgemやファイルにローカル環境とバージョンの際があると仮説を立てて、本番環境とローカル環境の ruby, bundler, unicorn,についてバージョンを比較。

ローカル環境のunicornのバージョンを上げてようとするも、正しいコマンドが分からず、エラーとなってしまう。
bundle update 'unicorn', '5.4.1'
bundle update unicorn '5.4.1'
bundle update ["unicorn", "v5.4.1"]
bundle update unicorn -v "5.4.1"


https://teratail.com/questions/229963 を参考にローカルのconfig/uncorn.rbを確認してunicornの設定ファイルの場所を確認。

#アプリケーションの設置されているディレクトリを指定 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"

補足情報(FW/ツールのバージョンなど)

本番環境
Bundler version 2.1.0
ruby 2.5.1
unicorn v5.4.1

ローカル環境
Bundler version 2.1.0
ruby 2.5.1
unicorn v5.5.1

ここにより詳細な情報を記載してください。

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

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

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

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

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

guest

回答1

0

自己解決

bundle exec unicorn -c /var/www/English_App3/current/config/unicorn.rb -E production -Dで実施をした所、正常に起動を行う事ができました。

エラー文の
config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current
を再度読み直し、起動しようとしていたディレクトリに誤りがある事がわかりました。

Capistranoで自動デプロイを行なった結果、ディレクトリ構成が変わっていた事が原因でconfig/unicorn.rb
で起動しようとしてもエラーが出ていたようです。

投稿2020/04/02 06:19

emon2943

総合スコア4

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問