navy 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/navy/admiral.rb +12 -57
  2. data/lib/navy/version.rb +1 -1
  3. metadata +9 -9
@@ -30,69 +30,18 @@ class Navy::Admiral < Navy::Rank
30
30
  attr_reader :options
31
31
 
32
32
  def initialize(options = {})
33
+ self.reexec_pid = 0
34
+
33
35
  @options = options.dup
36
+ @ready_pipe = @options.delete(:ready_pipe)
34
37
  @options[:use_defaults] = true
35
38
  self.orders = Navy::Admiral::Orders.new(self.class, @options)
36
39
 
37
- self.reexec_pid = 0
38
- @ready_pipe = @options.delete(:ready_pipe)
39
-
40
- @orders.give!(self)
41
- # self.pid = "/tmp/navy.pid"
42
- # @captains = {
43
- # admin: {
44
- # number: 3,
45
- # job: ->(*args) {
46
- # trap(:QUIT) { exit }
47
- # trap(:TERM) { exit }
48
- # n = 0
49
- # loop do
50
- # # Navy.logger.info "#{n} admin called #{args.inspect}"
51
- # # Navy.logger.info "START_CTX: #{START_CTX.inspect}"
52
- # # Navy.logger.info "Navy::Admiral::CAPTAINS: #{Navy::Admiral::CAPTAINS.inspect}"
53
- # # Navy.logger.info "Navy::Admiral::OFFICERS: #{Navy::Captain::OFFICERS.inspect}"
54
- # sleep 10
55
- # n += 1
56
- # end
57
- # }
58
- # },
59
- # user: {
60
- # number: 3,
61
- # job: ->(*args) {
62
- # trap(:QUIT) { exit }
63
- # trap(:TERM) { exit }
64
- # n = 0
65
- # loop do
66
- # # Navy.logger.info "#{n} user called #{args.inspect}"
67
- # # Navy.logger.info "Navy::Admiral::CAPTAINS: #{Navy::Admiral::CAPTAINS.inspect}"
68
- # # Navy.logger.info "Navy::Admiral::OFFICERS: #{Navy::Captain::OFFICERS.inspect}"
69
- # sleep 10
70
- # n += 1
71
- # end
72
- # }
73
- # }
74
- # }
75
- # self.after_fork = ->(admiral, captain) do
76
- # admiral.logger.info("captain=#{captain.label} spawned pid=#{$$}")
77
- # end
78
- # self.before_fork = ->(admiral, captain) do
79
- # admiral.logger.info("captain=#{captain.label} spawning...")
80
- # # old_pid = "#{admiral.pid}.oldbin"
81
- # # if old_pid != admiral.pid
82
- # # begin
83
- # # sig = (captain.number + 1) >= captain.number ? :QUIT : :TTOU
84
- # # Process.kill(sig, File.read(old_pid).to_i)
85
- # # rescue Errno::ENOENT, Errno::ESRCH
86
- # # end
87
- # # end
88
- # # sleep 1
89
- # end
90
- # self.before_exec = ->(admiral) do
91
- # admiral.logger.info("forked child re-executing...")
92
- # end
40
+ orders.give!(self, except: [ :stderr_path, :stdout_path ])
93
41
  end
94
42
 
95
43
  def start
44
+ orders.give!(self, only: [ :stderr_path, :stdout_path ])
96
45
  init_self_pipe!
97
46
  QUEUE_SIGS.each do |sig|
98
47
  trap(sig) do
@@ -128,7 +77,7 @@ class Navy::Admiral < Navy::Rank
128
77
  # avoid murdering workers after our master process (or the
129
78
  # machine) comes out of suspend/hibernation
130
79
  if (last_check + @timeout) >= (last_check = Time.now)
131
- # sleep_time = murder_lazy_workers
80
+ sleep_time = murder_lazy_captains
132
81
  logger.debug("would normally murder lazy captains") if $DEBUG
133
82
  else
134
83
  sleep_time = @timeout/2.0 + 1
@@ -221,6 +170,11 @@ class Navy::Admiral < Navy::Rank
221
170
  end while true
222
171
  end
223
172
 
173
+ # forcibly terminate all workers that haven't checked in in timeout seconds. The timeout is implemented using an unlinked File
174
+ def murder_lazy_captains
175
+ @timeout - 1
176
+ end
177
+
224
178
  # reexecutes the START_CTX with a new binary
225
179
  def reexec
226
180
  if reexec_pid > 0
@@ -250,6 +204,7 @@ class Navy::Admiral < Navy::Rank
250
204
  logger.info "reexec admiral"
251
205
 
252
206
  self.reexec_pid = fork do
207
+ # ENV['NAVY_FD'] = listener_fds.keys.join(',')
253
208
  ENV['NAVY_FD'] = '1'
254
209
  Dir.chdir(START_CTX[:cwd])
255
210
  cmd = [ START_CTX[0] ].concat(START_CTX[:argv])
@@ -1,3 +1,3 @@
1
1
  module Navy
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
16
- requirement: &70092620874740 !ruby/object:Gem::Requirement
16
+ requirement: &70203870889220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70092620874740
24
+ version_requirements: *70203870889220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70092620874200 !ruby/object:Gem::Requirement
27
+ requirement: &70203870888700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70092620874200
35
+ version_requirements: *70203870888700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70092620922520 !ruby/object:Gem::Requirement
38
+ requirement: &70203870888080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70092620922520
46
+ version_requirements: *70203870888080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: kgio
49
- requirement: &70092620921860 !ruby/object:Gem::Requirement
49
+ requirement: &70203870936360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.6'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70092620921860
57
+ version_requirements: *70203870936360
58
58
  description: Ruby daemon inspired by Unicorn.
59
59
  email:
60
60
  - potatosaladx@gmail.com