Class: Pastry

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

Defined Under Namespace

Modules: PastryServer Classes: Backend

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool, app, options = {}) ⇒ Pastry

Returns a new instance of Pastry.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pastry.rb', line 14

def initialize pool, app, options = {}
  @pool             = pool
  @app              = app
  @host             = options.fetch :host,            '127.0.0.1'
  @port             = options.fetch :port,            3000
  @queue            = options.fetch :queue,           1024
  @max_connections  = options.fetch :max_connections, 1024
  @timeout          = options.fetch :timeout,           30
  @daemonize        = options.fetch :daemonize,       false
  @pidfile          = options.fetch :pidfile,         '/tmp/pastry.pid'
  @name             = options.fetch :name,            nil
  @socket           = options.fetch :socket,          nil
  @logfile          = options.fetch :logfile,         nil
  @start_command    = options.fetch :start_command,   nil
  @cwd              = File.expand_path(ENV['PWD'] || Dir.pwd)

  @before_fork      = nil
  @after_fork       = nil
end

Instance Attribute Details

#cwdObject

no defaults



12
13
14
# File 'lib/pastry.rb', line 12

def cwd
  @cwd
end

#daemonizeObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def daemonize
  @daemonize
end

#hostObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def host
  @host
end

#logfileObject

no defaults



12
13
14
# File 'lib/pastry.rb', line 12

def logfile
  @logfile
end

#max_connectionsObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def max_connections
  @max_connections
end

#nameObject

no defaults



12
13
14
# File 'lib/pastry.rb', line 12

def name
  @name
end

#pidfileObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def pidfile
  @pidfile
end

#poolObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def pool
  @pool
end

#portObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def port
  @port
end

#queueObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def queue
  @queue
end

#socketObject

no defaults



12
13
14
# File 'lib/pastry.rb', line 12

def socket
  @socket
end

#start_commandObject

no defaults



12
13
14
# File 'lib/pastry.rb', line 12

def start_command
  @start_command
end

#timeoutObject

have defaults



9
10
11
# File 'lib/pastry.rb', line 9

def timeout
  @timeout
end

Instance Method Details

#after_fork(&block) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/pastry.rb', line 39

def after_fork &block
  raise ArgumentError, 'missing callback' unless block
  @after_fork = block
end

#before_fork(&block) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
# File 'lib/pastry.rb', line 34

def before_fork &block
  raise ArgumentError, 'missing callback' unless block
  @before_fork = block
end

#parse_config(file) ⇒ Object



44
45
46
# File 'lib/pastry.rb', line 44

def parse_config file
  instance_eval File.read(file)
end

#startObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pastry.rb', line 48

def start
  do_sanity_checks
  ensure_not_running!

  Process.daemon(true, true) if daemonize

  if daemonize || logfile
    STDOUT.reopen(logfile || '/tmp/pastry.log', 'a')
    STDERR.reopen(logfile || '/tmp/pastry.log', 'a')
    STDOUT.sync = true
    STDERR.sync = true
    STDOUT.binmode
    STDERR.binmode
  end

  start!
end