Class: Uc::Unicorn::Init
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helper
#first_worker?, #last_worker?, #old_pid, #restart?
Methods included from Logger
#event_queue, event_stream, #event_stream, logger, #logger, stderr, #stderr
Constructor Details
#initialize(server) ⇒ Init
Returns a new instance of Init.
14
15
16
|
# File 'lib/uc/unicorn/init.rb', line 14
def initialize(server)
@server = server
end
|
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
12
13
14
|
# File 'lib/uc/unicorn/init.rb', line 12
def server
@server
end
|
#worker ⇒ Object
Returns the value of attribute worker.
12
13
14
|
# File 'lib/uc/unicorn/init.rb', line 12
def worker
@worker
end
|
Instance Method Details
#acquire_lock ⇒ Object
36
37
38
39
40
41
|
# File 'lib/uc/unicorn/init.rb', line 36
def acquire_lock
lock_acquired = lock_fd.flock(File::LOCK_SH | File::LOCK_NB )
rescue => e
stderr.error "#{e.class} #{e.message}\n #{e.backtrace.join("\n")}"
return false
end
|
#end_run(worker) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/uc/unicorn/init.rb', line 53
def end_run(worker)
@worker = worker
if last_worker?
event_stream.pub :fin, "server #{event_type}"
end
end
|
#event_type ⇒ Object
18
19
20
|
# File 'lib/uc/unicorn/init.rb', line 18
def event_type
@event_type ||= (restart? ? "restart" : "start")
end
|
#lock_fd ⇒ Object
49
50
51
|
# File 'lib/uc/unicorn/init.rb', line 49
def lock_fd
@lock_fd ||= File.new(lock_file, "a+")
end
|
#lock_file ⇒ Object
22
23
24
|
# File 'lib/uc/unicorn/init.rb', line 22
def lock_file
@lock_file ||= "tmp/unicorn.lock"
end
|
#run ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/uc/unicorn/init.rb', line 26
def run
event_stream.debug "event_type #{event_type}"
acquired = acquire_lock
if not acquired
error_msg = "unable to acquire shared lock (unicorn)"
event_stream.fatal error_msg
raise ::Uc::Error, error_msg
end
end
|
#run_once ⇒ Object
43
44
45
46
47
|
# File 'lib/uc/unicorn/init.rb', line 43
def run_once
return if @ran_once
@ran_once = true
run
end
|