【问题标题】:How to resolve "Connection refused" when executing bin/rails (spring) commands?执行 bin/rails (spring) 命令时如何解决“连接被拒绝”?
【发布时间】:2014-09-16 03:56:28
【问题描述】:

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

# 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

【问题讨论】:

  • 什么是进程 17260 运行了四天?您是否尝试关闭所有服务器并重新启动?

标签: ruby-on-rails spring-gem


【解决方案1】:

我能够通过将用户登录 shell 更改为 bash(之前设置为 zsh)并添加此 PATH em> ~/.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​​/rvm 问题。您不妨奖励我的回答,因为无论如何那些代表都走了,非常感谢。 :)
  • 我本来可以的,但我已经离开了,直到现在我才看到你的评论。对不起!
【解决方案2】:

关于这个的一些想法,似乎spring server无法启动或者你不允许连接到socket:

【讨论】:

  • 感谢您的提示,Wolfram。我之前已经检查了大部分内容。我在问题中添加了“更新 1”。它包含对您的建议的答案。请注意,用户 projwheel 中。
【解决方案3】:

我在Error connecting to Spring server 的消息中偶然发现了这个问题。

对我来说解决方案很简单:

spring stop

至此,我的db:migrate 任务成功完成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2023-01-31
    • 2020-05-11
    相关资源
    最近更新 更多