zeusd 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/zeusd +1 -1
- data/lib/zeusd/daemon.rb +41 -31
- data/lib/zeusd/version.rb +1 -1
- metadata +4 -4
data/bin/zeusd
CHANGED
data/lib/zeusd/daemon.rb
CHANGED
@@ -12,19 +12,23 @@ module Zeusd
|
|
12
12
|
class Daemon
|
13
13
|
include Hooks
|
14
14
|
|
15
|
-
define_hooks :
|
15
|
+
define_hooks :before_action, :after_action, :after_output
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
before_action do |action|
|
18
|
+
details = {}
|
19
|
+
details[:process] = process.attributes if process
|
20
|
+
log_event("Before: #{action}", details)
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
after_action do |action|
|
24
|
+
details = {}
|
25
|
+
details[:process] = process.attributes if process
|
26
|
+
log_event("After: #{action}", details)
|
22
27
|
end
|
23
28
|
|
24
29
|
after_output do |output|
|
25
30
|
interpreter.translate(output)
|
26
|
-
|
27
|
-
puts(output) if verbose
|
31
|
+
puts output if verbose
|
28
32
|
end
|
29
33
|
|
30
34
|
attr_reader :cwd, :verbose, :log_file, :interpreter, :child_process
|
@@ -36,6 +40,8 @@ module Zeusd
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def start!(options = {})
|
43
|
+
run_hook :before_action, __method__
|
44
|
+
|
39
45
|
start_child_process!
|
40
46
|
|
41
47
|
@process = Zeusd::Process.find(child_process.pid)
|
@@ -44,23 +50,32 @@ module Zeusd
|
|
44
50
|
sleep(0.1) until loaded?
|
45
51
|
end
|
46
52
|
|
47
|
-
run_hook :
|
53
|
+
run_hook :after_action, __method__
|
48
54
|
|
49
55
|
self
|
50
56
|
end
|
51
57
|
|
52
58
|
def restart!(options = {})
|
59
|
+
run_hook :before_action, __method__
|
60
|
+
|
53
61
|
stop!.start!(options)
|
62
|
+
|
63
|
+
run_hook :after_action, __method__
|
64
|
+
|
65
|
+
self
|
54
66
|
end
|
55
67
|
|
56
68
|
def stop!
|
57
|
-
run_hook :
|
69
|
+
run_hook :before_action, __method__
|
58
70
|
|
59
71
|
return self unless process
|
60
72
|
|
61
73
|
# Kill process tree and wait for exits
|
62
74
|
process.kill!(:recursive => true, :wait => true)
|
63
75
|
|
76
|
+
# Clean up socket file if stil exists
|
77
|
+
(zeus_socket_file.delete rescue nil) if zeus_socket_file.exist?
|
78
|
+
|
64
79
|
# Check for remaining processes
|
65
80
|
if[process, process.descendants].flatten.select(&:alive?).any?
|
66
81
|
raise DaemonException, "Unable to KILL processes: " + alive_processes.join(', ')
|
@@ -68,7 +83,7 @@ module Zeusd
|
|
68
83
|
|
69
84
|
@process = nil
|
70
85
|
|
71
|
-
run_hook :
|
86
|
+
run_hook :after_action, __method__
|
72
87
|
|
73
88
|
self
|
74
89
|
end
|
@@ -81,38 +96,33 @@ module Zeusd
|
|
81
96
|
interpreter.complete?
|
82
97
|
end
|
83
98
|
|
84
|
-
def log_event(type, details = nil)
|
85
|
-
logger.info("EVENT") do
|
86
|
-
">>> #{type.to_s.upcase}" + (details ? (" >>> " + JSON.pretty_generate(details)) : "")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def logger
|
91
|
-
@logger ||= Logger.new(log_file.to_path).tap do |x|
|
92
|
-
x.formatter = proc do |severity, datetime, type, msg|
|
93
|
-
prefix = "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}][#{type}]"
|
94
|
-
msg = msg.chomp.gsub("\n", "\n".ljust(prefix.length) + "\e[36m|\e[0m ")
|
95
|
-
"\e[36m#{prefix}\e[0m" + " #{msg}\n"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
99
|
def zeus_socket_file
|
101
100
|
cwd.join('.zeus.sock')
|
102
101
|
end
|
103
102
|
|
104
|
-
def log_file
|
105
|
-
cwd.join('log/zeusd.log')
|
106
|
-
end
|
107
|
-
|
108
103
|
def zeus_log_file
|
109
|
-
cwd.join('
|
104
|
+
cwd.join('log', 'zeus.log').tap do |path|
|
110
105
|
FileUtils.touch(path.to_path)
|
111
106
|
end
|
112
107
|
end
|
113
108
|
|
114
109
|
protected
|
115
110
|
|
111
|
+
def log_event(type, details = nil)
|
112
|
+
logger.info do
|
113
|
+
"\e[35m[Event] (#{type})\e[0m" + (!details.empty? ? " " + JSON.pretty_generate(details) : "")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def logger
|
118
|
+
@logger ||= Logger.new(cwd.join('log', 'zeusd.log').to_path).tap do |x|
|
119
|
+
x.formatter = proc do |severity, datetime, progname, msg|
|
120
|
+
prefix = "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]"
|
121
|
+
"\e[36m#{prefix}\e[0m" + " #{msg}\n"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
116
126
|
def start_child_process!
|
117
127
|
# Truncate and cast to File
|
118
128
|
zeus_log_file.open("w") {}
|
data/lib/zeusd/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeusd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -231,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
231
|
version: '0'
|
232
232
|
segments:
|
233
233
|
- 0
|
234
|
-
hash:
|
234
|
+
hash: -4127736754607950828
|
235
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
236
|
none: false
|
237
237
|
requirements:
|
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
240
|
version: '0'
|
241
241
|
segments:
|
242
242
|
- 0
|
243
|
-
hash:
|
243
|
+
hash: -4127736754607950828
|
244
244
|
requirements: []
|
245
245
|
rubyforge_project:
|
246
246
|
rubygems_version: 1.8.25
|