How can I run multiple apps of multiple bundle with foreman - ruby

I have a ruby app that depends of several web-services i've built.
To start all together I've got the following Procfile:
mondodb: /home/dwaynemac/mongodb/bin/mongod
accounts: ./script/start_accounts.sh
contacts: ./script/start_contacts.sh
activity: ./script/start_activity_stream.sh
web: ./script/start.sh
Each of this start_xxx.sh script do something like:
cd ../activity_stream; bundle exec unicorn -p 3003 -c ./config/unicorn.rb
If I manually run these previous line activity_stream runs ok. But when ran from foreman some gems are not recognized. As if the bundle was not correctly built.
Example error:
activity_stream/config/boot.rb:2:in `require': no such file to load -- grape (LoadError)

Use the subcontractor gem to change working directory:
image_fallback: subcontract -d lib/rack/img_fallback/ -- bundle exec unicorn -c unicorn.conf config.ru

You will have to use a new bash shell for each app you want to boot up.
# Procfile
app1: sh -c 'cd path/to/app1 && bundle exec rackup config.ru -p $PORT'
app2: sh -c 'cd path/to/app2 && bundle exec rackup config.ru -p $PORT'
Then use foreman
foreman start --procfile path/to/Procfile
More info here http://www.seanbehan.com/how-to-boot-up-multiple-sinatra-applications-at-the-same-time-with-foreman

Related

Running bundle exec rake inside cron cannot find specific version of rake

I am setting up cron to run some rake tasks for my ruby on rails server. They are generated by whenever and look like this:
* * * * * /bin/bash -l -c 'cd /var/www && RAILS_ENV=production /usr/local/bin/bundle exec /usr/local/bin/rake my:task --silent >> /var/www/log/cron.log 2>&1'
bundle and rake executables seem to be found, but inside cron.log I find this error:
bundler: failed to load command: /usr/local/bin/rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-12.3.2 in any of the sources
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/spec_set.rb:91:in `block in materialize'
...
...
As I can see it tried to load rake-12.3.2, which is a correct version, from /usr/local/lib/ruby/gems/2.5.0/gems, which is not a correct path, because there is no rake-12.3.2. Correct version of rake is under another path /usr/local/bundle/gems, but I have no luck setting this path for cron to use.
I have tried adding GEM_PATH="/usr/local/bundle/gems" to cron file, but it doesn't work.
I am not using rvm or rbenv, ruby is installed directly.

How to start the rails console on Heroku with a multi-buildpack?

I'm deploying to heroku with the multi-buildpack on the cedar stack using a custom procfile:
web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
console: bundle exec irb -r ./console
When I boot my console with heroku run console I get LoadError: cannot load such file -- ./console and a virgin irb session.
How can I initialize the console with rails and my application environment loaded?
So running irb is obviously wrong.
What I needed was console: bundle exec rails console

Why is my middleman heroku app ignoring the Procfile?

I've been struggling trying to launch my middleman repo to heroku. I've followed a tutorial http://randomerrata.com/post/56163474367/middleman-on-heroku, but have had continued issues. Although installing the puma gem, for some reason the procfile is being ignored and the heroku app keeps pointing to
web bundle exec sudo unicorn_rails -c ./config/unicorn.rb -p $PORT -D --env production
Any idea how to get this thing to stop pointing to the unicorn rails and use puma?
Perhaps it would be worth checking out middleman-heroku as a different route to take. Alternatively I would check that your Gemfile.lock is up to date and committed.
I would try tailing the logs with heroku logs -t to see if you can see what's happening.
Is your Procfile called Procfile with a capital P?
What does it look like, can you post it here?
My Procfile has web: bundle exec puma -p $PORT. Is Puma listed in your Gemfile?

How to run Rack-based application (not Rails) with Unicorn

How can I run a Rack-based application (not Rails) with unicorn? Let's assume I have a "hello world" response simple rack app with the name of server.ru, and config file at the same directory with the name of unicorn.conf, how am I supposed to run it? In Thin, for example, I would do something like:
bundle exec rackup server.ru -s thin -E production -p 4001
How would I do the same to run under Unicorn?
Unicorn does not give any special treatment to Rails 3+ applications, so the behavior is exactly the same for Rails 3+ applications and non-Rails Rack applications. Just run
unicorn
in your app's root. To run with a specific port, pass -p/--port with the port:
unicorn -p 4001
You can also specify the rackup file:
unicorn server.ru
You can see all the options by running unicorn --help. Of course, you should prepend bundle exec to these commands as needed by your setup.
You can make a setting file for unicorn like this:
working_directory "/path/to/your/app"
listen 4001
pid "/tmp/unicorn.pid"
And then launch unicorn with the following command:
unicorn -c /path/to/your/setting/file.rb

Heroku Cedar: how to stop using WEBrick

In my Gemfile I have:
gem 'thin'
But when I push my application to Heroku Cedar, WEBrick is still used ("Booting WEBrick" in logs).
Where might be a problem?
You just need to create a Procfile and add the following line:
web: bundle exec rails server -p $PORT thin -e $RACK_ENV
Push that to Heroku and you'll be all set.

Resources