subcontractor 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -0,0 +1,44 @@
1
+ ### Overview
2
+
3
+ [Foreman](https://github.com/ddollar/foreman) is a gem released by Heroku that allows you to easily manage multiple processes with a Procfile. It ensures all processes launch successfully, colorizes output, and allows you to kill all processes with a simple CTL+C. It's simple and elegant.
4
+
5
+ Its not perfect however. For one, it doesn't handle running processes from a different directory. It also doesn't deal well with the complexity of running processes under a different RVM. You are probably thinking, "well, those aren't really Foreman's responsibilities". I agree with you. This gem fills that gap.
6
+
7
+ ### Usage
8
+
9
+ ```
10
+ gem install subcontractor
11
+ ```
12
+
13
+ or with bundler
14
+
15
+ ```ruby
16
+ gem 'subcontractor', '0.1.0'
17
+ ```
18
+
19
+ The gem provides an executable called ```subcontract``` that you will use from your Procfile. You can see what it does by running ```subcontract --help```
20
+
21
+ ```
22
+ USAGE: subcontract [options] -- executable
23
+ -r, --rvm RVM run in a specific RVM
24
+ -d, --chdir PATH chdir to PATH before starting process
25
+ -s, --signal SIGNAL signal to send to process to kill it, default TERM
26
+ ```
27
+
28
+ An example Procfile tells the story
29
+
30
+ ```
31
+ rails: rails s
32
+ another_app: subcontract --rvm ruby-1.8.7-p249@another_app --chdir ../another_app --signal INT -- rails s -p 3001
33
+ ```
34
+
35
+ Here another_app will be launch from the sibling directory another_app and will use the rvm ruby-1.8.7-p249@another_app. As you can see, the command that we wish to use to launch our application follows the double dashes (--).
36
+
37
+ ### Contributions
38
+ * Fork the project
39
+ * Make your change
40
+ * Add your name and contact info the the Contributors section below
41
+ * Send a pull request (bonus points for feature branches)
42
+
43
+ ### Contributors
44
+ * Tony Pitluga [github](http://github.com/pitluga) [twitter](http://twitter.com/pitluga)
data/examples/Procfile CHANGED
@@ -1,2 +1,3 @@
1
- webapp: ruby -I ../lib ../bin/subcontract --rvm ruby-1.8.7-p249@subcontractor-webapp --chdir webapp -- bundle exec thin --rackup config.ru start
1
+ thin: ruby -I ../lib ../bin/subcontract --rvm ruby-1.8.7-p249@subcontractor-webapp --chdir webapp --signal INT -- bundle exec rackup config.ru -p 3001
2
+ webrick: ruby -I ../lib ../bin/subcontract --rvm ruby-1.8.7-p249@subcontractor-webapp --chdir webapp --signal INT -- bundle exec thin --rackup config.ru -p 3002 start
2
3
  sleepy: ruby -I ../lib ../bin/subcontract --chdir script -- ruby sleepy.rb
@@ -8,9 +8,10 @@ module Subcontractor
8
8
  options = parse_options(ARGV)
9
9
  command = build_command(ARGV.dup, options)
10
10
  Dir.chdir(options[:chdir]) if options[:chdir]
11
+ signal = options[:signal] || "TERM"
11
12
  PTY.spawn(command) do |stdin, stdout, pid|
12
13
  trap("TERM") do
13
- options.has_key?(:rvm) ? kill_term(*child_pids(pid)) : kill_term(pid)
14
+ options.has_key?(:rvm) ? send_kill(signal, *child_pids(pid)) : send_kill(signal, pid)
14
15
  end
15
16
  until stdin.eof?
16
17
  puts stdin.gets
@@ -18,8 +19,8 @@ module Subcontractor
18
19
  end
19
20
  end
20
21
 
21
- def kill_term(*pids)
22
- pids.each { |pid| Process.kill("SIGTERM", pid) }
22
+ def send_kill(signal, *pids)
23
+ pids.each { |pid| Process.kill(signal, pid) }
23
24
  end
24
25
 
25
26
  def child_pids(pid)
@@ -37,12 +38,16 @@ module Subcontractor
37
38
  def parse_options(argv)
38
39
  options = {}
39
40
  parser = OptionParser.new do |opt|
41
+ opt.banner = "USAGE: subcontract [options] -- executable"
40
42
  opt.on('-r', '--rvm RVM', 'run in a specific RVM') do |rvm|
41
43
  options[:rvm] = rvm
42
44
  end
43
45
  opt.on('-d', '--chdir PATH', 'chdir to PATH before starting process') do |path|
44
46
  options[:chdir] = path
45
47
  end
48
+ opt.on('-s', '--signal SIGNAL', 'signal to send to process to kill it, default TERM') do |signal|
49
+ options[:signal] = signal
50
+ end
46
51
  end
47
52
 
48
53
  parser.parse! argv
@@ -1,3 +1,3 @@
1
1
  module Subcontractor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subcontractor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Pitluga
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-11 00:00:00 Z
18
+ date: 2011-10-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: foreman