title: Safely stopping em-websocket in rails on thin
body: <p>I have a rails app I am running on thin server to utilize the EventMachine run loop. The problem is that I would like to be able to include em-websocket to process information coming in from a ws and stop and start the websocket without stopping the EM run loop. This is how I am starting the websocket.</p>
  
  <pre><code>EventMachine::WebSocket.start(:host =&gt; "0.0.0.0", :port =&gt; 8080) do |ws|
    ws.onopen { }
    ws.onclose { }
    ws.onmessage { |msg| }
  end
  </code></pre>
  
  <p>The problem is in the start/stop code. From em-websocket's docs</p>
  
  <pre><code>#Start WebSocket
  def self.start(options, &amp;blk)
    EM.epoll
    EM.run do
  
      trap("TERM") { stop }
      trap("INT")  { stop }
  
      EventMachine::start_server(options[:host], options[:port],
        EventMachine::WebSocket::Connection, options) do |c|
        blk.call(c)
      end
    end
  end
  
  
  #Stop WebSocket
  def self.stop
    puts "Terminating WebSocket Server"
    EventMachine.stop
  end
  </code></pre>
  
  <p>The problem is that the internal em-websocket code does not track the signature coming from EM:start_server to be able to call EventMachine::stop_server(signature) to shut it down. Is there a way I can override these functions without modifying em-websocket so I can safely start / stop these websockets? I would like if it performed more like the standart Eventmachine server.</p>