简体   繁体   中英

Rails: Can't start the rails console in production

I am currently using Rails 5.2.3 and Ruby 2.5.0 on an application running on Ubuntu 18.04 production server, but when I run the command

rails c --environment=production

the command terminal gets stuck and I have to abort the process by holding down Ctrl + C keys together.

It, however, outputs the error below:

^CTraceback (most recent call last):
    16: from bin/rails:3:in `<main>'
    15: from bin/rails:3:in `load'
    14: from /home/deploy/myapp/bin/spring:15:in `<top (required)>'
    13: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    12: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
    11: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    10: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
     9: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
     8: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
     7: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
     6: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:24:in `call'
     5: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
     4: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/run.rb:35:in `call'
     3: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/run.rb:42:in `warm_run'
     2: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/run.rb:62:in `run'
     1: from /home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/run.rb:117:in `verify_server_version'
/home/deploy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/run.rb:117:in `gets': Interrupt

I have tried a few solutions but none seem to work for now, I would appreciate some help.

This issue is related to the spring gem that preloads a rails application in the background, however, it's not advisable to run it in a production environment

Here's how I solved the issue:

I installed/re-installed the spring gem:

gem install spring

I then upsprung (removed the spring gem from) the bin/ executables:

bin/spring binstub --remove --all

Or

spring binstub --remove --all

You can now run the command below to get into rails console in production

rails c --environment=production

Also, to avoid this from occurring in subsequent occasions endeavour to make sure that the spring gem is only present in development and test groups in your Gemfile.

Moreso, when you're in production make sure you always provide the --without development test argument to the bundle install command

bundle install --without development test

and not the usual or common

bundle install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM