Class: Pastry
- Inherits:
-
Object
- Object
- Pastry
- Defined in:
- lib/pastry.rb
Defined Under Namespace
Modules: PastryServer Classes: Backend
Instance Attribute Summary collapse
-
#cwd ⇒ Object
no defaults.
-
#daemonize ⇒ Object
have defaults.
-
#host ⇒ Object
have defaults.
-
#logfile ⇒ Object
no defaults.
-
#max_connections ⇒ Object
have defaults.
-
#name ⇒ Object
no defaults.
-
#pidfile ⇒ Object
have defaults.
-
#pool ⇒ Object
have defaults.
-
#port ⇒ Object
have defaults.
-
#queue ⇒ Object
have defaults.
-
#socket ⇒ Object
no defaults.
-
#start_command ⇒ Object
no defaults.
-
#timeout ⇒ Object
have defaults.
Instance Method Summary collapse
- #after_fork(&block) ⇒ Object
- #before_fork(&block) ⇒ Object
-
#initialize(pool, app, options = {}) ⇒ Pastry
constructor
A new instance of Pastry.
- #parse_config(file) ⇒ Object
- #start ⇒ Object
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, = {} @pool = pool @app = app @host = .fetch :host, '127.0.0.1' @port = .fetch :port, 3000 @queue = .fetch :queue, 1024 @max_connections = .fetch :max_connections, 1024 @timeout = .fetch :timeout, 30 @daemonize = .fetch :daemonize, false @pidfile = .fetch :pidfile, '/tmp/pastry.pid' @name = .fetch :name, nil @socket = .fetch :socket, nil @logfile = .fetch :logfile, nil @start_command = .fetch :start_command, nil @cwd = File.(ENV['PWD'] || Dir.pwd) @before_fork = nil @after_fork = nil end |
Instance Attribute Details
#cwd ⇒ Object
no defaults
12 13 14 |
# File 'lib/pastry.rb', line 12 def cwd @cwd end |
#daemonize ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def daemonize @daemonize end |
#host ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def host @host end |
#logfile ⇒ Object
no defaults
12 13 14 |
# File 'lib/pastry.rb', line 12 def logfile @logfile end |
#max_connections ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def max_connections @max_connections end |
#name ⇒ Object
no defaults
12 13 14 |
# File 'lib/pastry.rb', line 12 def name @name end |
#pidfile ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def pidfile @pidfile end |
#pool ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def pool @pool end |
#port ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def port @port end |
#queue ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def queue @queue end |
#socket ⇒ Object
no defaults
12 13 14 |
# File 'lib/pastry.rb', line 12 def socket @socket end |
#start_command ⇒ Object
no defaults
12 13 14 |
# File 'lib/pastry.rb', line 12 def start_command @start_command end |
#timeout ⇒ Object
have defaults
9 10 11 |
# File 'lib/pastry.rb', line 9 def timeout @timeout end |
Instance Method Details
#after_fork(&block) ⇒ Object
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
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 |
#start ⇒ Object
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 |