dev-consul 0.6.4.2 → 0.6.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df9bc7bd362c366f8aa6d7956255a4e01f3380be
4
- data.tar.gz: bdc1b8342a183553b56ad18a5bda91d7d022fbef
3
+ metadata.gz: 2029c024629f6905adb767d67b2bc3bb593763ff
4
+ data.tar.gz: 1a3e128053da30c1e21c52907c5ea350383eb2e5
5
5
  SHA512:
6
- metadata.gz: 1670510daddc655943ea67d44151501eab71ca83847d91f7d2d5e4b4fc9974430f5f8ef01948b06d4f83a973768e3a191cc1b4d480d15bd25af06ed2475d8b68
7
- data.tar.gz: 598c080288de08dd7c6f7924c8ed9e478bb9c49b6b5ab68ea4fc50bc3b6afe440936597941a76250682e6b1993d01609e5618e65d06ce21cadf1f5c9214cd9dc
6
+ metadata.gz: 9068614d369eba883ae5648b5cb332d7b150ffb519b78ee08721e523d5956640621a0b3263aa808a55c18ea596da69be54258af3286857a96ae06cff3ccd45f5
7
+ data.tar.gz: 3eba8bc39d4d00044b5dee1ea8a37594b04b499dcf740be1025603385310714b7c36eec0a8e765626be6e1800403d9d6b216e53366bea28e1b49d473086760c5
data/Rakefile CHANGED
@@ -10,11 +10,11 @@ task :fetch do
10
10
  end
11
11
 
12
12
  task :run do
13
- Dev::Consul.run
13
+ Dev::Consul.run.wait
14
14
  end
15
15
 
16
16
  task :wait do
17
- Dev::Consul.wait
17
+ Dev::Consul.block
18
18
  end
19
19
 
20
20
  task :default => [:run, :wait]
@@ -36,72 +36,84 @@ module Dev
36
36
  File.join(bindir, "consul_#{VERSION}_#{platform}_#{architecture}")
37
37
  end
38
38
 
39
- def output(arg = nil)
40
- @thread[:output] = arg unless @thread.nil? || arg.nil?
41
- @thread[:output] unless @thread.nil?
39
+ attr_reader :output
40
+
41
+ ## Logging helper
42
+ def log(*message)
43
+ return unless output.is_a?(IO)
44
+
45
+ output.write(message.join(' ') + "\n")
46
+ output.flush
42
47
  end
43
48
 
44
- def run
45
- puts "Starting #{bin}"
49
+ def run(**options)
50
+ @output = options.fetch(:output, $stdout)
51
+ log "Starting #{bin}"
52
+
46
53
 
47
54
  ## Fork a child process for Consul from a thread
55
+ @stopped = false
48
56
  @thread = Thread.new do
49
57
  IO.popen("#{bin} agent -dev -advertise=127.0.0.1", 'r+') do |io|
50
58
  Thread.current[:process] = io.pid
51
- puts "Started #{bin} (#{io.pid})"
59
+ log "Started #{bin} (#{io.pid})"
52
60
 
53
61
  ## Stream output
54
62
  loop do
55
63
  break if io.eof?
56
64
  chunk = io.readpartial(1024)
57
65
 
58
- if Thread.current[:output]
59
- Thread.current[:output].write(chunk)
60
- Thread.current[:output].flush
61
- end
66
+ next unless output.is_a?(IO)
67
+ output.write(chunk)
68
+ output.flush
62
69
  end
63
70
  end
64
71
  end
65
72
 
66
- @thread[:output] = $stdout
73
+ self
74
+ end
67
75
 
76
+ def wait
68
77
  ## Wait for the service to become ready
69
78
  loop do
70
- begin
71
- leader = Net::HTTP.get('localhost', '/v1/status/leader', 8500)
79
+ break if @stopped || @thread.nil? || !@thread.alive?
72
80
 
73
- if leader == '""'
74
- puts 'Waiting for Consul HTTP API to be ready'
81
+ leader =
82
+ begin
83
+ Net::HTTP.get('localhost', '/v1/status/leader', 8500)
84
+ rescue Errno::ECONNREFUSED
85
+ log 'Waiting for Consul HTTP API to be ready'
75
86
  sleep 1
76
-
77
87
  next
78
88
  end
79
89
 
80
- puts 'Consul HTTP API is ready!'
81
- break
82
-
83
- rescue Errno::ECONNREFUSED
84
- puts 'Waiting for Consul HTTP API to be ready'
90
+ if leader == '""'
91
+ log 'Waiting for RAFT to initialize'
85
92
  sleep 1
93
+ next
86
94
  end
95
+
96
+ log 'Consul HTTP API is ready!'
97
+ break
87
98
  end
88
99
  end
89
100
 
90
- def wait
101
+ def block
91
102
  @thread.join unless @thread.nil?
92
103
  end
93
104
 
94
105
  def stop
95
106
  unless @thread.nil?
96
107
  unless @thread[:process].nil?
97
- puts "Stop #{bin} (#{@thread[:process]})"
98
- Process.kill('INT', @thread[:process])
108
+ log "Stop #{bin} (#{@thread[:process]})"
109
+ Process.kill('TERM', @thread[:process])
99
110
  end
100
111
 
101
112
  @thread.join
102
113
  end
103
114
 
104
115
  @thread = nil
116
+ @stopped = true
105
117
  end
106
118
  end
107
119
  end
@@ -1,6 +1,6 @@
1
1
  module Dev
2
2
  module Consul
3
- RELEASE = '2'.freeze
3
+ RELEASE = '3'.freeze
4
4
  VERSION = '0.6.4'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev-consul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4.2
4
+ version: 0.6.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Manero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zipruby