ruby-on-rails - 执行bin/rails(spring)命令时如何解析 "Connection refused"?

标签 ruby-on-rails spring-gem

只要 Spring 被禁用,我就可以在生产环境 (FreeBSD 10) 中执行 rails 命令:

# DISABLE_SPRING=1 bin/rails runner -e production 'p "test"'
"test"

# script/rails runner -e production 'p "test"'
"test"

使用 Springrails-command 失败并出现以下错误:

# bin/rails runner -e production 'p "test"' 
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/run.rb:20:in `initialize': Connection refused - "/tmp/spring/6e31dd16c1146fc209ac385f36aac9a1" (Errno::ECONNREFUSED)
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/run.rb:20:in `open'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/run.rb:20:in `server'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/run.rb:54:in `verify_server_version'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/run.rb:25:in `call'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
        from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /s/usr-local/www/the_project/releases/20140724133941/bin/spring:16:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

到目前为止,我已验证 /tmp/spring 中的相应文件按预期存在。

此错误的可能原因是什么?我如何才能使 Spring 正常工作?

更新 1

这是我到目前为止所做的几项检查的概要。

# ls -al /tmp/spring
total 32
drwxr-xr-x   2 proj     wheel   8 Jul 27 19:35 .
drwxrwxrwt  36 root     wheel  43 Jul 28 08:22 ..
srwxr-xr-x   1 proj     wheel   0 Jul 27 19:35 3004493e4fa38d91e78f82a2e74b4bc8
-rw-r--r--   1 proj     wheel   6 Jul 27 19:35 3004493e4fa38d91e78f82a2e74b4bc8.pid
srwxr-xr-x   1 proj     wheel   0 Jun 30 13:00 383a7b299457953fc0eda45a4eca65f8
-rw-r--r--   1 proj     wheel   5 Jun 30 13:00 383a7b299457953fc0eda45a4eca65f8.pid
srwxr-xr-x   1 proj     wheel   0 Jul 24 14:01 6e31dd16c1146fc209ac385f36aac9a1
-rw-r--r--   1 proj     wheel   6 Jul 24 14:01 6e31dd16c1146fc209ac385f36aac9a1.pid

# groups proj
proj wheel rvm

# bin/spring status
Spring is running:

25240 ruby: spring server | 20140727193408 | started 14 hours ago (ruby)
25245 ruby: spring app    | 20140727193408 | started 0 secs ago | production mode (ruby)

# fuser /tmp/spring/*
/tmp/spring/3004493e4fa38d91e78f82a2e74b4bc8:
/tmp/spring/3004493e4fa38d91e78f82a2e74b4bc8.pid: 25240wa
/tmp/spring/383a7b299457953fc0eda45a4eca65f8:
/tmp/spring/383a7b299457953fc0eda45a4eca65f8.pid:
/tmp/spring/6e31dd16c1146fc209ac385f36aac9a1:
/tmp/spring/6e31dd16c1146fc209ac385f36aac9a1.pid: 17260wa

# ps aux | grep -E '25240|17260'
proj        17260  0.0  0.1  79040  3544  -  IJ   Thu02PM 0:00.47 ruby: spring server | 20140724133941 | started 92 hours ago (ruby)
proj        25240  0.0  0.1  79040  3372  -  IJ    7:35PM 0:00.28 ruby: spring server | 20140727193408 | started 14 hours ago (ruby)

# head -n1 /tmp/spring.log     
[2014-07-28 10:16:40 +0000] [66008] [server] started on /tmp/spring/3004493e4fa38d91e78f82a2e74b4bc8

# tail /tmp/spring.log
[2014-07-28 10:18:00 +0000] [66008] [server] accepted client
[2014-07-28 10:18:00 +0000] [66008] [server] running command rails_runner
[2014-07-28 10:18:00 +0000] [66128] [application:production] got client
[2014-07-28 10:18:00 +0000] [66128] [application:production] forked 66370
[2014-07-28 10:18:00 +0000] [66008] [application_manager:production] got worker pid 66370
[2014-07-28 10:18:03 +0000] [66128] [application:production] 66370 exited with 0

最佳答案

我能够通过将用户登录 shell 更改为 bash(之前,它被设置为 zsh)并添加此 PATH 到 ~/.profile: PATH=$GEM_HOME/bin:$GEM_HOME/wrappers:$PATH

为了确保只使用 RVM 的 ruby​​,我还强行删除了系统 ruby​​ (1.9.3):pkg remove -f ruby

(注意:如果没有上述 PATH 设置,这会导致预期的错误 env: ruby: No such file or directory )

它出现了一个killall ruby是更改生效所必需的。 也许是 bin/spring stop也足够了。

关于ruby-on-rails - 执行bin/rails(spring)命令时如何解析 "Connection refused"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24936349/

相关文章:

mysql - 为什么使用 PostgreSQL 和 MySQL 时 Rails 上的整数大小限制不同?

ruby-on-rails - 如何为法语设置 Rails?

ruby-on-rails - 默认: { action: 'method' } do in rails routes?是什么

ruby-on-rails - spring & rvm 符号链接(symbolic link)别名命令到 bin/

ruby-on-rails - 带 Spring 锁的 Rails 4 控制台

ruby-on-rails - Spring : does "rails server" not start spring?

ruby-on-rails - 是否可以清除 Spring gem 的缓存?

ruby-on-rails - 如何检查子链接文件是否存在

ruby-on-rails - 嵌套 Controller Action 测试