title: How to resolve "Connection refused" when executing bin/rails (spring) commands?
body: <p>I can execute <code>rails</code>-commands in production (FreeBSD 10) as long as <strong>Spring is disabled</strong>:</p>
  
  <pre><code># DISABLE_SPRING=1 bin/rails runner -e production 'p "test"'
  "test"
  
  # script/rails runner -e production 'p "test"'
  "test"
  </code></pre>
  
  <p><strong>With Spring</strong>, the <code>rails</code>-command fails with the following error:</p>
  
  <pre><code># 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 `&lt;top (required)&gt;'
          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 `&lt;top (required)&gt;'
          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 `&lt;top (required)&gt;'
          from bin/rails:3:in `load'
          from bin/rails:3:in `&lt;main&gt;'
  </code></pre>
  
  <p>So far, I verified that the according files in <code>/tmp/spring</code> exist as expected.</p>
  
  <p><strong>What could be the cause of this error and how can I achieve a correctly working Spring?</strong></p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Here is an outline of several checks I did so far.</p>
  
  <pre><code># 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
  </code></pre>