A memorandum that the author suffered from an error [bundler: failed to load command: unicorn NameError: uninitialized constant Model]

at first

This issue has been resolved. Maybe it's too special to be helpful to anyone. After filling out the question format, I noticed the cause of the error and resolved it. It is left as a memorandum of the author.

Impressions

Read all the error statements. But when I was told bundler: failed to load command: unicorn, I doubt unicorn. .. .. The Name Error: uninitialized constant Model one line down was super important. Why does it start in the local environment? At least detect the error ~~

Premise / What you want to achieve

I tried to deploy an app developed with Rails using Capistrano, The unicorn: start command always fails. The goal is to resolve the error so that unicorn can start correctly and deploy.

Problems / error messages that are occurring

I used to be able to deploy with capistrano, but when I deployed after about a week, I got this error. I edited some source code while I was not deploying.

Capistrano error statement

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 [email protected]: 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 [email protected]: 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 [email protected]: 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:

~abridgement~

 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 [email protected]

 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 line: kill: (21662) -There is no such process

 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 [email protected]

 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

Contents displayed in the production environment (in EC2) /var/www/app name/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)>'
~abridgement~

Background of the solution

Check unicorn.stderr.log. I noticed the cause when I copied and pasted it. It's written so messed up! !! !! !! !!

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

You guys! !! !! Please return my 4 hours and impatience. Crying

Cause source code

users/registrations_controller.rb


class Model::RegistrationsController < Devise::RegistrationsController
end

That's certainly a NameError: uninitialized constant Model. .. There is no Model class.

Supplementary information (FW / tool version, etc.)

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

Recommended Posts

A memorandum that the author suffered from an error [bundler: failed to load command: unicorn NameError: uninitialized constant Model]
The story that Tomcat suffered from a timeout error in Eclipse
Send a command to Spigot from an external process