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.



147
148
149
# File 'lib/puma/configuration.rb', line 147

def initialize(options)
  @options = options
end

Instance Method Details

#_load_from(path) ⇒ Object



151
152
153
# File 'lib/puma/configuration.rb', line 151

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.



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/puma/configuration.rb', line 169

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.



158
159
160
161
162
163
164
# File 'lib/puma/configuration.rb', line 158

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.



186
187
188
# File 'lib/puma/configuration.rb', line 186

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.



192
193
194
# File 'lib/puma/configuration.rb', line 192

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

#directory(dir) ⇒ Object

The directory to operate out of.



286
287
288
289
# File 'lib/puma/configuration.rb', line 286

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

#environment(environment) ⇒ Object

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



197
198
199
# File 'lib/puma/configuration.rb', line 197

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

#on_restart(&blk) ⇒ 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.



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

def on_restart(&blk)
  @options[:on_restart] << blk
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.



281
282
283
# File 'lib/puma/configuration.rb', line 281

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

#pidfile(path) ⇒ Object

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



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

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

#quietObject

Disable request logging.



225
226
227
# File 'lib/puma/configuration.rb', line 225

def quiet
  @options[:quiet] = true
end

#rackup(path) ⇒ Object

Load path as a rackup file.



231
232
233
# File 'lib/puma/configuration.rb', line 231

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.



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

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

#ssl_bind(host, port, opts) ⇒ Object



254
255
256
257
258
259
260
261
# File 'lib/puma/configuration.rb', line 254

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.



266
267
268
# File 'lib/puma/configuration.rb', line 266

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.



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

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

#threads(min, max) ⇒ Object

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



245
246
247
248
249
250
251
252
# File 'lib/puma/configuration.rb', line 245

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

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

#workers(count) ⇒ Object

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



272
273
274
# File 'lib/puma/configuration.rb', line 272

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