mixlib-shellout 1.4.0 → 1.6.0.rc.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: bb92770f369fa7a1e9f8243f593003270d96cb6d
4
- data.tar.gz: b09589f82ed5085958214e21258df8cf99127f17
3
+ metadata.gz: 021c7f8efea2d6d11f349b4a1728d3039567b191
4
+ data.tar.gz: b9d6684c7b751462d6e4c2cea479f39474e3ee6d
5
5
  SHA512:
6
- metadata.gz: 52112e577474277ba2f4d63855253f8d4f93c6edda83795486ebec788d07ab5bff038bd9b4c73f32d5ac3a1e056620e04570fc21a81dbbb87616735919635b6c
7
- data.tar.gz: dcf9457cf588943d54eafb2448be13c2015ac5b57a32ca02ad1bf16d4102a26e84d29e32f5d06e027336a21bd546751366f89631371e375c3c6dc7760dec91fb
6
+ metadata.gz: e4a1e30bb080f4bad1697480360acc76b852a32d46d1f8e350e2ce1a0c9024734a5f3ce0377c56ad5a72207084410bcb32eaa1477bb25e7e1ea51f4a1e840e24
7
+ data.tar.gz: 674076ca9e875c2b2b55d604f6ce3279c99e87014002429e51e1d1eeaac245947dbbbddd3811d32df5ca17e97910687ffaed91f9de7e41950b961be7cfcc27dd
data/README.md CHANGED
@@ -37,7 +37,7 @@ Invoke crontab to edit user cron:
37
37
  crontab.run_command
38
38
 
39
39
  ## Windows Impersonation Example
40
- Invoke crontab to edit user cron:
40
+ Invoke "whoami.exe" to demonstrate running a command as another user:
41
41
 
42
42
  whomai = Mixlib::ShellOut.new("whoami.exe", :user => "username", :domain => "DOMAIN", :password => "password")
43
43
  whoami.run_command
@@ -51,4 +51,4 @@ Apache 2 Licensed. See LICENSE for full details.
51
51
 
52
52
  ## See Also
53
53
  * `Process.spawn` in Ruby 1.9
