emissary 1.3.20 → 1.3.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emissary
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 20
10
- version: 1.3.20
9
+ - 21
10
+ version: 1.3.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl P. Corliss
@@ -189,10 +189,46 @@ extensions: []
189
189
  extra_rdoc_files: []
190
190
 
191
191
  files:
192
- - bin/emissary-setup
193
- - bin/emissary-send-message
194
- - bin/emissary
195
192
  - bin/amqp-listen
193
+ - bin/emissary
194
+ - bin/emissary-send-message
195
+ - bin/emissary-setup
196
+ - lib/emissary/agent/emissary.rb
197
+ - lib/emissary/agent/error.rb
198
+ - lib/emissary/agent/file.rb
199
+ - lib/emissary/agent/gem.rb
200
+ - lib/emissary/agent/mysql.rb
201
+ - lib/emissary/agent/ping.rb
202
+ - lib/emissary/agent/proxy.rb
203
+ - lib/emissary/agent/rabbitmq.rb
204
+ - lib/emissary/agent/sshkeys.rb
205
+ - lib/emissary/agent/stats.rb
206
+ - lib/emissary/agent/test.rb
207
+ - lib/emissary/agent.rb
208
+ - lib/emissary/config.rb
209
+ - lib/emissary/core_ext/blank.rb
210
+ - lib/emissary/core_ext/misc_object.rb
211
+ - lib/emissary/core_ext/symbolize.rb
212
+ - lib/emissary/daemon.rb
213
+ - lib/emissary/errors.rb
214
+ - lib/emissary/gem_helper.rb
215
+ - lib/emissary/identity/ec2.rb
216
+ - lib/emissary/identity/unix.rb
217
+ - lib/emissary/identity.rb
218
+ - lib/emissary/inifile.rb
219
+ - lib/emissary/logger.rb
220
+ - lib/emissary/message.rb
221
+ - lib/emissary/operator/amqp.rb
222
+ - lib/emissary/operator.rb
223
+ - lib/emissary/server.rb
224
+ - lib/emissary/servolux.rb
225
+ - lib/emissary.rb
226
+ - LICENSE
227
+ - README.txt
228
+ - Rakefile
229
+ - Manifest.txt
230
+ - VERSION.yml
231
+ - History.txt
196
232
  homepage: http://nimbul.github.com/nimbul/
197
233
  licenses: []
198
234