Class: Zeusd::Daemon
Instance Attribute Summary collapse
Instance Method Summary
collapse
included, #log_file, #logger, #track
Constructor Details
#initialize(options = {}) ⇒ Daemon
Returns a new instance of Daemon.
5
6
7
8
|
# File 'lib/zeusd/daemon.rb', line 5
def initialize(options = {})
@cwd = Pathname.new(options[:cwd] || Dir.pwd).realpath
@verbose = !!options[:verbose]
end
|
Instance Attribute Details
#child_process ⇒ Object
Returns the value of attribute child_process.
3
4
5
|
# File 'lib/zeusd/daemon.rb', line 3
def child_process
@child_process
end
|
#cwd ⇒ Object
Returns the value of attribute cwd.
3
4
5
|
# File 'lib/zeusd/daemon.rb', line 3
def cwd
@cwd
end
|
#status ⇒ Object
Returns the value of attribute status.
3
4
5
|
# File 'lib/zeusd/daemon.rb', line 3
def status
@status
end
|
#verbose ⇒ Object
Returns the value of attribute verbose.
3
4
5
|
# File 'lib/zeusd/daemon.rb', line 3
def verbose
@verbose
end
|
Instance Method Details
#finished? ⇒ Boolean
55
56
57
|
# File 'lib/zeusd/daemon.rb', line 55
def finished?
status.finished?
end
|
#process ⇒ Object
51
52
53
|
# File 'lib/zeusd/daemon.rb', line 51
def process
@process ||= Process.all.find {|p| !!p.command[/zeus.*start$/] && p.cwd == cwd }
end
|
#restart!(options = {}) ⇒ Object
22
23
24
|
# File 'lib/zeusd/daemon.rb', line 22
def restart!(options = {})
stop!.start!(options)
end
|
#start!(options = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/zeusd/daemon.rb', line 10
def start!(options = {})
start_child_process!
@process = Zeusd::Process.find(child_process.pid)
if options.fetch(:block, false)
sleep(3) until status.finished?
end
self
end
|
#status_queue ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/zeusd/daemon.rb', line 40
def status_queue
queue = Queue.new
status = Log::Status.new(File.new(zeus_log.to_path, 'r'))
queue << status.to_cli
status.on_update {|x| queue << x.to_cli }
status.record!
queue
end
|
#stop! ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/zeusd/daemon.rb', line 26
def stop!
return self unless process
process.kill!(:recursive => true, :signal => "KILL", :wait => true)
(zeus_socket.delete rescue nil) if zeus_socket.exist?
@process = nil
self
end
|
#to_json(*args) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/zeusd/daemon.rb', line 73
def to_json(*args)
{
:class => self.class.name,
:cwd => cwd.to_path,
:verbose => verbose,
:process => process
}.to_json(*args)
end
|
#verbose? ⇒ Boolean
69
70
71
|
# File 'lib/zeusd/daemon.rb', line 69
def verbose?
!!verbose
end
|
#zeus_log ⇒ Object
63
64
65
66
67
|
# File 'lib/zeusd/daemon.rb', line 63
def zeus_log
cwd.join('log', 'zeus.log').tap do |path|
FileUtils.touch(path.to_path)
end
end
|
#zeus_socket ⇒ Object
59
60
61
|
# File 'lib/zeusd/daemon.rb', line 59
def zeus_socket
cwd.join('.zeus.sock')
end
|