navy 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@navy"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.15.0 (master)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
@@ -12,7 +12,7 @@ class Navy::Captain < Navy::Rank
12
12
  # list of signals we care about and trap in admiral.
13
13
  QUEUE_SIGS = [ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP, :TTIN, :TTOU ]
14
14
 
15
- attr_accessor :label, :captain_pid, :officer_count, :officer_job
15
+ attr_accessor :label, :captain_pid, :officer_count, :officer_job, :officer_fire_and_forget
16
16
  attr_reader :admiral, :options
17
17
 
18
18
  def initialize(admiral, label, config, options = {})
@@ -124,7 +124,7 @@ class Navy::Captain < Navy::Rank
124
124
  before_stop.call(self, graceful) if before_stop
125
125
  limit = Time.now + patience
126
126
  until OFFICERS.empty? || (n = Time.now) > limit
127
- kill_each_officer(graceful ? :QUIT : :TERM)
127
+ kill_each_officer(graceful ? :QUIT : :TERM, officer_fire_and_forget)
128
128
  sleep(0.1)
129
129
  reap_all_officers
130
130
  end
@@ -221,16 +221,20 @@ class Navy::Captain < Navy::Rank
221
221
 
222
222
  # delivers a signal to a officer and fails gracefully if the officer
223
223
  # is no longer running.
224
- def kill_officer(signal, opid)
224
+ def kill_officer(signal, opid, detach = false)
225
225
  logger.debug "captain[#{label}] sending #{signal} to #{opid}" if $DEBUG
226
226
  Process.kill(signal, opid)
227
+ if detach
228
+ Process.detach(opid)
229
+ officer = OFFICERS.delete(opid) rescue nil
230
+ end
227
231
  rescue Errno::ESRCH
228
232
  officer = OFFICERS.delete(opid) rescue nil
229
233
  end
230
234
 
231
235
  # delivers a signal to each officer
232
- def kill_each_officer(signal)
233
- OFFICERS.keys.each { |opid| kill_officer(signal, opid) }
236
+ def kill_each_officer(signal, detach = false)
237
+ OFFICERS.keys.each { |opid| kill_officer(signal, opid, detach) }
234
238
  end
235
239
 
236
240
  def init_self_pipe!
@@ -18,6 +18,7 @@ class Navy::Captain::Orders < Navy::Orders
18
18
  end,
19
19
  officer_job: -> { trap(:QUIT) { exit }; trap(:TERM) { exit }; loop { sleep 1 } },
20
20
  officer_count: 0,
21
+ officer_fire_and_forget: false,
21
22
  patience: 30,
22
23
  post_fork: ->(captain, officer) do
23
24
  captain.logger.debug("(#{captain.label}) officer=#{officer.number} post-fork") if $DEBUG
@@ -1,8 +1,10 @@
1
1
  class Navy::Captain::Speak < Navy::Speak
2
2
 
3
3
  def officers(officer_count = 1, *args, &block)
4
+ options = args.last.is_a?(Hash) ? args.last : {}
4
5
  orders.set[:officer_count] = officer_count
5
6
  orders.set[:officer_job] = block_given? ? block : args[0]
7
+ orders.set[:officer_fire_and_forget] = options[:fire_and_forget] if options.has_key?(:fire_and_forget)
6
8
  end
7
9
 
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module Navy
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
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.1.1
4
+ version: 1.1.2
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: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -84,6 +84,7 @@ extensions: []
84
84
  extra_rdoc_files: []
85
85
  files:
86
86
  - .gitignore
87
+ - .rvmrc
87
88
  - Gemfile
88
89
  - LICENSE
89
90
  - README.md
@@ -118,17 +119,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
119
  - - ! '>='
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 1258671307750517922
121
125
  required_rubygems_version: !ruby/object:Gem::Requirement
122
126
  none: false
123
127
  requirements:
124
128
  - - ! '>='
125
129
  - !ruby/object:Gem::Version
126
130
  version: '0'
131
+ segments:
132
+ - 0
133
+ hash: 1258671307750517922
127
134
  requirements: []
128
135
  rubyforge_project:
129
- rubygems_version: 1.8.23
136
+ rubygems_version: 1.8.24
130
137
  signing_key:
131
138
  specification_version: 3
132
139
  summary: Ruby daemon inspired by Unicorn.
133
140
  test_files: []
134
- has_rdoc: