title: How to Start a Thin Socket-Backed Cluster from Foreman
body: <p>I'm trying to set up <a href="http://discourse.org" rel="nofollow">Discourse</a> behind an <a href="http://nginx.org" rel="nofollow">Nginx</a> proxy, served via <a href="http://code.macournoyer.com/thin/" rel="nofollow">Thin</a> and started via <a href="https://github.com/ddollar/foreman" rel="nofollow">Foreman</a>.</p>
  
  <p>So I have a <code>Procfile</code> like so:</p>
  
  <pre><code>web: thin start -p $PORT --socket tmp/sockets/thin.sock
  sidekiq: bundle exec sidekiq -e $RAILS_ENV
  clockwork: bundle exec clockwork config/clock.rb
  </code></pre>
  
  <p>And a nginx <code>conf</code> file that points to the socket:</p>
  
  <pre><code>upstream discourse {
    server unix:///var/www/discourse/tmp/sockets/thin.sock;
  }
  </code></pre>
  
  <p>And that all works great… as long as I only ever want one web worker, connected to the socket. If I were just running <code>thin</code> myself, I could tack in a <code>-s4</code> and get four thin workers, and it even handles the socket files, creating <code>thin.0.socket</code>, <code>thin.1.socket</code>, etc. But running <code>thin</code> that way spins up the workers in their own processes, and then quits, so if I put <code>-s4</code> into my <code>Procfile</code>, <code>foreman</code> thinks something died and cascades, bringing itself down, too.</p>
  
  <p>Just telling <code>foreman start -c web=2</code> brings up two processes... but they both point to the same <code>sock</code> file and neither seems to work.</p>
  
  <p>I'm sure there's a simple way to handle this, but I can't seem to figure out the magic incantation. What am I doing wrong here?</p>