Giter Site home page Giter Site logo

subcontractor's Introduction

Notice

####I'm looking for a new maintainer for this project. I have not been a good steward and it seems to be useful to people. Any takers?

Overview

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.

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.

Usage

gem install subcontractor

or with bundler

gem 'subcontractor', '0.9.1'

The gem provides an executable called subcontract that you will use from your Procfile. You can see what it does by running subcontract --help

USAGE: subcontract [options] -- executable
    -r, --rvm RVM                    run in a specific RVM (use `.` for ruby from `PATH`)
    -b, --rbenv RBENV                run in a specific RBENV (use `.` for local rbenv)
    -h, --chruby CHRUBY              run in a specific CHRUBY
    -c, --choose-env ENV             run in either a specified RBENV, RVM or CHRUBY, whichever is present
    -d, --chdir PATH                 chdir to PATH before starting process
    -s, --signal SIGNAL              signal to send to process to kill it, default TERM

An example Procfile tells the story

rails: rails s
another_app: subcontract --rvm ruby-1.8.7-p249@another_app --chdir ../another_app --signal INT -- rails s -p 3001

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 (--).

You can also allow another_app to use its existing .rvmrc file. This will load the .rvmrc file out of the current folder once it has been changed to the folder specified by --chdir

rails: rails s
another_app: subcontract --rvm . --chdir ../another_app --signal INT -- rails s -p 3001

You can use specific rbenv version.

rbenv_app: bundle exec subcontract --rbenv 'ree-1.8.7-2012.02' --chdir ~/rbenv_app -- bundle exec rails server -p 3001

Or you can use whatever the local rbenv settings are for a project. This will load whatever rbenv local returns out of the current folder once it has been changed to the folder specified by --chdir

rbenv_app: bundle exec subcontract --rbenv . --chdir ~/rbenv_app -- bundle exec rails server -p 3001

If you have team members using both rvm and rbenv on a project then use --choose-env to use whatever version manager is present on the system. If both are present rbenv is chosen.

mixed_env_manager_app: bundle exec subcontract --choose-env . --chdir ~/mixed_env_manager_app -- bundle exec rails server -p 3001

Contributions

  • Fork the project
  • Make your change
  • Add your name and contact info the the Contributors section below
  • Send a pull request (bonus points for feature branches)

Contributors

subcontractor's People

Contributors

andrewradev avatar braintreeps avatar drewolson avatar huwtl avatar ihara2525 avatar itsthatguy avatar jtdowney avatar mnussbaum avatar mpapis avatar pgr0ss avatar pitluga avatar ralfthewise avatar runemadsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

subcontractor's Issues

`eof?': Input/output error - /dev/pts/2

From the following:
subcontract --chdir ../contacts -- bundle exec unicorn -p 3002 -c ./config/unicorn.rb

I get this error

subcontractor-0.4.1/lib/subcontractor/cli.rb:19:in `eof?': Input/output error - /dev/pts/2 (Errno::EIO)

Thread deadlock when recursively killing pids

When using the slanger example, this is happening with slanger 0.3.4

14:07:26 slanger.1 | /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:39:in ``': deadlock; recursive locking (ThreadError)
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:39:in `find_child_pids'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:32:in `find_pids_to_kill'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:14:in `block (2 levels) in run'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:39:in `call'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:39:in ``'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:39:in `find_child_pids'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:32:in `find_pids_to_kill'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:17:in `block (2 levels) in run'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:19:in `call'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:19:in `eof?'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:19:in `block in run'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:12:in `spawn'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/lib/subcontractor/cli.rb:12:in `run'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/gems/subcontractor-0.4.1/bin/subcontract:5:in `<top (required)>'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/bin/subcontract:19:in `load'
14:07:26 slanger.1 |    from /Users/tonyp/.rvm/gems/ruby-1.9.3-p125@test_shit/bin/subcontract:19:in `<main>'

constant not defined

I've got 2 rails apps.

App A and app B.

The both work just fine when started manually from the console.

When I try to start app B with foreman + subcontractor from app A I get

accounts/config/initializers/active_admin.rb:1:in `<top (required)>': uninitialized constant ActiveAdmin (NameError)

This is my procfile:

mondodb: ~/mongodb/bin/mongod
accounts: subcontract --rvm 1.9.2 --chdir ../accounts -- bundle exec rails s -p 3001
web: ./script/start.sh

I've tried

accounts: subcontract --rvm "--with-rubies rvmrc" --chdir ../accounts -- bundle exec rails s -p 3001

and

 new_rvm_app: accounts: subcontract --rvm --with-rubies default-with-rvmrc do --chdir ../accounts --signal INT -- bundle exec rails s -p 3001

They don't work either (the 2nd one has a different error though)

I'm using subcontractor 0.6.0

subcontract processes not killed on ctrl+c

