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 3 years have passed since last update.

筆者がエラーに苦しんだ備忘録【bundler: failed to load command: unicorn NameError: uninitialized constant Model】

Last updated at Posted at 2020-10-13

初めに

この問題は解決済みです。
多分特例すぎて誰の参考にもならないです。
質問フォーマットに記入してたら、エラーの原因に気づいて解決しました。
筆者の備忘録として残してあります。

感想

エラー文を全部読みましょう。
でも、bundler: failed to load command: unicornって言われたら、unicorn疑っちゃう。。。
一行下のNameError: uninitialized constant Modelが超大事でした。
なんでローカル環境で起動しちゃうんですか〜
せめてエラー検知してくれ〜〜

前提・実現したいこと

Railsで開発したアプリをCapistranoを使用してデプロイしようとしましたが、
unicorn:startコマンドで必ず失敗します。
エラーを解決して、正しくunicornが起動できるようなりデプロイすることがゴールです。

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

以前、capistranoでデプロイできていたのですが、1週間ほど空いた後にデプロイしたら、今回のエラーが発生しました。
デプロイしてない間に一部ソースコードは編集しました。

capistranoのエラー文

00:52 unicorn:start
      01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/MyNote/current/config/unicorn.rb -E deployment -D 
      01 master failed to start, check stderr log for details
# <Thread:0x00007fbbfb37a690@/Users/ohishikaido/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from /Users/ohishikaido/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/ohishikaido/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@54.150.220.39: 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@54.150.220.39: 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@54.150.220.39: 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 [2632c234] Finished in 0.563 seconds with exit status 0 (successful).

 DEBUG [b61a7332] Running [ -e /var/www/MyNote/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/MyNote/shared/tmp/pids/unicorn.pid` as ec2-user@54.150.220.39

 DEBUG [b61a7332] Command: [ -e /var/www/MyNote/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/MyNote/shared/tmp/pids/unicorn.pid`

 DEBUG [b61a7332]       bash: 0 行: kill: (21662) - そのようなプロセスはありません

 DEBUG [b61a7332] Finished in 0.565 seconds with exit status 1 (failed).

  INFO [d82915ac] Running $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/MyNote/current/config/unicorn.rb -E deployment -D  as ec2-user@54.150.220.39

 DEBUG [d82915ac] Command: cd /var/www/MyNote/current && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/MyNote/current/config/unicorn.rb -E deployment -D  )

 DEBUG [d82915ac]       master failed to start, check stderr log for details

本番環境(EC2内) /var/www/アプリ名/shared/log/unicorn.stderr.logに表示される内容

I, [2020-10-13T08:34:14.025904 #12943]  INFO -- : Refreshing Gem list
bundler: failed to load command: unicorn (/var/www/MyNote/shared/bundle/ruby/2.5.0/bin/unicorn)
NameError: uninitialized constant Model
  /var/www/MyNote/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant'
  /var/www/MyNote/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:9:in `without_bootsnap_cache'
  /var/www/MyNote/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `rescue in load_missing_constant'
  /var/www/MyNote/shared/bundle/ruby/2.5.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in `load_missing_constant'
  /var/www/MyNote/releases/20201013083325/app/controllers/users/registrations_controller.rb:3:in `<top (required)>'
〜省略〜

解決した経緯

unicorn.stderr.logの確認。
コピペして貼り付けた時に原因に気づきました。
めっちゃくちゃしれーっと書いてありますね!!!!!

/var/www/MyNote/releases/20201013083325/app/controllers/users/registrations_controller.rb:3:in `<top (required)>'

おまえかーい!!!
僕の4時間と心の焦りを返してください。泣

原因のソースコード

users/registrations_controller.rb
class Model::RegistrationsController < Devise::RegistrationsController
end

そりゃ確かにNameError: uninitialized constant Modelになりますわ。。
Modelクラスなんて存在しませんからねー

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

Ruby2.5.1
Rails5.2.4.2
unicorn 5.4.1
AWS EC2 Amazon linux AMI

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?