process_mgt 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.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +21 -0
- data/Rakefile +21 -0
- data/lib/process_mgt.rb +85 -0
- data/test/test_process_mgt.rb +13 -0
- metadata +86 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= process_mgt
|
2
|
+
|
3
|
+
* http://cyberconnect.biz/opensource
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
High level calls for searching for process ids and killing processes given a string.
|
8
|
+
|
9
|
+
== REQUIREMENTS:
|
10
|
+
|
11
|
+
* /bin/ps
|
12
|
+
* Tested on GNU/Linux, but should work on other variants of Unix type OS's as well.
|
13
|
+
|
14
|
+
== INSTALL:
|
15
|
+
|
16
|
+
* sudo gem install process_mgt
|
17
|
+
|
18
|
+
== LICENSE:
|
19
|
+
|
20
|
+
GPLv3: http://www.gnu.org/licenses/gpl.html
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
# Hoe.plugin :compiler
|
7
|
+
# Hoe.plugin :gem_prelude_sucks
|
8
|
+
# Hoe.plugin :inline
|
9
|
+
# Hoe.plugin :racc
|
10
|
+
# Hoe.plugin :rubyforge
|
11
|
+
|
12
|
+
Hoe.spec 'process_mgt' do
|
13
|
+
# HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
|
14
|
+
# you'll never have to touch them again!
|
15
|
+
# (delete this comment too, of course)
|
16
|
+
|
17
|
+
developer('Cliff Cyphers', 'cliff.cyphers@gmail.com')
|
18
|
+
extra_deps << 'platform_helpers'
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=ruby
|
data/lib/process_mgt.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'platform_helpers'
|
9
|
+
|
10
|
+
module ProcessMgt
|
11
|
+
VERSION = '0.1.0'
|
12
|
+
def self.children(parent_pid)
|
13
|
+
pids=[]
|
14
|
+
out=`ps -ef --cols=400`
|
15
|
+
out.split(/\n/).grep(/#{parent_pid}/).each { |p|
|
16
|
+
tmp = p.split(' ')
|
17
|
+
pids << tmp[1] if p.split(' ')[2].strip == "#{parent_pid.strip}"
|
18
|
+
}
|
19
|
+
pids.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.parent_pid(child_pid)
|
23
|
+
out=`ps -ef --cols=400`
|
24
|
+
pid = ''
|
25
|
+
retry_ct = 0
|
26
|
+
out.each_line { |line|
|
27
|
+
line_split = line.split(' ')
|
28
|
+
return line_split[2].strip if line_split[1].strip == child_pid.strip
|
29
|
+
}
|
30
|
+
pid
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.pids(params={})
|
34
|
+
raise ArgumentError ":search not provided" unless params.has_key?(:search)
|
35
|
+
params[:exclude] ||= ''
|
36
|
+
out=`ps -ef --cols=400`
|
37
|
+
pids = ''
|
38
|
+
retry_ct = 0
|
39
|
+
out.grep(/#{params[:search]}/m).each { |i|
|
40
|
+
if params[:exclude] != ''
|
41
|
+
next if i.grep(/#{params[:exclude]}/).nitems > 0
|
42
|
+
end
|
43
|
+
item = " #{i.split(' ')[1].gsub(/\n/, '')}"
|
44
|
+
if params.has_key?(:parent)
|
45
|
+
parent = " #{i.split(' ')[2].gsub(/\n/, '')}"
|
46
|
+
pids += item if parent.strip == params[:parent].strip
|
47
|
+
else
|
48
|
+
pids += item
|
49
|
+
end
|
50
|
+
}
|
51
|
+
pids
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.pids_with_children(params={})
|
55
|
+
pids = ProcessMgt.pids(params)
|
56
|
+
all_pids = pids
|
57
|
+
pids.each { |pid|
|
58
|
+
all_pids += " #{ProcessMgt.children(pid)}"
|
59
|
+
}
|
60
|
+
all_pids
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.kill(params={})
|
64
|
+
params[:signal] ||= 'TERM'
|
65
|
+
params[:with_children] ||= 'false'
|
66
|
+
params[:force] ||= 'false'
|
67
|
+
if params.has_key?(:pid_list)
|
68
|
+
`kill -#{params[:signal]} #{params[:pid_list]} >/dev/null 2>&1`
|
69
|
+
else
|
70
|
+
if params[:with_children].to_bool
|
71
|
+
pids = pids_with_children(params)
|
72
|
+
else
|
73
|
+
if params.has_key?(:with_children)
|
74
|
+
pids = pids_with_children(params)
|
75
|
+
else
|
76
|
+
pids = pids(params)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
if pids.strip != ''
|
80
|
+
`kill -#{params[:signal]} #{pids} >/dev/null 2>&1`
|
81
|
+
`kill -9 #{pids} >/dev/null 2>&1` if params[:force].to_bool
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
require "process_mgt"
|
9
|
+
|
10
|
+
class TestProcessMgt < Test::Unit::TestCase
|
11
|
+
def test_sanity
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: process_mgt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cliff Cyphers
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: platform_helpers
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hoe
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "2.12"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description: High level calls for searching for process ids and killing processes given a string.
|
38
|
+
email:
|
39
|
+
- cliff.cyphers@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
files:
|
49
|
+
- .autotest
|
50
|
+
- History.txt
|
51
|
+
- Manifest.txt
|
52
|
+
- README.txt
|
53
|
+
- Rakefile
|
54
|
+
- lib/process_mgt.rb
|
55
|
+
- test/test_process_mgt.rb
|
56
|
+
- .gemtest
|
57
|
+
homepage: http://cyberconnect.biz/opensource
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --main
|
63
|
+
- README.txt
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: process_mgt
|
81
|
+
rubygems_version: 1.8.8
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: High level calls for searching for process ids and killing processes given a string.
|
85
|
+
test_files:
|
86
|
+
- test/test_process_mgt.rb
|