terminate 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c1c618cd6d5141bafcc34046a8b819b8733086f
4
+ data.tar.gz: 828a04e167c9ce6e32862c194fd9b141732f239f
5
+ SHA512:
6
+ metadata.gz: 2754dab1766a9d24f71e7dd7dac1029cfe97015a3283e81cdf855316a6ac9487cb0e2a9ef5f4f0ef964387b3648c76c786eea7db07d8b7ead59b9f1766540876
7
+ data.tar.gz: f831b8d1051ec01cc336673e2f1c8c5f84b31ce6f451bb7ab43c9d5774aff0a47e54a9c07d79f20d50cbd3ff37d5ad48ae73592f85f4f70b59598f2e41597556
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
5
+ branches:
6
+ only:
7
+ - master
8
+ env:
9
+ - COVERALLS=1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0 / 2015-11-02
2
+
3
+ Create project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in terminate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chen Yi-Cyuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # terminate
2
+
3
+ [![Build Status](https://api.travis-ci.org/emn178/terminate.png)](https://travis-ci.org/emn178/terminate)
4
+ [![Coverage Status](https://coveralls.io/repos/emn178/terminate/badge.svg?branch=master)](https://coveralls.io/r/emn178/terminate?branch=master)
5
+
6
+ Terminate process or kill if timeout.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'terminate'
13
+
14
+ And then execute:
15
+
16
+ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ gem install terminate
21
+
22
+ ## Usage
23
+ You can call `Terminate.execute` in your ruby program.
24
+ ```Ruby
25
+ # process to terminate
26
+ Terminate.execute(pid)
27
+
28
+ # specify timeout, default 10
29
+ Terminate.execute(pid, 30)
30
+
31
+ # specify SIGNAL, default 'TERM'
32
+ Terminate.execute(pid, 30, 'USR1')
33
+ ```
34
+
35
+ ### Command Line
36
+ You can alos run by `terminate` in command line.
37
+
38
+ terminate [pid] [options]
39
+
40
+ Eg.
41
+
42
+ # default timeout is 10 seconds
43
+ terminate 1234
44
+
45
+ # set timeout 30
46
+ terminate 1234 -t 30
47
+ # or
48
+ terminate 1234 --timeout=30
49
+
50
+ ## License
51
+ The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).
52
+
53
+ ## Contact
54
+ The project's website is located at https://github.com/emn178/terminate
55
+ Author: emn178@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/terminate ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'logger'
5
+ require 'terminate'
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!
15
+
16
+ pid = ARGV[0].to_i
17
+ if pid <= 0
18
+ puts help
19
+ exit
20
+ end
21
+
22
+ timeout = options[:timeout].to_i
23
+ timeout = 10 if timeout <= 0
24
+ signal = options[:signal] || 'TERM'
25
+
26
+ Terminate.logger = Logger.new(STDOUT)
27
+ Terminate.logger.formatter = proc do |severity, datetime, progname, msg|
28
+ "#{msg}\n"
29
+ end
30
+ Terminate.execute(pid, timeout, signal)
@@ -0,0 +1,3 @@
1
+ module Terminate
2
+ VERSION = "0.1.0"
3
+ end
data/lib/terminate.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'timeout'
2
+
3
+ module Terminate
4
+ def self.logger=(logger)
5
+ @@logger = logger
6
+ end
7
+
8
+ def self.logger
9
+ @@logger
10
+ end
11
+
12
+ def self.pid_exist?(pid)
13
+ begin
14
+ Process.getpgid( pid )
15
+ true
16
+ rescue Errno::ESRCH
17
+ false
18
+ end
19
+ end
20
+
21
+ def self.execute(pid, timeout = 10, signal = 'TERM')
22
+ if pid_exist?(pid)
23
+ Process.kill(signal, pid)
24
+ info "Send SIGNAL #{signal} to process #{pid}."
25
+ begin
26
+ Timeout.timeout(timeout) do
27
+ while pid_exist?(pid)
28
+ sleep 0.1
29
+ end
30
+ info "Process #{pid} is done."
31
+ end
32
+ rescue Timeout::Error
33
+ Process.kill('KILL', pid)
34
+ info "Timeout, send SIGNAL KILL to process #{pid}."
35
+ end
36
+ else
37
+ info "Process #{pid} is not found."
38
+ end
39
+ end
40
+
41
+ def self.info(*args)
42
+ logger.info(*args) unless logger.nil?
43
+ end
44
+ end
data/terminate.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'terminate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "terminate"
8
+ spec.version = Terminate::VERSION
9
+ spec.authors = ["Chen Yi-Cyuan"]
10
+ spec.email = ["emn178@gmail.com"]
11
+
12
+ spec.summary = %q{Terminate process or kill if timeout.}
13
+ spec.description = %q{Terminate process or kill if timeout.}
14
+ spec.homepage = "https://github.com/emn178/terminate"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+ spec.executables = ["terminate"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rspec-its"
25
+ spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "coveralls"
27
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terminate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Terminate process or kill if timeout.
98
+ email:
99
+ - emn178@gmail.com
100
+ executables:
101
+ - terminate
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/terminate
114
+ - lib/terminate.rb
115
+ - lib/terminate/version.rb
116
+ - terminate.gemspec
117
+ homepage: https://github.com/emn178/terminate
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.8
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Terminate process or kill if timeout.
141
+ test_files: []