简体   繁体   English

Rails:无法在生产中启动 rails 控制台

[英]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我目前在 Ubuntu 18.04 生产服务器上运行的应用程序上使用Rails 5.2.3Ruby 2.5.0 ,但是当我运行命令时

rails c --environment=production

the command terminal gets stuck and I have to abort the process by holding down Ctrl + C keys together.命令终端卡住了,我必须同时按住 Ctrl + C 键来中止该过程。

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此问题与在后台预加载rails应用程序的spring gem有关,但不建议在生产环境中运行它

Here's how I solved the issue:这是我解决问题的方法:

I installed/re-installed the spring gem:我安装/重新安装了spring gem:

gem install spring

I then upsprung (removed the spring gem from) the bin/ executables:然后我启动了(从中删除了spring gem) bin/可执行文件:

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 控制台

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.此外,为了避免在随后的情况下发生这种情况,请努力确保spring gem 仅出现在您的 Gemfile 中的developmenttest组中。

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参数

bundle install --without development test

and not the usual or common而不是通常的或常见的

bundle install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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