Hello,
I'm using the Slanger gem which spawns a thin process.

push: subcontract --rvm ruby-1.9.3-p0@push --chdir ../push --signal INT -- bundle exec slanger --app_key xxx --secret xxx

However when I hit CTRL+C all the other processes defined in the Procfile quits but this one. I also tried to send the default TERM or leaving out the parameter, but it makes no difference.

I haven't checked the code yet but it appears foreman is killing subcontract while leaving the subprocess alive.

Issues with multiple ruby projects using rvm

Hello,
this is my Procfile that resides in my main project dir:

web:  bundle exec rainbows -p $PORT -c ./config/unicorn.rb
node: subcontract --chdir ../node --signal INT -- coffee application.coffee --environment development --uploader --streamer
push: subcontract --rvm "--with-rubies rvmrc" --chdir ../push --signal INT -- bundle exec slanger --app_key xxx --secret xxx --redis_address redis://127.0.0.1:6379/0

Now, ../push does use a .rvmrc like this:

rvm use --create --install ruby-1.9.2-p290@push

if ! command -v bundle ; then
  gem install bundler --no-rdoc --no-ri
fi

if ! command -v foreman ; then
  gem install foreman --no-rdoc --no-ri
fi

The issue here is that everytime I run foreman startwith this Procfilethe system will attempt to download bundler and foreman gems for the push project, sometimes only foreman, like in the example below:

18:31:13 push.1    | started with pid 26375
18:31:25 push.1    | 
18:31:25 push.1    | RVM is not a function, selecting rubies with 'rvm use ...' will not work.
18:31:25 push.1    | /Users/kain/.rvm/bin/bundle
Fetching: foreman-0.34.1.gem (100%)man-0.34.1.gem
18:31:25 push.1    | Successfully installed foreman-0.34.1
18:31:25 push.1    | 1 gem installed
18:31:25 push.1    | Unrecognized command line argument: 'bundle' ( see: 'rvm usage' )

Any idea? Thanks.

.bash_profile

[[ -s "/Users/kain/.rvm/scripts/rvm" ]] && source "/Users/kain/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

rbenv

any chance to get this working with rbenv and bundler.

Trying to run two rails apps and one is not using the Gemfile as its complaining about undefined methods/classes, which isn't an issue when running normally.

Bundler::GemNotFound

I created a new gemset in Ruby 1.9.3p194 using RVM. Ran gem install subcontractor and then tried the command subcontract --help and it has many dependency issues. I get the following output on a clean gemset

/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.4/lib/bundler/spec_set.rb:90:in 
`block in materialize': Could not find i18n-0.6.1 in any of the sources (Bundler::GemNotFound)

I installed the rails gem and I get the same error but with the missing gem builder-3.0.3

Shouldn't all these dependencies be installed when the subcontractor gem is installed?

rbenv with bundler

I'm getting an error when launching 2 rails instances in different directories using rbenv and bundler. I've looked at the other outstanding issue with rbenv and the suggestion to add the path to the Gemfile but that didn't work for me. This exact setup works with rvm using --rvm. I'm trying to switch my projects to rbenv. Both rails project run fine individually too using 'bundle exec rails server'.

Error is:

23:01:04 customerservice.1 | started with pid 28887
23:01:04 onevueapi.1       | started with pid 28888
23:01:05 onevueapi.1       | rbenv: no local version configured for this directory
23:01:05 onevueapi.1       | /home/andrew/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'bundler' (>= 0) among 8 total gem(s) (Gem::LoadError)
23:01:05 onevueapi.1       |    from /home/andrew/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/dependency.rb:309:in `to_spec'
23:01:05 onevueapi.1       |    from /home/andrew/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:53:in `gem'
23:01:05 onevueapi.1       |    from /home/andrew/.rbenv/versions/2.1.1/gemsets/onevueapi-gemset/bin/bundle:22:in `<main>'
23:01:05 onevueapi.1       | exited with code 0
23:01:05 system            | sending SIGTERM to all processes
23:01:05 customerservice.1 | terminated by SIGTERM

My Procfile is:

customerservice:       bundle exec rails s -p 3005
onevueapi:             bundle exec subcontract --rbenv . --chdir ../onevueapi --signal INT -- bundle exec rails s -p 3000

The directory ~/src/onevueapi exists and I'm executing like:

~/src/customerservice> bundle exec foreman start

subcontract not dying.

Foreman is dead. Child process is dead. subcontract is alive and doesn't die on kill with term or int. I am kill -9ing it. I'd prefer not to do that. Any advice? I have tried --signal INT and --signal TERM. The way I start forman is by nohup and & it into the background, piping the log into a file. The way I am killing foreman is to kill it. Other processes seem to be behaving fine.

Load correct .env on --chdir

When you're using --chdir you often want to load the .env file in the chdir directory, not the directory foreman is run from.

I might take a stab at this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.