54
- * [https://github.com/rtomayko/posix-spawn](posix-spawn)
54
+ * [https://github.com/rtomayko/posix-spawn](https://github.com/rtomayko/posix-spawn)
@@ -53,10 +53,13 @@ module Mixlib
53
53
  # to determine if the command was successful. Normally set via options to new
54
54
  attr_accessor :valid_exit_codes
55
55
 
56
- # When live_stream is set, stdout of the subprocess will be copied to it as
57
- # the subprocess is running. For example, if live_stream is set to STDOUT,
58
- # the command's output will be echoed to STDOUT.
59
- attr_accessor :live_stream
56
+ # When live_stdout is set, the stdout of the subprocess will be copied to it
57
+ # as the subprocess is running.
58
+ attr_accessor :live_stdout
59
+
60
+ # When live_stderr is set, the stderr of the subprocess will be copied to it
61
+ # as the subprocess is running.
62
+ attr_accessor :live_stderr
60
63
 
61
64
  # ShellOut will push data from :input down the stdin of the subprocss.
62
65
  # Normally set via options passed to new.
@@ -147,7 +150,7 @@ module Mixlib
147
150
  # cmd.run_command # etc.
148
151
  def initialize(*command_args)
149
152
  @stdout, @stderr = '', ''
150
- @live_stream = nil
153
+ @live_stdout = @live_stderr = nil
151
154
  @input = nil
152
155
  @log_level = :debug
153
156
  @log_tag = nil
@@ -163,6 +166,18 @@ module Mixlib
163
166
  @command = command_args.size == 1 ? command_args.first : command_args
164
167
  end
165
168
 
169
+ # Returns the stream that both is being used by both live_stdout and live_stderr, or nil
170
+ def live_stream
171
+ live_stdout == live_stderr ? live_stdout : nil
172
+ end
173
+
174
+ # A shortcut for setting both live_stdout and live_stderr, so that both the
175
+ # stdout and stderr from the subprocess will be copied to the same stream as
176
+ # the subprocess is running.
177
+ def live_stream=(stream)
178
+ @live_stdout = @live_stderr = stream
179
+ end
180
+
166
181
  # Set the umask that the subprocess will have. If given as a string, it
167
182
  # will be converted to an integer by String#oct.
168
183
  def umask=(new_umask)
@@ -286,7 +301,11 @@ module Mixlib
286
301
  when 'returns'
287
302
  self.valid_exit_codes = Array(setting)
288
303
  when 'live_stream'
289
- self.live_stream = setting
304
+ self.live_stdout = self.live_stderr = setting
305
+ when 'live_stdout'
306
+ self.live_stdout = setting
307
+ when 'live_stderr'
308
+ self.live_stderr = setting
290
309
  when 'input'
291
310
  self.input = setting
292
311
  when 'logger'
@@ -115,7 +115,7 @@ module Mixlib
115
115
  # If the child dies very quickly, @child_pid may be a zombie, so handle
116
116
  # ESRCH here.
117
117
  @child_pgid = -Process.getpgid(@child_pid)
118
- rescue Errno::ESRCH
118
+ rescue Errno::ESRCH, Errno::EPERM
119
119
  @child_pgid = nil
120
120
  end
121
121
 
@@ -278,7 +278,7 @@ module Mixlib
278
278
  def read_stdout_to_buffer
279
279
  while chunk = child_stdout.read_nonblock(READ_SIZE)
280
280
  @stdout << chunk
281
- @live_stream << chunk if @live_stream
281
+ @live_stdout << chunk if @live_stdout
282
282
  end
283
283
  rescue Errno::EAGAIN
284
284
  rescue EOFError
@@ -288,6 +288,7 @@ module Mixlib
288
288
  def read_stderr_to_buffer
289
289
  while chunk = child_stderr.read_nonblock(READ_SIZE)
290
290
  @stderr << chunk
291
+ @live_stderr << chunk if @live_stderr
291
292
  end
292
293
  rescue Errno::EAGAIN
293
294
  rescue EOFError
@@ -345,12 +346,12 @@ module Mixlib
345
346
 
346
347
  def reap_errant_child
347
348
  return if attempt_reap
348
- @terminate_reason = "Command execeded allowed execution time, process terminated"
349
- logger.error("Command execeded allowed execution time, sending TERM") if logger
349
+ @terminate_reason = "Command exceeded allowed execution time, process terminated"
350
+ logger.error("Command exceeded allowed execution time, sending TERM") if logger
350
351
  Process.kill(:TERM, child_pgid)
351
352
  sleep 3
352
353
  attempt_reap
353
- logger.error("Command execeded allowed execution time, sending KILL") if logger
354
+ logger.error("Command exceeded allowed execution time, sending KILL") if logger
354
355
  Process.kill(:KILL, child_pgid)
355
356
  reap
356
357
 
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "1.4.0"
3
+ VERSION = "1.6.0.rc.0"
4
4
  end
5
5
  end
@@ -165,7 +165,9 @@ module Mixlib
165
165
 
166
166
  if ready.first.include?(stderr_read)
167
167
  begin
168
- @stderr << stderr_read.readpartial(READ_SIZE)
168
+ next_chunk = stderr_read.readpartial(READ_SIZE)
169
+ @stderr << next_chunk
170
+ @live_stderr << next_chunk if @live_stderr
169
171
  rescue EOFError
170
172
  stderr_read.close
171
173
  open_streams.delete(stderr_read)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0.rc.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Opscode
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-08 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -54,9 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ">="
57
+ - - ">"
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: 1.3.1
60
60
  requirements: []
61
61
  rubyforge_project:
62
62
  rubygems_version: 2.2.2