multi_timeout 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/MIT-LICENSE +20 -0
- data/bin/multi-timeout +5 -0
- data/lib/multi_timeout.rb +100 -0
- data/lib/multi_timeout/version.rb +3 -0
- metadata +70 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48d71cc32b686a996440a80637e22c1da0f1f093
|
4
|
+
data.tar.gz: dcc94b0b6ba333df8602be27df16846b9ae532fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ac3d8c8059beeddc9fd5f23d1bf797ba7786cf046c152a64a7b6e97785b0779e3e021c6352d1bc13b3d9d3de15742650a7440922794b862a508f5995fb24251
|
7
|
+
data.tar.gz: 2320339aedcf32b69cb3adf493c78a948bab3ada944f0fc88da9d1a912aed159cc626081d5f708c6f981f5b07faff7e13e55773762564bad7d8dce675f6494fe
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
Binary file
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
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/bin/multi-timeout
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "multi_timeout/version"
|
2
|
+
require "shellwords"
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module MultiTimeout
|
6
|
+
module CLI
|
7
|
+
TICK = 1
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def run(argv)
|
11
|
+
options = parse_options(argv)
|
12
|
+
command = options[:command]
|
13
|
+
|
14
|
+
pid = Process.spawn(command)
|
15
|
+
Thread.new do
|
16
|
+
now = 0
|
17
|
+
loop do
|
18
|
+
break if dead?(pid)
|
19
|
+
|
20
|
+
options[:timeouts].each do |signal, t|
|
21
|
+
if now >= t
|
22
|
+
puts "Killing #{command} with signal #{signal} after #{now} seconds"
|
23
|
+
Process.kill(signal, pid)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
now += TICK
|
27
|
+
sleep TICK
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Process.wait2.last.exitstatus || 1
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def dead?(pid)
|
37
|
+
Process.getpgid(pid)
|
38
|
+
false
|
39
|
+
rescue Errno::ESRCH
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_options(argv)
|
44
|
+
options = {:timeouts => []}
|
45
|
+
options[:timeouts], argv = consume_signals(argv)
|
46
|
+
|
47
|
+
|
48
|
+
OptionParser.new do |opts|
|
49
|
+
opts.banner = <<-BANNER.gsub(/^ {10}/, "")
|
50
|
+
Use multiple timeouts to soft and then hard kill a command
|
51
|
+
|
52
|
+
Usage:
|
53
|
+
multi-timeout -9 5s -2 4s sleep 20
|
54
|
+
|
55
|
+
Options:
|
56
|
+
BANNER
|
57
|
+
opts.on("-SIGNAL TIME", Integer, "Kill with this SIGNAL after TIME") { raise } # this is never used, just placeholder for docs
|
58
|
+
opts.on("-h", "--help", "Show this.") { puts opts; exit }
|
59
|
+
opts.on("-v", "--version", "Show Version"){ puts MultiTimeout::VERSION; exit}
|
60
|
+
end.parse!(argv)
|
61
|
+
|
62
|
+
raise "No timeouts given" if options[:timeouts].empty?
|
63
|
+
options[:command] = Shellwords.shelljoin(argv)
|
64
|
+
|
65
|
+
options
|
66
|
+
end
|
67
|
+
|
68
|
+
def consume_signals(argv)
|
69
|
+
timeouts = []
|
70
|
+
signal = nil
|
71
|
+
argv = argv.map do |item|
|
72
|
+
if !signal && item =~ /^(-\d+)$/
|
73
|
+
signal = $1
|
74
|
+
next
|
75
|
+
elsif signal && item =~ /^(\d+[smh]?)$/
|
76
|
+
time = $1
|
77
|
+
timeouts << [signal.sub("-", "").to_i, time.to_i * multi(time)]
|
78
|
+
signal = nil
|
79
|
+
next
|
80
|
+
else
|
81
|
+
item
|
82
|
+
end
|
83
|
+
end.compact
|
84
|
+
|
85
|
+
return timeouts, argv
|
86
|
+
end
|
87
|
+
|
88
|
+
def multi(t)
|
89
|
+
case t
|
90
|
+
when /s/ then 1
|
91
|
+
when /m/ then 60
|
92
|
+
when /h/ then 60 * 60
|
93
|
+
when /^\d+$/ then 1
|
94
|
+
else
|
95
|
+
raise "Unknown format for time #{t}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multi_timeout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
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YJKoZIhvcNAQEFBQAD
|
26
|
+
ggEBAExBcUWfGuamYn+IddOA0Ws8jUKwB14RXoZRDrTiTAlMm3Bkg2OKyxS3uJXa
|
27
|
+
6Z+LwFiZwVYk62yHXqNzEJycQk4SEmY+xDWLj0p7X6qEeU4QZKwR1TwJ5z3PTrZ6
|
28
|
+
irJgM3q7NIBRvmTzRaAghWcQn+Eyr5YLOfMksjVBMUMnzh5/ZDgq53LphgJbGwvz
|
29
|
+
ScJAgfNclLHnjk9q1mT1s0e1FPWbiAL3siBIR5HpH8qtSEiivTf2ntciebOqS93f
|
30
|
+
F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
|
31
|
+
/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
34
|
+
dependencies: []
|
35
|
+
description:
|
36
|
+
email: michael@grosser.it
|
37
|
+
executables:
|
38
|
+
- multi-timeout
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- MIT-LICENSE
|
43
|
+
- bin/multi-timeout
|
44
|
+
- lib/multi_timeout.rb
|
45
|
+
- lib/multi_timeout/version.rb
|
46
|
+
homepage: https://github.com/grosser/multi_timeout
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.0.14
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Use multiple timeouts to soft and then hard kill a command
|
70
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|