emissary 1.3.0
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/LICENSE +203 -0
- data/README.txt +54 -0
- data/VERSION.yml +4 -0
- data/bin/emissary +196 -0
- data/bin/emissary-setup +75 -0
- data/etc/emissary/config.ini +13 -0
- data/etc/init.d/emissary +50 -0
- data/lib/emissary.rb +223 -0
- data/lib/emissary/agent.rb +61 -0
- data/lib/emissary/agent/emissary.rb +163 -0
- data/lib/emissary/agent/error.rb +26 -0
- data/lib/emissary/agent/file.rb +26 -0
- data/lib/emissary/agent/gem.rb +42 -0
- data/lib/emissary/agent/mysql.rb +219 -0
- data/lib/emissary/agent/ping.rb +37 -0
- data/lib/emissary/agent/proxy.rb +26 -0
- data/lib/emissary/agent/rabbitmq.rb +233 -0
- data/lib/emissary/agent/sshkeys.rb +152 -0
- data/lib/emissary/agent/stats.rb +96 -0
- data/lib/emissary/agent/test.rb +40 -0
- data/lib/emissary/config.rb +231 -0
- data/lib/emissary/core_ext/blank.rb +60 -0
- data/lib/emissary/core_ext/misc_object.rb +21 -0
- data/lib/emissary/core_ext/symbolize.rb +33 -0
- data/lib/emissary/daemon.rb +404 -0
- data/lib/emissary/errors.rb +106 -0
- data/lib/emissary/gem_helper.rb +183 -0
- data/lib/emissary/identity.rb +183 -0
- data/lib/emissary/identity/ec2.rb +64 -0
- data/lib/emissary/identity/unix.rb +67 -0
- data/lib/emissary/logger.rb +130 -0
- data/lib/emissary/message.rb +217 -0
- data/lib/emissary/operator.rb +274 -0
- data/lib/emissary/operator/amqp.rb +203 -0
- data/lib/emissary/server.rb +98 -0
- data/lib/emissary/servolux.rb +75 -0
- metadata +262 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
# Copyright 2010 The New York Times
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
require 'emissary/servolux'
|
17
|
+
require 'eventmachine'
|
18
|
+
|
19
|
+
module Emissary
|
20
|
+
class Server < Servolux::Server
|
21
|
+
attr_accessor :running
|
22
|
+
|
23
|
+
def initialize(name, opts = {}, &block)
|
24
|
+
opts[:logger] = Emissary.logger
|
25
|
+
@running = false
|
26
|
+
@operator = opts.delete(:operator) or raise Emissary::Error.new(ArgumentError, "Operator not provided")
|
27
|
+
|
28
|
+
at_exit { shutdown! :graceful }
|
29
|
+
super(name, opts, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def running?() !!@running; end
|
33
|
+
|
34
|
+
def shutdown! type = :graceful
|
35
|
+
begin
|
36
|
+
case type
|
37
|
+
when :graceful
|
38
|
+
@operator.shutdown! unless not @operator.connected?
|
39
|
+
EM.stop_event_loop
|
40
|
+
end
|
41
|
+
rescue Exception => e
|
42
|
+
Emissary.logger.error "Exception caught during graceful shutdown: #{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
43
|
+
ensure
|
44
|
+
exit!(0)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
alias :int :shutdown!
|
49
|
+
alias :term :shutdown!
|
50
|
+
|
51
|
+
# override Servolux::Server's startup because we don't need threaded here.
|
52
|
+
# also, we want to enforce exiting on completion of startup's run
|
53
|
+
def startup
|
54
|
+
return self unless not running?
|
55
|
+
|
56
|
+
begin
|
57
|
+
create_pid_file
|
58
|
+
trap_signals
|
59
|
+
run
|
60
|
+
rescue Exception => e
|
61
|
+
# if something is caught here, then we can only log it. at this point we are in an
|
62
|
+
# unknown state and can only delete our pid file and #exit!. Attempting to call
|
63
|
+
# our #term method could cause other problems here.
|
64
|
+
Emissary.logger.error "Server '#{$0}': #{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
65
|
+
ensure
|
66
|
+
delete_pid_file
|
67
|
+
shutdown! :hard
|
68
|
+
end
|
69
|
+
|
70
|
+
return self
|
71
|
+
end
|
72
|
+
|
73
|
+
def run
|
74
|
+
return unless not running?
|
75
|
+
|
76
|
+
thr = Thread.new { EM.run }
|
77
|
+
|
78
|
+
begin
|
79
|
+
EM.add_periodic_timer(0.5) { @operator.shutdown! unless not @operator.shutting_down? }
|
80
|
+
|
81
|
+
begin
|
82
|
+
$0 = @name
|
83
|
+
logger.info "Starting up new Operator process"
|
84
|
+
@running = @operator.run
|
85
|
+
rescue Exception => e
|
86
|
+
Emissary.logger.error "Server '#{$0}': #{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
87
|
+
raise e
|
88
|
+
end
|
89
|
+
rescue ::Emissary::Error::ConnectionError => e
|
90
|
+
shutdown! :hard
|
91
|
+
rescue Exception => e
|
92
|
+
shutdown! :graceful
|
93
|
+
end
|
94
|
+
|
95
|
+
thr.join
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright 2010 The New York Times
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
require 'servolux'
|
17
|
+
|
18
|
+
# monkey patches for servolux
|
19
|
+
class Servolux::Daemon
|
20
|
+
# provide pid to external libraries
|
21
|
+
def get_pid() retrieve_pid; end
|
22
|
+
def alive?
|
23
|
+
pid = retrieve_pid
|
24
|
+
Process.kill(0, pid)
|
25
|
+
true
|
26
|
+
rescue TypeError # don't fail on nil being passed to kill
|
27
|
+
# usually means pid was nil, so return false
|
28
|
+
false
|
29
|
+
rescue Errno::ESRCH, Errno::ENOENT
|
30
|
+
false
|
31
|
+
rescue Errno::EACCES => err
|
32
|
+
logger.error "You do not have access to the PID file at " \
|
33
|
+
"#{pid_file.inspect}: #{err.message}"
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Servolux::Piper
|
39
|
+
def initialize( *args )
|
40
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
41
|
+
mode = args.first || 'r'
|
42
|
+
|
43
|
+
unless %w[r w rw].include? mode
|
44
|
+
raise ArgumentError, "Unsupported mode #{mode.inspect}"
|
45
|
+
end
|
46
|
+
|
47
|
+
@timeout = opts.key?(:timeout) ? opts[:timeout] : nil
|
48
|
+
socket_pair = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0)
|
49
|
+
@child_pid = Kernel.fork
|
50
|
+
|
51
|
+
if child?
|
52
|
+
@socket = socket_pair[1]
|
53
|
+
socket_pair[0].close
|
54
|
+
|
55
|
+
case mode
|
56
|
+
when 'r'; @socket.close_read
|
57
|
+
when 'w'; @socket.close_write
|
58
|
+
end
|
59
|
+
else
|
60
|
+
# prevent zombie processes - register disinterest
|
61
|
+
# in return status of child process
|
62
|
+
Process.detach @child_pid
|
63
|
+
|
64
|
+
@socket = socket_pair[0]
|
65
|
+
socket_pair[1].close
|
66
|
+
|
67
|
+
case mode
|
68
|
+
when 'r'; @socket.close_write
|
69
|
+
when 'w'; @socket.close_read
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
metadata
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emissary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Carl P. Corliss
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-19 00:00:00 -04:00
|
19
|
+
default_executable: bin/emissary-setup
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: daemons
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 10
|
34
|
+
version: 1.0.10
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: inifile
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 19
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 3
|
49
|
+
- 0
|
50
|
+
version: 0.3.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: sys-cpu
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 6
|
65
|
+
- 2
|
66
|
+
version: 0.6.2
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bert
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 1
|
81
|
+
- 2
|
82
|
+
version: 1.1.2
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: amqp
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 9
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 6
|
97
|
+
- 7
|
98
|
+
version: 0.6.7
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: carrot
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 1
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 7
|
113
|
+
- 1
|
114
|
+
version: 0.7.1
|
115
|
+
type: :runtime
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: eventmachine
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 59
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
- 12
|
129
|
+
- 10
|
130
|
+
version: 0.12.10
|
131
|
+
type: :runtime
|
132
|
+
version_requirements: *id007
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: servolux
|
135
|
+
prerelease: false
|
136
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 51
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
- 9
|
145
|
+
- 4
|
146
|
+
version: 0.9.4
|
147
|
+
type: :runtime
|
148
|
+
version_requirements: *id008
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: uuid
|
151
|
+
prerelease: false
|
152
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 2
|
160
|
+
- 3
|
161
|
+
- 0
|
162
|
+
version: 2.3.0
|
163
|
+
type: :runtime
|
164
|
+
version_requirements: *id009
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: work_queue
|
167
|
+
prerelease: false
|
168
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
hash: 23
|
174
|
+
segments:
|
175
|
+
- 1
|
176
|
+
- 0
|
177
|
+
- 0
|
178
|
+
version: 1.0.0
|
179
|
+
type: :runtime
|
180
|
+
version_requirements: *id010
|
181
|
+
description:
|
182
|
+
email: carl.corliss@nytimes.com
|
183
|
+
executables:
|
184
|
+
- emissary
|
185
|
+
- emissary-setup
|
186
|
+
extensions: []
|
187
|
+
|
188
|
+
extra_rdoc_files:
|
189
|
+
- README.txt
|
190
|
+
files:
|
191
|
+
- lib/emissary.rb
|
192
|
+
- lib/emissary/servolux.rb
|
193
|
+
- lib/emissary/server.rb
|
194
|
+
- lib/emissary/operator.rb
|
195
|
+
- lib/emissary/operator/amqp.rb
|
196
|
+
- lib/emissary/message.rb
|
197
|
+
- lib/emissary/logger.rb
|
198
|
+
- lib/emissary/identity.rb
|
199
|
+
- lib/emissary/identity/unix.rb
|
200
|
+
- lib/emissary/identity/ec2.rb
|
201
|
+
- lib/emissary/gem_helper.rb
|
202
|
+
- lib/emissary/errors.rb
|
203
|
+
- lib/emissary/daemon.rb
|
204
|
+
- lib/emissary/core_ext/symbolize.rb
|
205
|
+
- lib/emissary/core_ext/misc_object.rb
|
206
|
+
- lib/emissary/core_ext/blank.rb
|
207
|
+
- lib/emissary/config.rb
|
208
|
+
- lib/emissary/agent.rb
|
209
|
+
- lib/emissary/agent/test.rb
|
210
|
+
- lib/emissary/agent/stats.rb
|
211
|
+
- lib/emissary/agent/sshkeys.rb
|
212
|
+
- lib/emissary/agent/rabbitmq.rb
|
213
|
+
- lib/emissary/agent/proxy.rb
|
214
|
+
- lib/emissary/agent/ping.rb
|
215
|
+
- lib/emissary/agent/mysql.rb
|
216
|
+
- lib/emissary/agent/gem.rb
|
217
|
+
- lib/emissary/agent/file.rb
|
218
|
+
- lib/emissary/agent/error.rb
|
219
|
+
- lib/emissary/agent/emissary.rb
|
220
|
+
- etc/init.d/emissary
|
221
|
+
- etc/emissary/config.ini
|
222
|
+
- bin/emissary-setup
|
223
|
+
- bin/emissary
|
224
|
+
- VERSION.yml
|
225
|
+
- LICENSE
|
226
|
+
- README.txt
|
227
|
+
has_rdoc: true
|
228
|
+
homepage: http://www.nytimes.com/
|
229
|
+
licenses: []
|
230
|
+
|
231
|
+
post_install_message:
|
232
|
+
rdoc_options: []
|
233
|
+
|
234
|
+
require_paths:
|
235
|
+
- lib
|
236
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
237
|
+
none: false
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
hash: 3
|
242
|
+
segments:
|
243
|
+
- 0
|
244
|
+
version: "0"
|
245
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
|
+
none: false
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
hash: 3
|
251
|
+
segments:
|
252
|
+
- 0
|
253
|
+
version: "0"
|
254
|
+
requirements: []
|
255
|
+
|
256
|
+
rubyforge_project:
|
257
|
+
rubygems_version: 1.3.7
|
258
|
+
signing_key:
|
259
|
+
specification_version: 3
|
260
|
+
summary: EventMachine/AMQP based event handling client
|
261
|
+
test_files: []
|
262
|
+
|