powr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +29 -0
  5. data/Rakefile +37 -0
  6. data/VERSION +1 -0
  7. data/bin/powr +89 -0
  8. data/lib/powr.rb +2 -0
  9. data/powr.gemspec +52 -0
  10. metadata +82 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 804f30cd7943139bd358ec972e3c6c5028c6ebf1
4
+ data.tar.gz: b14865c61d0180871492f69360f358f500906c97
5
+ SHA512:
6
+ metadata.gz: a6ed4976ab1c19977b84bd9abaf03b898546a8ad78162ead667663efac749513c65841bf660276c7a9d8534b6f9587a4b9822809b3d57edc86a071b3fb137164
7
+ data.tar.gz: a1e1aeef9d949195a70e7d80b936283b8e8df19b2a48015863130ce6b1c9801705edf4cc3a3a0328dd9df53e4148f539f91cc4e700ca396df5274185b1ff0647
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ group :development do
4
+ gem 'bundler', '~> 1.0'
5
+ gem 'jeweler', '~> 2.0'
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Scott Tadman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # powr
2
+
3
+ Simple Pow process manager.
4
+
5
+ ## Usage
6
+
7
+ To stamp out a `tmp/restart.txt` file that will cause the Ruby Rack processes
8
+ to restart on the next load:
9
+
10
+ powr
11
+
12
+ To show all Ruby Rack processes for the current application that are running:
13
+
14
+ powr -s
15
+
16
+ To kill off all Ruby Rack processes for the current application:
17
+
18
+ powr -k
19
+
20
+ ## Notes
21
+
22
+ The location of the Rails root is determined based on the presence of a
23
+ `config/database.yml` file.
24
+
25
+ ## Copyright
26
+
27
+ Copyright (c) 2014 Scott Tadman. See LICENSE.txt for
28
+ further details.
29
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
19
+ gem.name = "powr"
20
+ gem.homepage = "http://github.com/twg/powr"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Pow Ruby Rack Process Manager Tool}
23
+ gem.description = %Q{Simple Rack process management}
24
+ gem.email = "scott@twg.ca"
25
+ gem.authors = [ "Scott Tadman" ]
26
+ # dependencies defined in Gemfile
27
+ end
28
+
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/powr ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # == Dependencies ===========================================================
4
+
5
+ require 'optparse'
6
+ require 'open3'
7
+
8
+ # == Constants ==============================================================
9
+
10
+ PATH_LENGTH_MAX = 255
11
+ ROOT_TRIGGER = 'config.ru'.freeze
12
+ RESTART_PATH = 'tmp/restart.txt'.freeze
13
+
14
+ # == Support Methods ========================================================
15
+
16
+ def rails_processes(path)
17
+ ps, status = Open3.capture2("ps", "aux")
18
+ path_rx = Regexp.new(Regexp.escape(path))
19
+
20
+ return [ ] unless (ps)
21
+
22
+ ps.split(/\n/).collect do |line|
23
+ parts = line.split(/\s+/)
24
+
25
+ # Ignore header. Should work with default OS X and Linux `ps` tool.
26
+ next if (parts[0] == 'USER')
27
+
28
+ [ parts[1].to_i, parts[10, parts.length] ]
29
+ end.select do |process|
30
+ process and process[1].grep(path_rx).any?
31
+ end
32
+ end
33
+
34
+ def rails_root
35
+ return @rails_root unless (@rails_root.nil?)
36
+
37
+ @rails_root = false
38
+ path = Dir.pwd
39
+
40
+ while (File.exists?(path) and (path.length < PATH_LENGTH_MAX) and !@rails_root)
41
+ if (File.exists?(File.expand_path(ROOT_TRIGGER, path)))
42
+ @rails_root = path
43
+ else
44
+ last_path = path
45
+ path = File.expand_path("..", path)
46
+
47
+ break if (last_path == path)
48
+ end
49
+ end
50
+
51
+ @rails_root
52
+ end
53
+
54
+ # == Main ===================================================================
55
+
56
+ options = { }
57
+
58
+ parser = OptionParser.new do |parser|
59
+ parser.on("-s", "--show", "List all Pow launched Ruby processes") do
60
+ options[:show] = true
61
+ end
62
+ parser.on("-k", "--kill", "Kill all Pow launched Ruby processes") do
63
+ options[:kill] = true
64
+ end
65
+ parser.on("-t", "--touch", "Creates a new #{RESTART_PATH} in the Rails root (default action)") do
66
+ options[:touch] = true
67
+ end
68
+ end
69
+
70
+ args = parser.parse(*ARGV)
71
+
72
+ _root = rails_root
73
+
74
+ unless (_root)
75
+ STDERR.puts("Could not find #{ROOT_TRIGGER} to locate Rails root")
76
+ exit(-1)
77
+ end
78
+
79
+ if (options[:show])
80
+ rails_processes(_root).each do |process|
81
+ puts '%6d %s' % [ process[0], process[1].join(' ') ]
82
+ end
83
+ elsif (options[:kill])
84
+ rails_processes(_root).each do |process|
85
+ Process.kill('TERM', process[0])
86
+ end
87
+ else
88
+ system("touch", File.expand_path(RESTART_PATH, _root))
89
+ end
data/lib/powr.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Powr
2
+ end
data/powr.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: powr 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "powr"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Scott Tadman"]
14
+ s.date = "2014-06-19"
15
+ s.description = "Simple Rack process management"
16
+ s.email = "scott@twg.ca"
17
+ s.executables = ["powr"]
18
+ s.extra_rdoc_files = [
19
+ "LICENSE.txt",
20
+ "README.md"
21
+ ]
22
+ s.files = [
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/powr",
29
+ "lib/powr.rb",
30
+ "powr.gemspec"
31
+ ]
32
+ s.homepage = "http://github.com/twg/powr"
33
+ s.licenses = ["MIT"]
34
+ s.rubygems_version = "2.2.2"
35
+ s.summary = "Pow Ruby Rack Process Manager Tool"
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 4
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
42
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
43
+ else
44
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
45
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
49
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
50
+ end
51
+ end
52
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Tadman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jeweler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: Simple Rack process management
42
+ email: scott@twg.ca
43
+ executables:
44
+ - powr
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - LICENSE.txt
48
+ - README.md
49
+ files:
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - VERSION
55
+ - bin/powr
56
+ - lib/powr.rb
57
+ - powr.gemspec
58
+ homepage: http://github.com/twg/powr
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Pow Ruby Rack Process Manager Tool
82
+ test_files: []