atduskgreg-dog_catcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-12-30
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/dog_catcher.rb
6
+ bin/dog_catcher
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = dog_catcher
2
+
3
+ http://github.com/atduskgreg/dog_catcher
4
+
5
+ == DESCRIPTION:
6
+
7
+ Do you run many Rails apps from many different directories? Do you get annoyed when you try to start a new one and an existing app is already occupying your port of choice? Are you sick of killing these Rails apps with 'kill -9' (after having to scare up their PID) and then having to clean up the stranded .pid files later?
8
+
9
+ If you answered 'yes' to any of these questions, you need the dog_catcher. The dog_catcher provides an interactive utility for politely shutting down mongrels from anywhere on your machine.
10
+
11
+ == FEATURES:
12
+
13
+ * Sends a TERM signal to one or all of your running mongrels.
14
+
15
+ * Displays them to you via port.
16
+
17
+ * Has a "catchy" name.
18
+
19
+ == SYNOPSIS:
20
+
21
+ Witness, an example dog_catcher session:
22
+
23
+ $ dog_catcher
24
+ Weclome to the Dog Catcher.
25
+ You currently have 3 running mongrels.
26
+ 1. Port: 3000
27
+ 2. Port: 3333
28
+ 3. Port: 9999
29
+ Enter a number to cleanly shut down that mongrel (or hit return for all):
30
+ 2
31
+ Sending 'TERM' to mongrel running on 27993
32
+
33
+ == INSTALL:
34
+
35
+ sudo gem install atduskgreg-dog_catcher
36
+
37
+ == LICENSE:
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2008 Greg Borenstein
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/dog_catcher'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('dog_catcher', DogCatcher::VERSION) do |p|
7
+ p.developer('Greg Borenstein', 'greg@mfdz.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+ # p.extra_deps = [
11
+ # ['activesupport','>= 2.0.2'],
12
+ # ]
13
+ p.extra_dev_deps = [
14
+ ['newgem', ">= #{::Newgem::VERSION}"]
15
+ ]
16
+
17
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
18
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
19
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
20
+ p.rsync_args = '-av --delete --ignore-errors'
21
+ end
22
+
23
+ require 'newgem/tasks' # load /tasks/*.rake
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # task :default => [:spec, :features]
data/bin/dog_catcher ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'dog_catcher'
5
+
6
+ d = DogCatcher.new
7
+
8
+ puts "Weclome to the Dog Catcher."
9
+ puts "You currently have #{d.running_mongrels.length} running mongrels."
10
+
11
+ if d.running_mongrels.length > 0
12
+
13
+ d.running_mongrels.each_with_index do |m,i|
14
+ puts "#{i+1}. Port: #{DogCatcher.guess_port(m)}"
15
+ end
16
+ puts "Enter a number to cleanly shut down that mongrel (or hit return for all): "
17
+ choice = STDIN.gets.chomp
18
+
19
+ case choice.to_i
20
+ when 0
21
+ d.stop_all_mongrels!
22
+ else
23
+ DogCatcher.stop_mongrel! d.running_mongrels[choice.to_i - 1]
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "dog_catcher"
3
+ s.version = "0.1.0"
4
+ s.date = "2008-12-30"
5
+ s.summary = "Find and cleanly shut down any and all mongrels running on your system."
6
+ s.email = "greg@mfdz.com"
7
+ s.homepage = "http://github.com/atduskgreg/dog_catcher"
8
+ s.description = "Find and cleanly shut down any and all mongrels running on your system."
9
+ s.has_rdoc = true
10
+ s.authors = ["Greg Borenstein"]
11
+ s.files = ["History.txt",
12
+ "README.rdoc",
13
+ "Maifest.txt",
14
+ "bin/dog_catcher",
15
+ "lib/dog_catcher.rb",
16
+ "Rakefile",
17
+ "dog_catcher.gemspec"]
18
+ s.rdoc_options = ["--main", "README.rdoc"]
19
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
20
+ end
@@ -0,0 +1,42 @@
1
+ class DogCatcher
2
+ VERSION = "0.1"
3
+
4
+ attr_accessor :lines
5
+
6
+ def initialize
7
+ @psx = `ps x`
8
+ @lines = @psx.split(/\n/).collect{|l| DogCatcher.parse_line(l) }
9
+ end
10
+
11
+ def self.parse_line( string )
12
+ arr = string.split(' ')
13
+ { :pid => arr[0].to_i,
14
+ :prog => arr[4],
15
+ :args => arr[5..arr.length-1].join(" ")
16
+ }
17
+ end
18
+
19
+ def self.stop_mongrel!( m )
20
+ puts "Sending 'TERM' to mongrel running on #{m[:pid]}"
21
+ Process.kill("TERM", m[:pid])
22
+ end
23
+
24
+ def running_rubies
25
+ self.lines.select{|l| l[:prog] == "ruby" }
26
+ end
27
+
28
+ def running_mongrels
29
+ self.lines.select{|l| l[:args] =~ /mong/}
30
+ end
31
+
32
+ def self.guess_port( m )
33
+ port_arg = m[:args].scan(/(-p\s\d*)/).first
34
+ port_arg ? port_arg.first.split(" ").last : "3000"
35
+ end
36
+
37
+ def stop_all_mongrels!
38
+ self.running_mongrels.each{|m| DogCatcher.stop_mongrel! m }
39
+ end
40
+
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atduskgreg-dog_catcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Borenstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-30 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Find and cleanly shut down any and all mongrels running on your system.
17
+ email: greg@mfdz.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - Manifest.txt
25
+ - README.rdoc
26
+ files:
27
+ - History.txt
28
+ - README.rdoc
29
+ - Maifest.txt
30
+ - bin/dog_catcher
31
+ - lib/dog_catcher.rb
32
+ - Rakefile
33
+ - dog_catcher.gemspec
34
+ - Manifest.txt
35
+ has_rdoc: true
36
+ homepage: http://github.com/atduskgreg/dog_catcher
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --main
40
+ - README.rdoc
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Find and cleanly shut down any and all mongrels running on your system.
62
+ test_files: []
63
+