terminate 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c1c618cd6d5141bafcc34046a8b819b8733086f
4
- data.tar.gz: 828a04e167c9ce6e32862c194fd9b141732f239f
3
+ metadata.gz: 7fe02caeda6ad45c1110c7d2786aef2503ba5a06
4
+ data.tar.gz: ffa08e566c228ce43a89668e2d90256880b41e95
5
5
  SHA512:
6
- metadata.gz: 2754dab1766a9d24f71e7dd7dac1029cfe97015a3283e81cdf855316a6ac9487cb0e2a9ef5f4f0ef964387b3648c76c786eea7db07d8b7ead59b9f1766540876
7
- data.tar.gz: f831b8d1051ec01cc336673e2f1c8c5f84b31ce6f451bb7ab43c9d5774aff0a47e54a9c07d79f20d50cbd3ff37d5ad48ae73592f85f4f70b59598f2e41597556
6
+ metadata.gz: df3bc5122cfcc0f2532271dfaa02b986dbe979a8272a1e0c1286312d0523e3b5108e42ceacb2a6fcd7d27bc86cd7f59022cc79b25b8f36d35cee6ee827257a8d
7
+ data.tar.gz: 189c41a2f443ee4aa9643c99ca2160ca5a693f237a73c89c5e1231b1235ca3e53b0822c3925e06d6a8fba25bcad92a1e006727a0269625b7efd3f952ff290f72
@@ -1,3 +1,7 @@
1
+ # v0.1.1 / 2015-11-02
2
+
3
+ Support Rake
4
+
1
5
  # v0.1.0 / 2015-11-02
2
6
 
3
7
  Create project
data/README.md CHANGED
@@ -32,6 +32,21 @@ Terminate.execute(pid, 30)
32
32
  Terminate.execute(pid, 30, 'USR1')
33
33
  ```
34
34
 
35
+ ### Rake
36
+ You can alos run by `rake`:
37
+
38
+ bundle exec terminate [pid] -- [options]
39
+
40
+ Eg.
41
+
42
+ # default timeout is 10 seconds
43
+ bundle exec terminate 1234
44
+
45
+ # set timeout 30
46
+ bundle exec terminate 1234 -- -t 30
47
+ # or
48
+ bundle exec terminate 1234 -- --timeout=30
49
+
35
50
  ### Command Line
36
51
  You can alos run by `terminate` in command line.
37
52
 
@@ -4,27 +4,15 @@ require 'optparse'
4
4
  require 'logger'
5
5
  require 'terminate'
6
6
 
7
- help = ''
8
- options = {}
9
- OptionParser.new do |opts|
10
- opts.banner = "Usage: wait_stop [pid] [options]"
11
- opts.on('-t', '--timeout=TIMEOUT', 'Timeout to kill(seconds, default is 10)') { |v| options[:timeout] = v }
12
- opts.on('-s', '--signal=SIGNAL', 'SIGNAL to terminate(default TERM)') { |v| options[:signal] = v }
13
- help = opts.to_s
14
- end.parse!
7
+ options = Terminate::Options.new
15
8
 
16
- pid = ARGV[0].to_i
17
- if pid <= 0
18
- puts help
9
+ if options.pid <= 0
10
+ puts options.help
19
11
  exit
20
12
  end
21
13
 
22
- timeout = options[:timeout].to_i
23
- timeout = 10 if timeout <= 0
24
- signal = options[:signal] || 'TERM'
25
-
26
14
  Terminate.logger = Logger.new(STDOUT)
27
15
  Terminate.logger.formatter = proc do |severity, datetime, progname, msg|
28
16
  "#{msg}\n"
29
17
  end
30
- Terminate.execute(pid, timeout, signal)
18
+ Terminate.execute(options.pid, options.timeout, options.signal)
@@ -0,0 +1,9 @@
1
+ desc "Terminate Process"
2
+ task :terminate do
3
+ ARGV.shift
4
+ options = Terminate::Options.new
5
+ cmd = "terminate #{ARGV.join(' ')}"
6
+ puts "Command: #{cmd}"
7
+ puts `#{cmd}`
8
+ ARGV.each { |a| task a.to_sym do ; end }
9
+ end
@@ -1,4 +1,6 @@
1
1
  require 'timeout'
2
+ require 'terminate/options'
3
+ require 'terminate/railtie'
2
4
 
3
5
  module Terminate
4
6
  def self.logger=(logger)
@@ -0,0 +1,29 @@
1
+ module Terminate
2
+ class Options
3
+ attr_reader :help
4
+
5
+ def initialize
6
+ @help = ''
7
+ @options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: wait_stop [pid] [options]"
10
+ opts.on('-t', '--timeout=TIMEOUT', 'Timeout to kill(seconds, default is 10)') { |v| @options[:timeout] = v }
11
+ opts.on('-s', '--signal=SIGNAL', 'SIGNAL to terminate(default TERM)') { |v| @options[:signal] = v }
12
+ @help = opts.to_s
13
+ end.parse!
14
+ end
15
+
16
+ def pid
17
+ ARGV[0].to_i
18
+ end
19
+
20
+ def timeout
21
+ timeout = @options[:timeout].to_i
22
+ timeout <= 0 ? 10 : timeout
23
+ end
24
+
25
+ def signal
26
+ @options[:signal] || 'TERM'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ if defined? ::Rails
2
+ module Terminate
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load "tasks/terminate.rake"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Terminate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chen Yi-Cyuan
@@ -111,7 +111,10 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - bin/terminate
114
+ - lib/tasks/terminate.rake
114
115
  - lib/terminate.rb
116
+ - lib/terminate/options.rb
117
+ - lib/terminate/railtie.rb
115
118
  - lib/terminate/version.rb
116
119
  - terminate.gemspec
117
120
  homepage: https://github.com/emn178/terminate
@@ -134,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
137
  version: '0'
135
138
  requirements: []
136
139
  rubyforge_project:
137
- rubygems_version: 2.4.8
140
+ rubygems_version: 2.4.5
138
141
  signing_key:
139
142
  specification_version: 4
140
143
  summary: Terminate process or kill if timeout.