subcontractor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.8.7-p249@subcontractor
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in subcontractor.gemspec
4
+ gemspec
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/subcontract ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "subcontractor/cli"
4
+
5
+ Subcontractor::CLI.new.run
data/examples/Procfile ADDED
@@ -0,0 +1,2 @@
1
+ webapp: ruby -I ../lib ../bin/subcontract --rvm ruby-1.8.7-p249@subcontractor-webapp --chdir webapp -- bundle exec thin --rackup config.ru start
2
+ sleepy: ruby -I ../lib ../bin/subcontract --chdir script -- ruby sleepy.rb
@@ -0,0 +1,5 @@
1
+ puts File.expand_path('.')
2
+ puts `rvm current`
3
+ trap("TERM") { puts "got term"; exit 0 }
4
+ sleep 100000
5
+ puts "done sleeping"
@@ -0,0 +1 @@
1
+ rvm ruby-1.8.7-p249@subcontractor-webapp --create
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "thin"
4
+ gem "sinatra"
@@ -0,0 +1,5 @@
1
+ require 'sinatra'
2
+
3
+ get "/" do
4
+ "hello world"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra'
3
+ require 'app'
4
+
5
+ run Sinatra::Application
@@ -0,0 +1,3 @@
1
+ module Subcontractor
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'optparse'
2
+ require 'pty'
3
+
4
+ module Subcontractor
5
+ class CLI
6
+
7
+ def run
8
+ options = parse_options(ARGV)
9
+ command = build_command(ARGV.dup, options)
10
+ Dir.chdir(options[:chdir]) if options[:chdir]
11
+ PTY.spawn(command) do |stdin, stdout, pid|
12
+ trap("TERM") do
13
+ options.has_key?(:rvm) ? kill_term(*child_pids(pid)) : kill_term(pid)
14
+ end
15
+ until stdin.eof?
16
+ puts stdin.gets
17
+ end
18
+ end
19
+ end
20
+
21
+ def kill_term(*pids)
22
+ pids.each { |pid| Process.kill("SIGTERM", pid) }
23
+ end
24
+
25
+ def child_pids(pid)
26
+ lines = `ps axo pid,ppid`
27
+ lines.map(&:split).select do |(child_pid, parent_pid)|
28
+ parent_pid == pid.to_s
29
+ end.map(&:first).map(&:to_i)
30
+ end
31
+
32
+ def build_command(parts, options)
33
+ parts.unshift("rvm #{options[:rvm]} exec") if options.has_key?(:rvm)
34
+ parts.join(' ')
35
+ end
36
+
37
+ def parse_options(argv)
38
+ options = {}
39
+ parser = OptionParser.new do |opt|
40
+ opt.on('-r', '--rvm RVM', 'run in a specific RVM') do |rvm|
41
+ options[:rvm] = rvm
42
+ end
43
+ opt.on('-d', '--chdir PATH', 'chdir to PATH before starting process') do |path|
44
+ options[:chdir] = path
45
+ end
46
+ end
47
+
48
+ parser.parse! argv
49
+ options
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Subcontractor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "subcontractor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "subcontractor"
7
+ s.version = Subcontractor::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tony Pitluga"]
10
+ s.email = ["tony.pitluga@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{rvm aware process launcher for foreman}
13
+ s.description = %q{rvm aware process launcher for foreman}
14
+
15
+ s.rubyforge_project = "subcontractor"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'foreman', '~> 0.22.0'
22
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subcontractor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tony Pitluga
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: foreman
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 71
29
+ segments:
30
+ - 0
31
+ - 22
32
+ - 0
33
+ version: 0.22.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: rvm aware process launcher for foreman
37
+ email:
38
+ - tony.pitluga@gmail.com
39
+ executables:
40
+ - subcontract
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - .rvmrc
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - bin/subcontract
52
+ - examples/Procfile
53
+ - examples/script/sleepy.rb
54
+ - examples/webapp/.rvmrc
55
+ - examples/webapp/Gemfile
56
+ - examples/webapp/app.rb
57
+ - examples/webapp/config.ru
58
+ - lib/subcontractor.rb
59
+ - lib/subcontractor/cli.rb
60
+ - lib/subcontractor/version.rb
61
+ - subcontractor.gemspec
62
+ homepage: ""
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: subcontractor
91
+ rubygems_version: 1.8.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: rvm aware process launcher for foreman
95
+ test_files: []
96
+