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

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

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

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

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Q&A

解決済

1回答

6832閲覧

デプロイ後、unicornの起動時にworking_directoryが参照されない

minalo

総合スコア6

unicorn

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

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

0グッド

1クリップ

投稿2019/12/16 18:44

前提・実現したいこと

現在、チーム開発で完成したWEBアプリをチーム各個人毎のEC2サーバーで立ち上げる作業をしております。

EC2サーバーにデプロイを行ったあと、ユニコーンを立ち上げる際に以下のエラーメッセージが発生しました。

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

bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.5.1/bin/unicorn_rails) 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:5: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_rails:209:in `new' /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)>' master failed to start, check stderr log for details

該当のソースコード

config/unicorn.rb

#サーバ上でのアプリケーションコードが設置されているディレクトリを変数に入れておく # ../が一つ増えている app_path = File.expand_path('../../../', __FILE__) #アプリケーションサーバの性能を決定する worker_processes 1 #アプリケーションの設置されているディレクトリを指定 # currentを指定 working_directory "#{app_path}/current" # それぞれ、sharedの中を参照するよう変更 #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" ~~~後略

shared/log/unicorn.stderr.log

I, [2019-12-16T18:08:05.907242 #4722] INFO -- : Refreshing Gem list I, [2019-12-16T18:08:08.276922 #4722] INFO -- : listening on addr=/var/www/myAPP/shared/tmp/sockets/unicorn.sock fd=8 I, [2019-12-16T18:08:08.282860 #4722] INFO -- : master process ready I, [2019-12-16T18:08:08.291125 #4726] INFO -- : worker=0 ready I, [2019-12-16T18:08:08.515852 #4756] INFO -- : executing ["/var/www/myapp/shared/bundle/ruby/2.5.0/bin/unicorn", "-c", "/var/www/myapp/current/config/unicorn.rb", "-E", "production", "-D", {8=>#<Kgio::UNIXServer:/var/www/myapp/shared/tmp/sockets/unicorn.sock>}] (in /var/www/myapp/releases/20191216180611) I, [2019-12-16T18:08:08.515952 #4756] INFO -- : forked child re-executing... I, [2019-12-16T18:08:08.832267 #4756] INFO -- : inherited addr=/var/www/myapp/shared/tmp/sockets/unicorn.sock fd=8 I, [2019-12-16T18:08:08.832490 #4756] INFO -- : Refreshing Gem list I, [2019-12-16T18:08:11.125396 #4756] INFO -- : master process ready I, [2019-12-16T18:08:11.129116 #4798] INFO -- : worker=0 ready I, [2019-12-16T18:08:11.218315 #4722] INFO -- : reaped #<Process::Status: pid 4726 exit 0> worker=0 I, [2019-12-16T18:08:11.218411 #4722] INFO -- : master complete I, [2019-12-16T18:08:49.460777 #4756] INFO -- : reaped #<Process::Status: pid 4798 exit 0> worker=0 I, [2019-12-16T18:08:49.460900 #4756] INFO -- : master complete

試したこと

lsコマンドでcurrentフォルダの存在を確認しました。

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

ruby 2.5.1
Rails 5.2.3
unicorn 5.4.1

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

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

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

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

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

winterboum

2019/12/17 00:26

1)deployの手段は何を使っていますか データの構造が分からないので 2) app_path 直下のfile、dirを教えてください 3) app_path/current 直下のfile,dirを教えてください。 4) unicorn.rb のfull path(/からのpath)を教えてください
minalo

2019/12/17 07:26

情報が不足しており申し訳ございません。 1. deployにはCapistranoを使用しております。 2. app_path直下のfile,dirは Capfile Gemfile.lock Rakefile bin config.ru db log public repo server.crt server.key spec test vendor Gemfile README.md app config current lib package.json releases revisions.log server.csr shared storage tmp となっております。 3.app_path/current直下のfile,dirは Capfile Gemfile.lock REVISION app bin config.ru lib package.json spec test vendor Gemfile README.md Rakefile assets_manifest_backup config db log public storage tmp 以上になっております。 4.unicornのfull_pathは current/config/unicorn.rbです。
winterboum

2019/12/17 07:33

4 は相対pathです。/ からのfullpathでください。  あと追加ですが、app_path の定義も念の為ください 2,3の中身が一緒なのがおかしいのですが。 Capistrano をつかった場合私の経験では app_dirの下に current releases 及び設定によっては shared があり、 currentは実際は releasesの下のdirへのsynbolic linkなのですが。 app_pathの直下のは何かの間違いでできたとして、上の質問への答えで様子が判るかと思います
minalo

2019/12/17 07:46

4の回答なのですが /var/www/myapp/current/config/unicorn.rbでした。 申し訳ございません。 app_pathの定義はapp_path = File.expand_path('../../../', __FILE__)です。 自動デプロイ後、currentフォルダのunicorn.rbを参照すると理解していたため 上記の記述にしました。
winterboum

2019/12/17 07:49

app_pathの定義は /var/www/myapp/current/config/unicorn.rb に書かれているのですね?
minalo

2019/12/17 07:51

はい。 そういった意図で記述しております。 情報が不足しており、申し訳ございません。。。
winterboum

2019/12/17 07:55 編集

回答に書きます
guest

回答1

0

ベストアンサー

working_directory=/var/www/current の config_file=config/unicorn.rb にアクセス出来ないというエラーです。
/var/www/current/config/unicorn.rb を探しに行っています。
でも実際は /var/www/myapp/current/config/unicorn.rb にあります。
なのでこのエラーとなっています
unicorn起動の指示部分を再確認してください

投稿2019/12/17 07:55

winterboum

総合スコア23329

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

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

minalo

2019/12/17 07:58

unicorn起動時のコマンドが間違っておりました。。。 ありがとうございます。 ただ、 bundle exec unicorn -c current/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=current/config/unicorn.rb would not be accessible in working_directory=/var/www/freemarket_sample_54b/current
winterboum

2019/12/17 08:01

current に cd して bundle exec unicorn -c config/unicorn.rb -E production -D してみてください
winterboum

2019/12/17 08:03 編集

ん?  駄目だったら /var/www/myapp にて ls -l current ls -l current/config の結果もください
minalo

2019/12/17 08:11

currentにcdしてbundle exec unicorn -c config/unicorn.rb -E production -Dを行ったところ bundler: failed to load command: unicorn (/var/www/myapp/shared/bundle/ruby/2.5.0/bin/unicorn) ArgumentError: config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/myapp/releases/current 上記のエラーが発生しました。 ls -l current の結果 lrwxrwxrwx 1 ec2-user ec2-user 54 12月 16 18:08 current -> /var/www/myapp/releases/20191216180611 ls -l current/config の結果 -rw-rw-r-- 1 ec2-user ec2-user 1539 11月 28 11:36 application.rb -rw-rw-r-- 1 ec2-user ec2-user 207 11月 28 11:36 boot.rb -rw-rw-r-- 1 ec2-user ec2-user 2691 11月 28 11:36 breadcrumbs.rb -rw-rw-r-- 1 ec2-user ec2-user 203 11月 28 11:36 cable.yml -rw-rw-r-- 1 ec2-user ec2-user 1088 11月 28 11:36 credentials.yml.enc -rw-rw-r-- 1 ec2-user ec2-user 1727 11月 28 11:36 database.yml drwxrwxr-x 2 ec2-user ec2-user 4096 11月 28 11:36 deploy -rw-rw-r-- 1 ec2-user ec2-user 3097 11月 28 11:36 deploy.rb -rw-rw-r-- 1 ec2-user ec2-user 128 11月 28 11:36 environment.rb drwxrwxr-x 2 ec2-user ec2-user 4096 11月 28 11:36 environments drwxrwxr-x 2 ec2-user ec2-user 4096 11月 28 11:36 initializers drwxrwxr-x 2 ec2-user ec2-user 4096 11月 28 11:36 locales lrwxrwxrwx 1 ec2-user ec2-user 55 12月 16 18:06 master.key -> /var/www/myapp/shared/config/master.key -rw-rw-r-- 1 ec2-user ec2-user 1550 11月 28 11:36 puma.rb -rw-rw-r-- 1 ec2-user ec2-user 2599 11月 28 11:36 routes.rb -rw-rw-r-- 1 ec2-user ec2-user 111 11月 28 11:36 spring.rb -rw-rw-r-- 1 ec2-user ec2-user 1096 11月 28 11:36 storage.yml -rw-rw-r-- 1 ec2-user ec2-user 1774 11月 28 11:36 unicorn.rb お手間をとらせてしまい、申し訳ございません。。。
winterboum

2019/12/17 08:21

どうもおかしいなぁ。どこからworking_directory=/var/www/myapp/releases/current などというpathが出てくるのだ。 いっそfull pathで指定しますか ${app_path}/current/config/unicorn.conf
minalo

2019/12/17 09:53 編集

app_pathを定義し直したところ、unicornが起動しました。 長々とお付き合いしていただき、ありがとうございました!
j30st

2020/03/29 09:37

すみません。おそらく同じエラーが起きているのですが、app_pathをどのように定義し直したのでしょうか。ご教示いただければ幸いです。
koya1613

2020/12/13 16:18

今更かと思いますが、今後これを見られる方のためにコメント残します。 自分も同じエラーが起きたのですが、 app_path = File.expand_path('../../../', __FILE__)を app_path = File.expand_path('../../', __FILE__)に定義し直したところ解消しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問