Class: Puma::Configuration::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/configuration.rb

Overview

The methods that are available for use inside the config file.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DSL

Returns a new instance of DSL.



156
157
158
# File 'lib/puma/configuration.rb', line 156

def initialize(options)
  @options = options
end

Instance Method Details

#_load_from(path) ⇒ Object



160
161
162
# File 'lib/puma/configuration.rb', line 160

def _load_from(path)
  instance_eval File.read(path), path, 1
end

#activate_control_app(url = "auto", opts = nil) ⇒ Object

Start the Puma control rack app on url. This app can be communicated with to control the main server.



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/puma/configuration.rb', line 178

def activate_control_app(url="auto", opts=nil)
  @options[:control_url] = url

  if opts
    if tok = opts[:auth_token]
      @options[:control_auth_token] = tok
    end

    if opts[:no_token]
      @options[:control_auth_token] = :none
    end
  end
end

#app(obj = nil, &block) ⇒ Object

Use obj or block as the Rack app. This allows a config file to be the app itself.



167
168
169
170
171
172
173
# File 'lib/puma/configuration.rb', line 167

def app(obj=nil, &block)
  obj ||= block

  raise "Provide either a #call'able or a block" unless obj

  @options[:app] = obj
end

#bind(url) ⇒ Object

Bind the server to url. tcp:// and unix:// are the only accepted protocols.



195
196
197
# File 'lib/puma/configuration.rb', line 195

def bind(url)
  @options[:binds] << url
end

#daemonize(which = true) ⇒ Object

Daemonize the server into the background. Highly suggest that this be combined with pidfile and stdout_redirect.



207
208
209
# File 'lib/puma/configuration.rb', line 207

def daemonize(which=true)
  @options[:daemon] = which
end

#directory(dir) ⇒ Object

The directory to operate out of.



311
312
313
314
# File 'lib/puma/configuration.rb', line 311

def directory(dir)
  @options[:directory] = dir.to_s
  @options[:worker_directory] = dir.to_s
end

#drain_on_shutdown(which = true) ⇒ Object

When shutting down, drain the accept socket of pending connections and proces them. This loops over the accept socket until there are no more read events and then stops looking and waits for the requests to finish.



215
216
217
# File 'lib/puma/configuration.rb', line 215

def drain_on_shutdown(which=true)
  @options[:drain_on_shutdown] = which
end

#environment(environment) ⇒ Object

Set the environment in which the Rack’s app will run.



220
221
222
# File 'lib/puma/configuration.rb', line 220

def environment(environment)
  @options[:environment] = environment
end

#on_restart(&block) ⇒ Object

Code to run before doing a restart. This code should close logfiles, database connections, etc.

This can be called multiple times to add code each time.



229
230
231
# File 'lib/puma/configuration.rb', line 229

def on_restart(&block)
  @options[:on_restart] << block
end

#on_worker_boot(&block) ⇒ Object

*Cluster mode only* Code to run when a worker boots to setup the process before booting the app.

This can be called multiple times to add hooks.



306
307
308
# File 'lib/puma/configuration.rb', line 306

def on_worker_boot(&block)
  @options[:worker_boot] << block
end

#pidfile(path) ⇒ Object

Store the pid of the server in the file at path.



242
243
244
# File 'lib/puma/configuration.rb', line 242

def pidfile(path)
  @options[:pidfile] = path
end

#port(port) ⇒ Object

Define the TCP port to bind to. Use bind for more advanced options.



201
202
203
# File 'lib/puma/configuration.rb', line 201

def port(port)
  @options[:binds] << "tcp://#{Configuration::DefaultTCPHost}:#{port}"
end

#preload_app!(answer = true) ⇒ Object

*Cluster mode only* Preload the application before starting the workers and setting up the listen ports. This conflicts with using the phased restart feature, you can’t use both.



325
326
327
# File 'lib/puma/configuration.rb', line 325

def preload_app!(answer=true)
  @options[:preload_app] = answer
end

#quietObject

Disable request logging.



248
249
250
# File 'lib/puma/configuration.rb', line 248

def quiet
  @options[:quiet] = true
end

#rackup(path) ⇒ Object

Load path as a rackup file.



254
255
256
# File 'lib/puma/configuration.rb', line 254

def rackup(path)
  @options[:rackup] = path.to_s
end

#restart_command(cmd) ⇒ Object

Command to use to restart puma. This should be just how to load puma itself (ie. ‘ruby -Ilib bin/puma’), not the arguments to puma, as those are the same as the original process.



237
238
239
# File 'lib/puma/configuration.rb', line 237

def restart_command(cmd)
  @options[:restart_cmd] = cmd
end

#ssl_bind(host, port, opts) ⇒ Object



279
280
281
282
283
284
285
286
# File 'lib/puma/configuration.rb', line 279

def ssl_bind(host, port, opts)
  o = [
    "cert=#{opts[:cert]}",
    "key=#{opts[:key]}"
  ]

  @options[:binds] << "ssl://#{host}:#{port}?#{o.join('&')}"
end

#state_path(path) ⇒ Object

Use path as the file to store the server info state. This is used by pumactl to query and control the server.



291
292
293
# File 'lib/puma/configuration.rb', line 291

def state_path(path)
  @options[:state] = path.to_s
end

#stdout_redirect(stdout = nil, stderr = nil, append = false) ⇒ Object

Redirect STDOUT and STDERR to files specified.



259
260
261
262
263
# File 'lib/puma/configuration.rb', line 259

def stdout_redirect(stdout=nil, stderr=nil, append=false)
  @options[:redirect_stdout] = stdout
  @options[:redirect_stderr] = stderr
  @options[:redirect_append] = append
end

#tcp_modeObject

Run the app as a raw TCP app instead of an HTTP rack app



317
318
319
# File 'lib/puma/configuration.rb', line 317

def tcp_mode
  @options[:mode] = :tcp
end

#threads(min, max) ⇒ Object

Configure min to be the minimum number of threads to use to answer requests and max the maximum.



268
269
270
271
272
273
274
275
276
277
# File 'lib/puma/configuration.rb', line 268

def threads(min, max)
  min = Integer(min)
  max = Integer(max)
  if min > max
    raise "The minimum (#{min}) number of threads must be less than the max (#{max})"
  end

  @options[:min_threads] = min
  @options[:max_threads] = max
end

#workers(count) ⇒ Object

*Cluster mode only* How many worker processes to run.



297
298
299
# File 'lib/puma/configuration.rb', line 297

def workers(count)
  @options[:workers] = count.to_i
end