Class Thin::Server
In: lib/thin/server.rb
Parent: Object

The uterly famous Thin HTTP server. It listen for incoming request through a given backend and forward all request to app.

TCP server

Create a new TCP server on bound to host:port by specifiying host and port as the first 2 arguments.

  Thin::Server.start('0.0.0.0', 3000, app)

UNIX domain server

Create a new UNIX domain socket bound to socket file by specifiying a filename as the first argument. Eg.: /tmp/thin.sock. If the first argument contains a / it will be assumed to be a UNIX socket.

  Thin::Server.start('/tmp/thin.sock', app)

Using a custom backend

You can implement your own way to connect the server to its client by creating your own Backend class and pass it as the :backend option.

  Thin::Server.start('galaxy://faraway', 1345, app, :backend => Thin::Backends::MyFancyBackend)

Rack application (app)

All requests will be processed through app that must be a valid Rack adapter. A valid Rack adapter (application) must respond to call(env#Hash) and return an array of [status, headers, body].

Building an app in place

If a block is passed, a Rack::Builder instance will be passed to build the app. So you can do cool stuff like this:

  Thin::Server.start('0.0.0.0', 3000) do
    use Rack::CommonLogger
    use Rack::ShowExceptions
    map "/lobster" do
      use Rack::Lint
      run Rack::Lobster.new
    end
  end

Controlling with signals

Disable signals by passing :signals => false

Methods

Included Modules

Logging Daemonizable

Constants

DEFAULT_TIMEOUT = 30   Default values
DEFAULT_HOST = '0.0.0.0'
DEFAULT_PORT = 3000
DEFAULT_MAXIMUM_CONNECTIONS = 1024
DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS = 512

Attributes

app  [RW]  Application (Rack adapter) called with the request that produces the response.
backend  [RW]  Backend handling the connections to the clients.
tag  [RW]  A tag that will show in the process listing

Public Class methods

Lil’ shortcut to turn this:

  Server.new(...).start

into this:

  Server.start(...)

Public Instance methods

Configure the server

The process might need to have superuser privilege to configure server with optimal options.

Name of the server and type of backend used. This is also the name of the process in which Thin is running as a daemon.

Return true if the server is running and ready to receive requests. Note that the server might still be running and return false when shuting down and waiting for active connections to complete.

Start the server and listen for connections.

start!()

Alias for start

Gracefull shutdown

Stops the server after processing all current connections. As soon as this method is called, the server stops accepting new requests and wait for all current connections to finish. Calling twice is the equivalent of calling stop!.

Force shutdown

Stops the server closing all current connections right away. This doesn‘t wait for connection to finish their work and send data. All current requests will be dropped.

to_s()

Alias for name

Protected Instance methods

Taken from Mongrel cgi_multipart_eof_fix Ruby 1.8.5 has a security bug in cgi.rb, we need to patch it.

Register signals:

  • INT calls stop to shutdown gracefully.
  • TERM calls stop! to force shutdown.

[Validate]