hookit 0.10.0 → 0.11.0

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: be8d878c31cfb5843f20a99980f9f2fa7491c6b6
4
- data.tar.gz: ce6373de03a2d8276e0b2409b080752d769dd08d
3
+ metadata.gz: 8ef6a1d03fe66b7dc858921b2c6f9b38c46dab67
4
+ data.tar.gz: 11ab5f5d41b157edbd05903ee92714bee86fae0a
5
5
  SHA512:
6
- metadata.gz: 6bd3cd48a338e2c33b8dec7e3a8bc111ad48cc971bccef2b4e685391e1bbd9f53e6d7959dcc2951065a88e72f9fac1f551ae6d10aec1f65dc5884f974b6d190e
7
- data.tar.gz: 9fdb4ddb415236a49171454b59eb9354bdf50579429c491112c3b3cebba0fc22614ab26285491926e179d72146f63ee85ffe69b8312807cf132db3b84647e156
6
+ metadata.gz: 695084242a78005016c86fbf9e26903e631bb2c1f6fe2a1094eac62a75a1f26cc077fc2f3a667ba3a048bfccc97c0b806d541f4091608c644acbaba2260c11bc
7
+ data.tar.gz: 177d445bc16ad1ec7fef87be550b105259a47f5b890f9923fac8e409ec56fece6a14e42f29356161716dc54e6dbff756550023ebb66477bc17d0045b2f9d960e
@@ -1,5 +1,5 @@
1
1
  require 'hookit/platform/base'
2
- require 'hookit/plaftorm/docker'
2
+ require 'hookit/platform/docker'
3
3
  require 'hookit/platform/smartos'
4
4
  require 'hookit/platform/ubuntu'
5
5
 
@@ -1,4 +1,5 @@
1
1
  require 'timeout'
2
+ require 'open3'
2
3
 
3
4
  module Hookit
4
5
  module Resource
@@ -13,6 +14,8 @@ module Hookit
13
14
  field :timeout
14
15
  field :stream
15
16
  field :on_data
17
+ field :on_stdout
18
+ field :on_stderr
16
19
  field :on_exit
17
20
  field :validator
18
21
  field :ignore_exit
@@ -66,31 +69,55 @@ module Hookit
66
69
  end
67
70
 
68
71
  def stream!
72
+ exit_status = 0
69
73
  result = ""
70
74
 
71
75
  STDOUT.sync = STDERR.sync = true # don't buffer stdout/stderr
72
76
 
73
- ::IO.popen(cmd, :err=>[:child, :out]) do |out|
74
- eof = false
75
- until eof do
76
- begin
77
- chunk = out.readpartial(4096)
78
- if on_data and on_data.respond_to? :call
79
- on_data.call(chunk)
77
+ Open3.popen3 cmd do |stdin, stdout, stderr, wait_thr|
78
+ stdout_eof = false
79
+ stderr_eof = false
80
+
81
+ until stdout_eof and stderr_eof do
82
+ (ready_pipes, dummy, dummy) = IO.select([stdout, stderr])
83
+ ready_pipes.each_with_index do |socket|
84
+ if socket == stdout
85
+ begin
86
+ chunk = socket.readpartial(4096)
87
+ if on_data and on_data.respond_to? :call
88
+ on_data.call(chunk)
89
+ end
90
+ if on_stdout and on_stdout.respond_to? :call
91
+ on_stdout.call(chunk)
92
+ end
93
+ rescue EOFError
94
+ stdout_eof = true
95
+ end
96
+ result << chunk.to_s
97
+ elsif socket == stderr
98
+ begin
99
+ chunk = socket.readpartial(4096)
100
+ if on_data and on_data.respond_to? :call
101
+ on_data.call(chunk)
102
+ end
103
+ if on_stderr and on_stderr.respond_to? :call
104
+ on_stderr.call(chunk)
105
+ end
106
+ rescue EOFError
107
+ stderr_eof = true
108
+ end
109
+ result << chunk.to_s
80
110
  end
81
- rescue EOFError
82
- eof = true
83
111
  end
84
- result << chunk.to_s
85
112
  end
86
- end
87
113
 
88
- code = $?.exitstatus
114
+ exit_status = wait_thr.value.to_s.match(/exit (\d+)/)[1].to_i
115
+ end
89
116
 
90
117
  if on_exit and on_exit.respond_to? :call
91
- on_exit.call(code)
118
+ on_exit.call(exit_status)
92
119
  else
93
- unexpected_exit(code) unless code == returns
120
+ unexpected_exit(exit_status) unless exit_status == returns
94
121
  end
95
122
 
96
123
  validate! result
@@ -49,11 +49,6 @@ module Hookit
49
49
  when :smf
50
50
  run_command! "svcadm enable -s #{"-r" if recursive} #{service_name}"
51
51
  when :runit
52
- # fail fast if we don't have an runit run configuration
53
- if not File.exist?("/etc/service/#{service_name}/run")
54
- raise Hookit::Error::MissingConfiguration "Expecting service configuration file at: /etc/service/#{service_name}/run"
55
- end
56
-
57
52
  # register and potentially start the service
58
53
  run_command! "sv start #{service_name}", false
59
54
 
@@ -119,4 +114,4 @@ module Hookit
119
114
 
120
115
  end
121
116
  end
122
- end
117
+ end
@@ -17,11 +17,11 @@ module Hookit
17
17
 
18
18
  case platform.os
19
19
  when 'sun'
20
- @active_com=`netstat -an | egrep '\*\.#{port}' | grep LISTEN`
21
- @inactive_com=`netstat -an | grep 'ESTABLISHED' | awk '{ print $1 }' | grep "$(ifconfig #{interface} | grep inet | awk '{ print $2 }')\.#{port}"`
20
+ @active_com = "netstat -an | egrep '\*\.#{port}' | grep LISTEN"
21
+ @inactive_com = "netstat -an | grep 'ESTABLISHED' | awk '{ print $1 }' | grep \"$(ifconfig #{interface} | grep inet | awk '{ print $2 }')\.#{port}\""
22
22
  else
23
- @active_com=`netstat -an | egrep ':#{port}' | grep LISTEN`
24
- @inactive_com=`netstat -an | grep 'ESTABLISHED' | awk '{ print $4 }' | grep "$(ifconfig #{interface} | awk '/inet addr/ { print $2}' | cut -f2 -d':' | tr -d '\n'):#{port}"`
23
+ @active_com = "netstat -an | egrep ':#{port}' | grep LISTEN"
24
+ @inactive_com = "netstat -an | grep 'ESTABLISHED' | awk '{ print $4 }' | grep \"$(ifconfig #{interface} | awk '/inet addr/ { print $2}' | cut -f2 -d':' | tr -d '\n'):#{port}\""
25
25
  end
26
26
  end
27
27
 
@@ -1,3 +1,3 @@
1
1
  module Hookit
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Flint
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-08 00:00:00.000000000 Z
12
+ date: 2015-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt