zeusd 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/zeusd/daemon.rb +19 -26
- data/lib/zeusd/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Zeusd [![Gem Version](https://badge.fury.io/rb/zeusd.png)](http://badge.fury.io/rb/zeusd) [![Build Status](https://travis-ci.org/veloper/zeusd.png?branch=master)](https://travis-ci.org/veloper/zeusd) [![Code Climate](https://codeclimate.com/github/veloper/zeusd.png)](https://codeclimate.com/github/veloper/zeusd)
|
1
|
+
# Zeusd [![Gem Version](https://badge.fury.io/rb/zeusd.png)](http://badge.fury.io/rb/zeusd) [![Dependency Status](https://gemnasium.com/veloper/zeusd.png)](https://gemnasium.com/veloper/zeusd) [![Build Status](https://travis-ci.org/veloper/zeusd.png?branch=master)](https://travis-ci.org/veloper/zeusd) [![Code Climate](https://codeclimate.com/github/veloper/zeusd.png)](https://codeclimate.com/github/veloper/zeusd)
|
2
2
|
|
3
3
|
Zeusd aims to provide greater control and easier scripting of the [Zeus Gem](https://github.com/burke/zeus) via daemonization.
|
4
4
|
|
@@ -53,4 +53,4 @@ $ gem install zeusd
|
|
53
53
|
|
54
54
|
## License
|
55
55
|
|
56
|
-
* Zeusd is released under the New BSD license. http://dan.doezema.com/licenses/new-bsd/
|
56
|
+
* Zeusd is released under the New BSD license. http://dan.doezema.com/licenses/new-bsd/
|
data/lib/zeusd/daemon.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'thread'
|
2
3
|
require 'childprocess'
|
3
4
|
require 'pathname'
|
@@ -7,15 +8,12 @@ module Zeusd
|
|
7
8
|
class DaemonException < StandardError; end
|
8
9
|
|
9
10
|
class Daemon
|
10
|
-
attr_reader :cwd, :verbose, :log_file, :log_queue, :interpreter, :child_process
|
11
|
-
|
12
|
-
|
13
11
|
include Hooks
|
14
|
-
define_hooks :after_start!, :after_stop!, :after_output
|
15
12
|
|
16
|
-
after_start
|
17
|
-
|
18
|
-
|
13
|
+
define_hooks :after_start!, :after_stop!, :before_stop!, :after_output
|
14
|
+
|
15
|
+
after_start! { logger.info("Zeusd") { "Start - pid(#{process.pid})" } }
|
16
|
+
before_stop! { logger.info("Zeusd") { "Stop - pid(#{process ? process.pid : 'nil'})" } }
|
19
17
|
|
20
18
|
after_stop! do
|
21
19
|
(socket_file.delete rescue nil) if socket_file.exist?
|
@@ -23,9 +21,12 @@ module Zeusd
|
|
23
21
|
|
24
22
|
after_output do |output|
|
25
23
|
interpreter.translate(output)
|
26
|
-
|
24
|
+
logger.info("Zeus"){output}
|
25
|
+
puts(output) if verbose
|
27
26
|
end
|
28
27
|
|
28
|
+
attr_reader :cwd, :verbose, :log_file, :interpreter, :child_process
|
29
|
+
|
29
30
|
def initialize(options = {})
|
30
31
|
@cwd = Pathname.new(options[:cwd] || Dir.pwd).realpath
|
31
32
|
@verbose = !!options[:verbose]
|
@@ -51,6 +52,8 @@ module Zeusd
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def stop!
|
55
|
+
run_hook :before_stop!
|
56
|
+
|
54
57
|
return self unless process
|
55
58
|
|
56
59
|
# Kill process tree and wait for exits
|
@@ -84,24 +87,16 @@ module Zeusd
|
|
84
87
|
cwd.join('.zeus.sock')
|
85
88
|
end
|
86
89
|
|
87
|
-
def verbose?
|
88
|
-
!!verbose
|
89
|
-
end
|
90
|
-
|
91
90
|
protected
|
92
91
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def ensure_log_worker
|
102
|
-
@log_worker ||= Thread.new do
|
103
|
-
while value = log_queue.shift
|
104
|
-
log_file.open("a+") {|f| f.write(value) }
|
92
|
+
def logger
|
93
|
+
@logger ||= Logger.new(log_file.to_path).tap do |x|
|
94
|
+
x.formatter = proc do |severity, datetime, progname, msg|
|
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"
|
105
100
|
end
|
106
101
|
end
|
107
102
|
end
|
@@ -117,8 +112,6 @@ module Zeusd
|
|
117
112
|
|
118
113
|
@writer.close
|
119
114
|
|
120
|
-
ensure_log_worker
|
121
|
-
|
122
115
|
Thread.new do
|
123
116
|
while (buffer = (@reader.readpartial(10000) rescue nil)) do
|
124
117
|
run_hook :after_output, buffer
|
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.1
|
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-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -215,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
segments:
|
217
217
|
- 0
|
218
|
-
hash:
|
218
|
+
hash: -796152463092065801
|
219
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
220
|
none: false
|
221
221
|
requirements:
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
segments:
|
226
226
|
- 0
|
227
|
-
hash:
|
227
|
+
hash: -796152463092065801
|
228
228
|
requirements: []
|
229
229
|
rubyforge_project:
|
230
230
|
rubygems_version: 1.8.25
|