0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

bundle exec unicorn_railsコマンドでのエラー

Posted at

はじめに

プログラミング初心者による備忘録です。

今回はEC2内でrailsサーバーを立ち上げようとした時に発生したエラーと解決できた方法を残します。

問題とエラーメッセージ

EC2内で以下のコマンドを実行。

$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D

すると以下のようなエラーが発生。

Your RubyGems version (3.0.3) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`
bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails)
Traceback (most recent call last):
	25: from /home/ec2-user/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
	24: from /home/ec2-user/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
	23: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/exe/bundle:33:in `<top (required)>'
	22: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	21: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/exe/bundle:45:in `block in <top (required)>'
	20: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli.rb:28:in `start'
	19: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	18: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli.rb:34:in `dispatch'
	17: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	16: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	15: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	14: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli.rb:491:in `exec'
	13: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli/exec.rb:23:in `run'
	12: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli/exec.rb:58:in `kernel_load'
	11: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.4.3/lib/bundler/cli/exec.rb:58:in `load'
	10: from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<top (required)>'
	 9: from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load'
	 8: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
	 7: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `new'
	 6: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `initialize'
	 5: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `new'
	 4: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:77:in `initialize'
	 3: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `reload'
	 2: from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:84:in `instance_eval'
	 1: from config/unicorn.rb:7:in `reload'
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory': config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current (ArgumentError)
master failed to start, check stderr log for details

原因

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

working_directory': config_file=config/unicorn.rb would not be accessible in working_directory=/var/www/current (ArgumentError)
この部分がエラーの原因を直接教えてくれています。

config_file=config/unicorn.rb
を探しているが
working_directory=/var/www/current
にありませんよ?と言っているわけです。

要するに
/var/www/current/config/unicorn.rbを探しています。
しかし実際は
/var/www/<アプリ名>/current/config/unicorn.rbにあります。
なので、このパスを指定している部分を治す必要があります。

解決方法

EC2アプリ内で以下のコマンドを実行

$ vi config/unicorn.rb

config/unicorn.rbが開かれますので

app_path = File.expand_path('../../../', __FILE__)

app_path = File.expand_path('../../', __FILE__)
に修正します。

これでパスの指定は問題ありません。

あとがき

受講スクールの記述を鵜呑みにして自分で考えていませんでした。
反省して、記述する内容はしっかり理解したものを実行していきます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?