portertech-sensu-spawn 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +148 -0
- data/LICENSE.txt +20 -0
- data/README.md +28 -0
- data/lib/sensu/spawn.rb +180 -0
- data/sensu-spawn.gemspec +26 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dc6df05e8c6e108291827db4c0562b0ac0d69e793f69bd049a4a2fe4c7209b43
|
|
4
|
+
data.tar.gz: cebaf8bbca9bc1f07004509c6b81ed1a68d43cc64da687ef6a97b78b8296563b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5a7d77b7df604a77bd52a8ba50bf68a34c096211f0f76b93c47e641a6739fa4d5f8a2f1d5c47903431b315f0c809ccebb8729d667c37fceef08bd429707a542e
|
|
7
|
+
data.tar.gz: '0568e9075095b44cb18fb3118efcff1dd01303cf4216fa9e96ac448085810c64eb5986186803c7e6ee04c9829b25743d9f5acf1c3f441768c5ef63f9aecf9ce3'
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## [Unreleased](https://github.com/sensu/sensu-spawn/tree/HEAD)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.4.1...HEAD)
|
|
6
|
+
|
|
7
|
+
**Merged pull requests:**
|
|
8
|
+
|
|
9
|
+
- Include stop error message in timeout output [\#25](https://github.com/sensu/sensu-spawn/pull/25) ([portertech](https://github.com/portertech))
|
|
10
|
+
|
|
11
|
+
## [v2.4.1](https://github.com/sensu/sensu-spawn/tree/v2.4.1) (2018-04-18)
|
|
12
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.4.0...v2.4.1)
|
|
13
|
+
|
|
14
|
+
**Merged pull requests:**
|
|
15
|
+
|
|
16
|
+
- Pin FFI version on load \(as well as install\) [\#28](https://github.com/sensu/sensu-spawn/pull/28) ([portertech](https://github.com/portertech))
|
|
17
|
+
|
|
18
|
+
## [v2.4.0](https://github.com/sensu/sensu-spawn/tree/v2.4.0) (2018-04-18)
|
|
19
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.3.0...v2.4.0)
|
|
20
|
+
|
|
21
|
+
**Merged pull requests:**
|
|
22
|
+
|
|
23
|
+
- Revert "Revert "Only enable posix spawn on x86\_64 and i386"" [\#27](https://github.com/sensu/sensu-spawn/pull/27) ([portertech](https://github.com/portertech))
|
|
24
|
+
- Pin FFI at 1.9.21, newer versions segfault on CentOS [\#26](https://github.com/sensu/sensu-spawn/pull/26) ([portertech](https://github.com/portertech))
|
|
25
|
+
- Revert "Only enable posix spawn on x86\_64 and i386" [\#24](https://github.com/sensu/sensu-spawn/pull/24) ([portertech](https://github.com/portertech))
|
|
26
|
+
|
|
27
|
+
## [v2.3.0](https://github.com/sensu/sensu-spawn/tree/v2.3.0) (2018-04-12)
|
|
28
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.2.2...v2.3.0)
|
|
29
|
+
|
|
30
|
+
**Merged pull requests:**
|
|
31
|
+
|
|
32
|
+
- Only enable posix spawn on x86\_64 and i386 [\#23](https://github.com/sensu/sensu-spawn/pull/23) ([portertech](https://github.com/portertech))
|
|
33
|
+
|
|
34
|
+
## [v2.2.2](https://github.com/sensu/sensu-spawn/tree/v2.2.2) (2018-03-08)
|
|
35
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.2.1...v2.2.2)
|
|
36
|
+
|
|
37
|
+
**Merged pull requests:**
|
|
38
|
+
|
|
39
|
+
- Sign the sensu-spawn Ruby gem [\#22](https://github.com/sensu/sensu-spawn/pull/22) ([portertech](https://github.com/portertech))
|
|
40
|
+
- Implement automated changelog generation [\#21](https://github.com/sensu/sensu-spawn/pull/21) ([cwjohnston](https://github.com/cwjohnston))
|
|
41
|
+
|
|
42
|
+
## [v2.2.1](https://github.com/sensu/sensu-spawn/tree/v2.2.1) (2016-09-12)
|
|
43
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.2.0...v2.2.1)
|
|
44
|
+
|
|
45
|
+
**Merged pull requests:**
|
|
46
|
+
|
|
47
|
+
- Only include necessary gem files [\#19](https://github.com/sensu/sensu-spawn/pull/19) ([amdprophet](https://github.com/amdprophet))
|
|
48
|
+
|
|
49
|
+
## [v2.2.0](https://github.com/sensu/sensu-spawn/tree/v2.2.0) (2016-05-27)
|
|
50
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.1.0...v2.2.0)
|
|
51
|
+
|
|
52
|
+
**Merged pull requests:**
|
|
53
|
+
|
|
54
|
+
- Fixed child process large STDIN writes [\#17](https://github.com/sensu/sensu-spawn/pull/17) ([portertech](https://github.com/portertech))
|
|
55
|
+
|
|
56
|
+
## [v2.1.0](https://github.com/sensu/sensu-spawn/tree/v2.1.0) (2016-05-26)
|
|
57
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v2.0.0...v2.1.0)
|
|
58
|
+
|
|
59
|
+
**Closed issues:**
|
|
60
|
+
|
|
61
|
+
- Command with large output \( larger than STDOUT buffer\) times out if any timeout is set [\#14](https://github.com/sensu/sensu-spawn/issues/14)
|
|
62
|
+
|
|
63
|
+
**Merged pull requests:**
|
|
64
|
+
|
|
65
|
+
- Replace poll\_for\_exit with stdlib Timeout to fix large output deadlock [\#15](https://github.com/sensu/sensu-spawn/pull/15) ([tbriggs-curse](https://github.com/tbriggs-curse))
|
|
66
|
+
|
|
67
|
+
## [v2.0.0](https://github.com/sensu/sensu-spawn/tree/v2.0.0) (2016-05-17)
|
|
68
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.8.0...v2.0.0)
|
|
69
|
+
|
|
70
|
+
**Merged pull requests:**
|
|
71
|
+
|
|
72
|
+
- Configurable spawn child process limit [\#16](https://github.com/sensu/sensu-spawn/pull/16) ([portertech](https://github.com/portertech))
|
|
73
|
+
|
|
74
|
+
## [v1.8.0](https://github.com/sensu/sensu-spawn/tree/v1.8.0) (2016-03-10)
|
|
75
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.7.0...v1.8.0)
|
|
76
|
+
|
|
77
|
+
**Merged pull requests:**
|
|
78
|
+
|
|
79
|
+
- Moved FFI require into load error rescue block, fixing AIX build [\#13](https://github.com/sensu/sensu-spawn/pull/13) ([portertech](https://github.com/portertech))
|
|
80
|
+
|
|
81
|
+
## [v1.7.0](https://github.com/sensu/sensu-spawn/tree/v1.7.0) (2016-03-01)
|
|
82
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.6.0...v1.7.0)
|
|
83
|
+
|
|
84
|
+
**Closed issues:**
|
|
85
|
+
|
|
86
|
+
- childprocess posix\_spawn does not support freebsd [\#9](https://github.com/sensu/sensu-spawn/issues/9)
|
|
87
|
+
|
|
88
|
+
**Merged pull requests:**
|
|
89
|
+
|
|
90
|
+
- Only enable POSIX Spawn for Linux & OS X [\#10](https://github.com/sensu/sensu-spawn/pull/10) ([portertech](https://github.com/portertech))
|
|
91
|
+
|
|
92
|
+
## [v1.6.0](https://github.com/sensu/sensu-spawn/tree/v1.6.0) (2015-11-13)
|
|
93
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.5.0...v1.6.0)
|
|
94
|
+
|
|
95
|
+
**Merged pull requests:**
|
|
96
|
+
|
|
97
|
+
- Fix Windows job handle leak [\#8](https://github.com/sensu/sensu-spawn/pull/8) ([portertech](https://github.com/portertech))
|
|
98
|
+
|
|
99
|
+
## [v1.5.0](https://github.com/sensu/sensu-spawn/tree/v1.5.0) (2015-09-16)
|
|
100
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.4.0...v1.5.0)
|
|
101
|
+
|
|
102
|
+
**Merged pull requests:**
|
|
103
|
+
|
|
104
|
+
- Remove sensu-em as a dependency, let Sensu core determine which em to use [\#7](https://github.com/sensu/sensu-spawn/pull/7) ([portertech](https://github.com/portertech))
|
|
105
|
+
|
|
106
|
+
## [v1.4.0](https://github.com/sensu/sensu-spawn/tree/v1.4.0) (2015-09-09)
|
|
107
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.3.0...v1.4.0)
|
|
108
|
+
|
|
109
|
+
**Merged pull requests:**
|
|
110
|
+
|
|
111
|
+
- Use a mutex for childprocess posix spawn [\#6](https://github.com/sensu/sensu-spawn/pull/6) ([portertech](https://github.com/portertech))
|
|
112
|
+
|
|
113
|
+
## [v1.3.0](https://github.com/sensu/sensu-spawn/tree/v1.3.0) (2015-07-09)
|
|
114
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.2.0...v1.3.0)
|
|
115
|
+
|
|
116
|
+
**Merged pull requests:**
|
|
117
|
+
|
|
118
|
+
- Bump childprocess to latest available \(0.5.6\) [\#5](https://github.com/sensu/sensu-spawn/pull/5) ([darix](https://github.com/darix))
|
|
119
|
+
|
|
120
|
+
## [v1.2.0](https://github.com/sensu/sensu-spawn/tree/v1.2.0) (2015-05-29)
|
|
121
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.1.0...v1.2.0)
|
|
122
|
+
|
|
123
|
+
**Merged pull requests:**
|
|
124
|
+
|
|
125
|
+
- Require POSIX spawn libs immediately [\#4](https://github.com/sensu/sensu-spawn/pull/4) ([portertech](https://github.com/portertech))
|
|
126
|
+
|
|
127
|
+
## [v1.1.0](https://github.com/sensu/sensu-spawn/tree/v1.1.0) (2014-09-15)
|
|
128
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v1.0.0...v1.1.0)
|
|
129
|
+
|
|
130
|
+
**Merged pull requests:**
|
|
131
|
+
|
|
132
|
+
- use a spec asset for testing output larger than 64KB \(ascii\) [\#3](https://github.com/sensu/sensu-spawn/pull/3) ([portertech](https://github.com/portertech))
|
|
133
|
+
- lock java-jars for travis-ci jruby build [\#2](https://github.com/sensu/sensu-spawn/pull/2) ([portertech](https://github.com/portertech))
|
|
134
|
+
- Parent should not wait for child before closing its write end of pipe [\#1](https://github.com/sensu/sensu-spawn/pull/1) ([nlim](https://github.com/nlim))
|
|
135
|
+
|
|
136
|
+
## [v1.0.0](https://github.com/sensu/sensu-spawn/tree/v1.0.0) (2014-06-12)
|
|
137
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v0.0.3...v1.0.0)
|
|
138
|
+
|
|
139
|
+
## [v0.0.3](https://github.com/sensu/sensu-spawn/tree/v0.0.3) (2014-05-24)
|
|
140
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v0.0.2...v0.0.3)
|
|
141
|
+
|
|
142
|
+
## [v0.0.2](https://github.com/sensu/sensu-spawn/tree/v0.0.2) (2014-05-24)
|
|
143
|
+
[Full Changelog](https://github.com/sensu/sensu-spawn/compare/v0.0.1...v0.0.2)
|
|
144
|
+
|
|
145
|
+
## [v0.0.1](https://github.com/sensu/sensu-spawn/tree/v0.0.1) (2014-05-19)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2014 Heavy Water Operations, LLC.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Sensu::Spawn
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/sensu/sensu-spawn)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'sensu-spawn'
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Documentation can be found [here](http://rubydoc.info/github/sensu/sensu-spawn/Sensu/Spawn).
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
0. By contributing to this project you agree to abide by the [code of conduct](https://sensuapp.org/conduct).
|
|
24
|
+
1. [Fork it](https://github.com/sensu/sensu-spawn/fork)
|
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
28
|
+
5. Create a new Pull Request
|
data/lib/sensu/spawn.rb
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
gem "em-worker", "0.0.2"
|
|
2
|
+
gem "childprocess", "4.1.0"
|
|
3
|
+
gem "ffi", "1.16.3"
|
|
4
|
+
|
|
5
|
+
require "eventmachine"
|
|
6
|
+
require "em/worker"
|
|
7
|
+
require "childprocess"
|
|
8
|
+
require "rbconfig"
|
|
9
|
+
require "timeout"
|
|
10
|
+
|
|
11
|
+
# Attempt an upfront loading of FFI and POSIX spawn libraries. These
|
|
12
|
+
# libraries may fail to load on certain platforms, load errors are
|
|
13
|
+
# silenced, and the libraries are not used by Sensu Spawn.
|
|
14
|
+
begin
|
|
15
|
+
require "ffi"
|
|
16
|
+
require "childprocess/unix/platform/#{ChildProcess.platform_name}"
|
|
17
|
+
require "childprocess/unix/lib"
|
|
18
|
+
require "childprocess/unix/posix_spawn_process"
|
|
19
|
+
rescue LoadError; end
|
|
20
|
+
|
|
21
|
+
module Sensu
|
|
22
|
+
module Spawn
|
|
23
|
+
POSIX_SPAWN_PLATFORMS = [:linux, :macosx].freeze
|
|
24
|
+
POSIX_SPAWN_ARCHS = ["x86_64", "i386"].freeze
|
|
25
|
+
|
|
26
|
+
@@mutex = Mutex.new
|
|
27
|
+
|
|
28
|
+
class << self
|
|
29
|
+
# Setup a spawn process worker, to limit the number of
|
|
30
|
+
# concurrent child processes allowed at one time. This method
|
|
31
|
+
# creates the spawn process worker instance variable:
|
|
32
|
+
# `@process_worker`.
|
|
33
|
+
#
|
|
34
|
+
# @param [Hash] options to create a process worker with.
|
|
35
|
+
# @option options [Integer] :limit max number of child processes
|
|
36
|
+
# at a time.
|
|
37
|
+
def setup(options={})
|
|
38
|
+
limit = options[:limit] || 12
|
|
39
|
+
@process_worker ||= EM::Worker.new(:concurrency => limit)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Spawn a child process. The EventMachine reactor (loop) must be
|
|
43
|
+
# running for this method to work.
|
|
44
|
+
#
|
|
45
|
+
# @param [String] command to run.
|
|
46
|
+
# @param [Hash] options to create a child process with.
|
|
47
|
+
# @option options [String] :data to write to STDIN.
|
|
48
|
+
# @option options [Integer] :timeout in seconds.
|
|
49
|
+
# @param [Proc] callback called when the child process exits,
|
|
50
|
+
# its output and exit status are passed as parameters.
|
|
51
|
+
def process(command, options={}, &callback)
|
|
52
|
+
create = Proc.new do
|
|
53
|
+
child_process(command, options)
|
|
54
|
+
end
|
|
55
|
+
setup(options) unless @process_worker
|
|
56
|
+
@process_worker.enqueue(create, callback)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Determine if POSIX Spawn is used to create child processes on
|
|
60
|
+
# the current platform. ChildProcess supports POSIX Spawn for
|
|
61
|
+
# several platforms (OSs & architectures), however, Sensu only
|
|
62
|
+
# enables the use of POSIX Spawn on a select few.
|
|
63
|
+
#
|
|
64
|
+
# @return [TrueClass, FalseClass]
|
|
65
|
+
def posix_spawn?
|
|
66
|
+
return @posix_spawn unless @posix_spawn.nil?
|
|
67
|
+
platform_supported = POSIX_SPAWN_PLATFORMS.include?(ChildProcess.os)
|
|
68
|
+
arch_supported = POSIX_SPAWN_ARCHS.include?(ChildProcess.arch)
|
|
69
|
+
@posix_spawn = platform_supported && arch_supported
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Determine if the current platform is Windows.
|
|
73
|
+
#
|
|
74
|
+
# @return [TrueClass, FalseClass]
|
|
75
|
+
def on_windows?
|
|
76
|
+
return @on_windows unless @on_windows.nil?
|
|
77
|
+
@on_windows = ChildProcess.windows?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Build a child process attached to a pipe, in order to capture
|
|
81
|
+
# its output (STDERR, STDOUT). The child process will be a
|
|
82
|
+
# platform dependent shell, that is responsible for executing
|
|
83
|
+
# the provided command.
|
|
84
|
+
#
|
|
85
|
+
# @param [String] command to run.
|
|
86
|
+
# @return [Array] child object, pipe reader, pipe writer.
|
|
87
|
+
def build_child_process(command)
|
|
88
|
+
reader, writer = IO.pipe
|
|
89
|
+
shell = case
|
|
90
|
+
when on_windows?
|
|
91
|
+
["cmd", "/c"]
|
|
92
|
+
else
|
|
93
|
+
["sh", "-c"]
|
|
94
|
+
end
|
|
95
|
+
ChildProcess.posix_spawn = posix_spawn?
|
|
96
|
+
shell_command = shell + [command]
|
|
97
|
+
child = ChildProcess.build(*shell_command)
|
|
98
|
+
child.io.stdout = child.io.stderr = writer
|
|
99
|
+
child.leader = true
|
|
100
|
+
[child, reader, writer]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Write data to a stream/file and read a stream/file
|
|
104
|
+
# until end of file (EOF).
|
|
105
|
+
#
|
|
106
|
+
# @param writer [Object] to write data to (optional).
|
|
107
|
+
# @param reader [Object] to read contents of until EOF.
|
|
108
|
+
# @param data [String] to be written to writer.
|
|
109
|
+
# @return [String] the reader stream/file contents.
|
|
110
|
+
def write_and_read(writer, reader, data)
|
|
111
|
+
buffer = (data || "").dup
|
|
112
|
+
output = ""
|
|
113
|
+
loop do
|
|
114
|
+
unless buffer.empty?
|
|
115
|
+
writer.write(buffer.slice!(0, 8191))
|
|
116
|
+
writer.close if buffer.empty?
|
|
117
|
+
end
|
|
118
|
+
begin
|
|
119
|
+
readable, _ = IO.select([reader], nil, nil, 0)
|
|
120
|
+
if readable || buffer.empty?
|
|
121
|
+
output << reader.readpartial(8192)
|
|
122
|
+
end
|
|
123
|
+
rescue EOFError
|
|
124
|
+
reader.close
|
|
125
|
+
break
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
output
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Create a child process, return its output (STDERR & STDOUT),
|
|
132
|
+
# and exit status. The child process will have its own process
|
|
133
|
+
# group, may accept data via STDIN, and have a timeout.
|
|
134
|
+
# ChildProcess Unix POSIX spawn (`start()`) is not thread safe,
|
|
135
|
+
# so a mutex is used to allow safe execution on Ruby runtimes
|
|
136
|
+
# with real threads (JRuby).
|
|
137
|
+
#
|
|
138
|
+
# Using stdlib's Timeout instead of child.poll_for_exit to
|
|
139
|
+
# avoid a deadlock, when the child output is greater than
|
|
140
|
+
# the OS max buffer size.
|
|
141
|
+
#
|
|
142
|
+
# @param [String] command to run.
|
|
143
|
+
# @param [Hash] options to create a child process with.
|
|
144
|
+
# @option options [String] :data to write to STDIN.
|
|
145
|
+
# @option options [Integer] :timeout in seconds.
|
|
146
|
+
# @return [Array] child process output and exit status.
|
|
147
|
+
def child_process(command, options={})
|
|
148
|
+
child, reader, writer = build_child_process(command)
|
|
149
|
+
child.duplex = true if options[:data]
|
|
150
|
+
@@mutex.synchronize do
|
|
151
|
+
child.start
|
|
152
|
+
end
|
|
153
|
+
writer.close
|
|
154
|
+
output = ""
|
|
155
|
+
if options[:timeout]
|
|
156
|
+
Timeout::timeout(options[:timeout], ChildProcess::TimeoutError) do
|
|
157
|
+
output = write_and_read(child.io.stdin, reader, options[:data])
|
|
158
|
+
child.wait
|
|
159
|
+
end
|
|
160
|
+
else
|
|
161
|
+
output = write_and_read(child.io.stdin, reader, options[:data])
|
|
162
|
+
child.wait
|
|
163
|
+
end
|
|
164
|
+
[output, child.exit_code]
|
|
165
|
+
rescue ChildProcess::TimeoutError
|
|
166
|
+
output = "Execution timed out"
|
|
167
|
+
begin
|
|
168
|
+
child.stop
|
|
169
|
+
rescue => error
|
|
170
|
+
pid = child.pid rescue "?"
|
|
171
|
+
output += " - Unable to TERM/KILL the process: ##{pid}, #{error}"
|
|
172
|
+
end
|
|
173
|
+
[output, 2]
|
|
174
|
+
rescue => error
|
|
175
|
+
child.stop rescue nil
|
|
176
|
+
["Unexpected error: #{error}", 3]
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
data/sensu-spawn.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "portertech-sensu-spawn"
|
|
5
|
+
spec.version = "2.6.0"
|
|
6
|
+
spec.authors = ["Sean Porter"]
|
|
7
|
+
spec.email = ["portertech@gmail.com", "engineering@sensu.io"]
|
|
8
|
+
spec.summary = "The Sensu spawn process library"
|
|
9
|
+
spec.description = "The Sensu spawn process library"
|
|
10
|
+
spec.homepage = "https://github.com/sensu/sensu-spawn"
|
|
11
|
+
spec.license = "MIT"
|
|
12
|
+
|
|
13
|
+
spec.files = Dir.glob("lib/**/*") + %w[sensu-spawn.gemspec README.md CHANGELOG.md LICENSE.txt]
|
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
16
|
+
spec.require_paths = ["lib"]
|
|
17
|
+
|
|
18
|
+
spec.add_dependency "eventmachine"
|
|
19
|
+
spec.add_dependency "em-worker", "0.0.2"
|
|
20
|
+
spec.add_dependency "childprocess", "4.1.0"
|
|
21
|
+
spec.add_dependency "ffi", "1.16.3"
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.4"
|
|
24
|
+
spec.add_development_dependency "rake", "13.0.6"
|
|
25
|
+
spec.add_development_dependency "rspec"
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: portertech-sensu-spawn
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.6.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sean Porter
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-10-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: eventmachine
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: em-worker
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.0.2
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.0.2
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: childprocess
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 4.1.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 4.1.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: ffi
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.16.3
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.16.3
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: bundler
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '2.4'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '2.4'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 13.0.6
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - '='
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 13.0.6
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description: The Sensu spawn process library
|
|
112
|
+
email:
|
|
113
|
+
- portertech@gmail.com
|
|
114
|
+
- engineering@sensu.io
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- CHANGELOG.md
|
|
120
|
+
- LICENSE.txt
|
|
121
|
+
- README.md
|
|
122
|
+
- lib/sensu/spawn.rb
|
|
123
|
+
- sensu-spawn.gemspec
|
|
124
|
+
homepage: https://github.com/sensu/sensu-spawn
|
|
125
|
+
licenses:
|
|
126
|
+
- MIT
|
|
127
|
+
metadata: {}
|
|
128
|
+
post_install_message:
|
|
129
|
+
rdoc_options: []
|
|
130
|
+
require_paths:
|
|
131
|
+
- lib
|
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
requirements: []
|
|
143
|
+
rubygems_version: 3.4.10
|
|
144
|
+
signing_key:
|
|
145
|
+
specification_version: 4
|
|
146
|
+
summary: The Sensu spawn process library
|
|
147
|
+
test_files: []
|