title: How to determine if Rails is running from CLI, console or as server?
body: <p>I have a <a href="https://github.com/crishoj/rack_jour" rel="noreferrer">middleware for announcing my application on the local network app using Bonjour</a>, but it's also announcing the service when Rails is invoked from rake or through the console. </p>
  
  <p>I'd like to exclude these cases, and only use the Bonjour middleware when Rails is running as a server. </p>
  
  <p>The middleware configuration accepts a proc to exclude middlewares under certain conditions using a <code>proc</code>:</p>
  
  <pre><code>config.middleware.insert_before ActionDispatch::Static, Rack::SSL, :exclude =&gt; proc { |env| 
    env['HTTPS'] != 'on' 
  }
  </code></pre>
  
  <p>But how do I determine if Rails was invoked from the CLI, console or as a server?</p>