frontkick 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +21 -14
- data/lib/frontkick/command.rb +14 -5
- data/lib/frontkick/version.rb +1 -1
- data/spec/frontkick/command_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c67ae20a2f6e7807c0f88329dd758548c5ff3f
|
4
|
+
data.tar.gz: 5da56ec31b5550c6cd723f839cf11264844119aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863d2b04e91a27960ab5fd91c45c54876b71de1852447101f1bd720ea2b47cb6f957be16313088b87483506b788b3a9dc44678e6ad7c429a1685622fe3443d1c
|
7
|
+
data.tar.gz: 3ea6eb45338bdf1f42632a098fe32a5e0b1bdfb5859ef49e371c41368b4a8de139832a61128e66949ebb1c4a0e0cffe53c3c3ca167f913239dac06eee70730e1
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -70,16 +70,16 @@ ruby
|
|
70
70
|
└─ echo
|
71
71
|
```
|
72
72
|
|
73
|
-
NOTE: This interface is
|
73
|
+
NOTE: This **no shell** interface is similar to IO.popen which work as:
|
74
74
|
|
75
75
|
```
|
76
|
-
|
76
|
+
IO.popen(['echo', '*'])
|
77
77
|
```
|
78
78
|
|
79
|
-
|
79
|
+
but different with Kernel.spawn, or Open3.popen3 which work as:
|
80
80
|
|
81
81
|
```
|
82
|
-
|
82
|
+
spawn('echo', '*')
|
83
83
|
```
|
84
84
|
|
85
85
|
### Environment Variables
|
@@ -93,20 +93,27 @@ result = Frontkick.exec({"FOO"=>"BAR"}, ["echo", "*"])
|
|
93
93
|
### Dry Run Option
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
result = Frontkick.exec(["echo", "*"], :
|
96
|
+
result = Frontkick.exec(["echo", "*"], dry_run: true)
|
97
97
|
puts result.stdout #=> echo \*
|
98
98
|
```
|
99
99
|
|
100
100
|
### Timeout Option
|
101
101
|
|
102
102
|
```ruby
|
103
|
-
Frontkick.exec("sleep 2 && ls /hoge", :
|
103
|
+
Frontkick.exec("sleep 2 && ls /hoge", timeout: 1) # raises Frontkick::Timeout
|
104
|
+
```
|
105
|
+
|
106
|
+
The default signal that is sent to the command is `SIGINT`.
|
107
|
+
You can change the signal as below.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Frontkick.exec("sleep 2 && ls /hoge", timeout: 1, timeout_kill_signal: 'SIGTERM') # raises Frontkick::Timeout
|
104
111
|
```
|
105
112
|
|
106
113
|
not to kill timeouted process
|
107
114
|
|
108
115
|
```ruby
|
109
|
-
Frontkick.exec("sleep 2 && ls /hoge", :
|
116
|
+
Frontkick.exec("sleep 2 && ls /hoge", timeout: 1, timeout_kill: false) # raises Frontkick::Timeout
|
110
117
|
```
|
111
118
|
|
112
119
|
### Exclusive Option
|
@@ -114,19 +121,19 @@ Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1, :timeout_kill => false) # r
|
|
114
121
|
Prohibit another process to run a command concurrently
|
115
122
|
|
116
123
|
```ruby
|
117
|
-
Frontkick.exec("sleep 2 && ls /hoge", :
|
124
|
+
Frontkick.exec("sleep 2 && ls /hoge", exclusive: "/tmp/frontkick.lock") # raises Fontkick::Locked if locked
|
118
125
|
```
|
119
126
|
|
120
127
|
If you prefer to be blocked:
|
121
128
|
|
122
129
|
```ruby
|
123
|
-
Frontkick.exec("sleep 2 && ls /hoge", :
|
130
|
+
Frontkick.exec("sleep 2 && ls /hoge", exclusive: "/tmp/frontkick.lock", exclusive_blocking: true)
|
124
131
|
```
|
125
132
|
|
126
133
|
### Redirect Options (:out and :err)
|
127
134
|
|
128
135
|
```ruby
|
129
|
-
Frontkick.exec(["ls /something_not_found"], :
|
136
|
+
Frontkick.exec(["ls /something_not_found"], out: 'stdout.txt', err: 'stderr.txt')
|
130
137
|
```
|
131
138
|
|
132
139
|
This redirects STDOUT and STDERR into files. In this case, result.stdout, and result.stderr are the given filename.
|
@@ -134,7 +141,7 @@ This redirects STDOUT and STDERR into files. In this case, result.stdout, and re
|
|
134
141
|
```ruby
|
135
142
|
out = File.open('stdout.txt', 'w').tap {|fp| fp.sync = true }
|
136
143
|
err = File.open('stderr.txt', 'w').tap {|fp| fp.sync = true }
|
137
|
-
Frontkick.exec(["ls /something_not_found"], :
|
144
|
+
Frontkick.exec(["ls /something_not_found"], out: out, err: err)
|
138
145
|
```
|
139
146
|
|
140
147
|
You can also give IO objects. In this case, result.stdout, and result.stderr are the given IO objects.
|
@@ -142,15 +149,15 @@ You can also give IO objects. In this case, result.stdout, and result.stderr are
|
|
142
149
|
### Popen2e Option (Get stdout and stderr together)
|
143
150
|
|
144
151
|
```ruby
|
145
|
-
result = Frontkick.exec("echo foo; ls /something_not_found", :
|
152
|
+
result = Frontkick.exec("echo foo; ls /something_not_found", popen2e: true)
|
146
153
|
puts result.output #=>
|
147
154
|
foo
|
148
155
|
ls: /something_not_found: No such file or directory
|
149
156
|
```
|
150
157
|
|
151
|
-
### Popen3 Options (such as :chdir)
|
158
|
+
### Other Popen3 Options (such as :chdir)
|
152
159
|
|
153
|
-
Other options such as :chdir are treated as options of `Open3.#popen3
|
160
|
+
Other options such as :chdir are treated as options of `Open3.#popen3` (or `Open3.#popen2e` for the case of `popen2e: true`)
|
154
161
|
|
155
162
|
### Kill Child Process
|
156
163
|
|
data/lib/frontkick/command.rb
CHANGED
@@ -17,6 +17,7 @@ module Frontkick
|
|
17
17
|
cmd_array = cmd.is_a?(Array) ? cmd : [cmd]
|
18
18
|
|
19
19
|
opts[:timeout_kill] = true unless opts.has_key?(:timeout_kill) # default: true
|
20
|
+
opts[:timeout_kill_signal] = 'SIGINT' unless opts.has_key?(:timeout_kill_signal) # default: 'SIGINT'
|
20
21
|
|
21
22
|
exit_code, duration = nil
|
22
23
|
stdin, stdout, stderr, wait_thr, pid = nil
|
@@ -44,9 +45,8 @@ module Frontkick
|
|
44
45
|
end
|
45
46
|
|
46
47
|
if opts[:dry_run]
|
47
|
-
|
48
|
-
stdout
|
49
|
-
return Result.new(:stdout => stdout, :stderr => '', :exit_code => 0, :duration => 0)
|
48
|
+
command = build_command(env, cmd_array)
|
49
|
+
return Result.new(:stdout => command, :stderr => '', :exit_code => 0, :duration => 0)
|
50
50
|
end
|
51
51
|
|
52
52
|
popen3_opts = self.popen3_opts(opts)
|
@@ -105,11 +105,12 @@ module Frontkick
|
|
105
105
|
end
|
106
106
|
rescue Frontkick::TimeoutLocal => e
|
107
107
|
if opts[:timeout_kill]
|
108
|
-
Process.kill(
|
108
|
+
Process.kill(opts[:timeout_kill_signal], pid)
|
109
109
|
exit_code = wait_thr.value.exitstatus
|
110
110
|
process_wait(pid)
|
111
111
|
end
|
112
|
-
|
112
|
+
command = build_command(env, cmd_array)
|
113
|
+
raise Frontkick::Timeout.new(pid, command, opts[:timeout_kill])
|
113
114
|
ensure
|
114
115
|
stdin.close if stdin and !stdin.closed?
|
115
116
|
stdout.close if stdout and !stdout.closed?
|
@@ -133,9 +134,17 @@ module Frontkick
|
|
133
134
|
|
134
135
|
# private
|
135
136
|
|
137
|
+
def self.build_command(env, cmd_array)
|
138
|
+
command = env.map {|k,v| "#{k}=#{v} " }.join('')
|
139
|
+
command << cmd_array.first
|
140
|
+
command << " #{cmd_array[1..-1].shelljoin}" if cmd_array.size > 1
|
141
|
+
command
|
142
|
+
end
|
143
|
+
|
136
144
|
def self.popen3_opts(opts)
|
137
145
|
opts.dup.tap {|o|
|
138
146
|
o.delete(:timeout_kill)
|
147
|
+
o.delete(:timeout_kill_signal)
|
139
148
|
o.delete(:exclusive)
|
140
149
|
o.delete(:exclusive_blocking)
|
141
150
|
o.delete(:timeout)
|
data/lib/frontkick/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe Frontkick::Command do
|
4
4
|
describe '.exec' do
|
5
5
|
describe 'timeout option' do
|
6
|
-
subject { described_class.exec('sleep 2 && ls /hoge', timeout:
|
6
|
+
subject { described_class.exec('sleep 2 && ls /hoge', timeout: 0.01) }
|
7
7
|
it { expect { subject }.to raise_error Frontkick::Timeout }
|
8
8
|
end
|
9
9
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frontkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.6.13
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Execute a command simply!
|