zeusd 0.2.1 → 0.2.3
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/lib/zeusd/daemon.rb +49 -29
- data/lib/zeusd/interpreter.rb +0 -6
- data/lib/zeusd/version.rb +1 -1
- data/zeusd.gemspec +2 -1
- metadata +21 -5
data/lib/zeusd/daemon.rb
CHANGED
@@ -3,6 +3,8 @@ require 'thread'
|
|
3
3
|
require 'childprocess'
|
4
4
|
require 'pathname'
|
5
5
|
require 'hooks'
|
6
|
+
require 'file-tail'
|
7
|
+
require 'json'
|
6
8
|
|
7
9
|
module Zeusd
|
8
10
|
class DaemonException < StandardError; end
|
@@ -12,16 +14,16 @@ module Zeusd
|
|
12
14
|
|
13
15
|
define_hooks :after_start!, :after_stop!, :before_stop!, :after_output
|
14
16
|
|
15
|
-
after_start! {
|
16
|
-
before_stop! {
|
17
|
+
after_start! { log_event :start, :process => process ? process.attributes : nil }
|
18
|
+
before_stop! { log_event :stop, :process => process ? process.attributes : nil }
|
17
19
|
|
18
20
|
after_stop! do
|
19
|
-
(
|
21
|
+
(zeus_socket_file.delete rescue nil) if zeus_socket_file.exist?
|
20
22
|
end
|
21
23
|
|
22
24
|
after_output do |output|
|
23
25
|
interpreter.translate(output)
|
24
|
-
logger.info("Zeus"){output}
|
26
|
+
# logger.info("Zeus"){output}
|
25
27
|
puts(output) if verbose
|
26
28
|
end
|
27
29
|
|
@@ -42,9 +44,9 @@ module Zeusd
|
|
42
44
|
sleep(0.1) until loaded?
|
43
45
|
end
|
44
46
|
|
45
|
-
self
|
46
|
-
ensure
|
47
47
|
run_hook :after_start!
|
48
|
+
|
49
|
+
self
|
48
50
|
end
|
49
51
|
|
50
52
|
def restart!(options = {})
|
@@ -66,9 +68,9 @@ module Zeusd
|
|
66
68
|
|
67
69
|
@process = nil
|
68
70
|
|
69
|
-
self
|
70
|
-
ensure
|
71
71
|
run_hook :after_stop!
|
72
|
+
|
73
|
+
self
|
72
74
|
end
|
73
75
|
|
74
76
|
def process
|
@@ -79,45 +81,63 @@ module Zeusd
|
|
79
81
|
interpreter.complete?
|
80
82
|
end
|
81
83
|
|
82
|
-
def
|
83
|
-
|
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
|
84
98
|
end
|
85
99
|
|
86
|
-
def
|
100
|
+
def zeus_socket_file
|
87
101
|
cwd.join('.zeus.sock')
|
88
102
|
end
|
89
103
|
|
90
|
-
|
104
|
+
def log_file
|
105
|
+
cwd.join('log/zeusd.log')
|
106
|
+
end
|
91
107
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
color = progname["Zeusd"] ? 36 : 35
|
96
|
-
ts = datetime.strftime('%Y-%m-%d %H:%M:%S')
|
97
|
-
prefix = "[#{ts}][#{progname.ljust(6)}]"
|
98
|
-
msg = msg.chomp.gsub("\n", "\n".ljust(prefix.length) + "\e[#{color}m|\e[0m ")
|
99
|
-
"\e[#{color}m#{prefix}\e[0m" + " #{msg}\n"
|
100
|
-
end
|
108
|
+
def zeus_log_file
|
109
|
+
cwd.join('.zeus.log').tap do |path|
|
110
|
+
FileUtils.touch(path.to_path)
|
101
111
|
end
|
102
112
|
end
|
103
113
|
|
114
|
+
protected
|
115
|
+
|
104
116
|
def start_child_process!
|
105
|
-
|
117
|
+
# Truncate and cast to File
|
118
|
+
zeus_log_file.open("w") {}
|
119
|
+
std_file = File.new(zeus_log_file, 'w+').tap{|x| x.sync = true}
|
120
|
+
|
121
|
+
# Prep and Start child process
|
106
122
|
@child_process = ChildProcess.build("zeus", "start")
|
107
123
|
@child_process.environment["BUNDLE_GEMFILE"] = cwd.join("Gemfile").to_path
|
108
|
-
@child_process.io.
|
109
|
-
@child_process.
|
110
|
-
@child_process.
|
124
|
+
@child_process.io.stderr = std_file
|
125
|
+
@child_process.io.stdout = std_file
|
126
|
+
@child_process.cwd = cwd.to_path
|
127
|
+
@child_process.detach = true
|
111
128
|
@child_process.start
|
112
129
|
|
113
|
-
|
114
|
-
|
130
|
+
# Start tailing child process output
|
115
131
|
Thread.new do
|
116
|
-
|
117
|
-
|
132
|
+
File.open(std_file.to_path) do |log|
|
133
|
+
log.extend(File::Tail)
|
134
|
+
log.interval = 0.1
|
135
|
+
log.backward(100)
|
136
|
+
log.tail {|line| run_hook(:after_output, line) }
|
118
137
|
end
|
119
138
|
end
|
120
139
|
|
140
|
+
# Block until the first zeus command has been registered
|
121
141
|
sleep 0.1 until interpreter.commands.any?
|
122
142
|
|
123
143
|
@child_process
|
data/lib/zeusd/interpreter.rb
CHANGED
data/lib/zeusd/version.rb
CHANGED
data/zeusd.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "thor" , "~> 0.18.1"
|
22
|
-
spec.add_runtime_dependency "childprocess" , "
|
22
|
+
spec.add_runtime_dependency "childprocess" , ">= 0.5.1"
|
23
|
+
spec.add_runtime_dependency "file-tail" , "~> 1.0.12"
|
23
24
|
spec.add_runtime_dependency "hooks" , "~> 0.3.3"
|
24
25
|
spec.add_runtime_dependency "zeus" , "~> 0.13.3"
|
25
26
|
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -29,12 +29,28 @@ dependencies:
|
|
29
29
|
version: 0.18.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: childprocess
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.5.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.5.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: file-tail
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
33
49
|
none: false
|
34
50
|
requirements:
|
35
51
|
- - ~>
|
36
52
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
53
|
+
version: 1.0.12
|
38
54
|
type: :runtime
|
39
55
|
prerelease: false
|
40
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +58,7 @@ dependencies:
|
|
42
58
|
requirements:
|
43
59
|
- - ~>
|
44
60
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
61
|
+
version: 1.0.12
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: hooks
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
231
|
version: '0'
|
216
232
|
segments:
|
217
233
|
- 0
|
218
|
-
hash:
|
234
|
+
hash: 4001944416869534268
|
219
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
236
|
none: false
|
221
237
|
requirements:
|
@@ -224,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
240
|
version: '0'
|
225
241
|
segments:
|
226
242
|
- 0
|
227
|
-
hash:
|
243
|
+
hash: 4001944416869534268
|
228
244
|
requirements: []
|
229
245
|
rubyforge_project:
|
230
246
|
rubygems_version: 1.8.25
|