Foreman not finding rake tasks; error: rake tasks 'not found' - ruby-on-rails

Using Foreman on my rails application with Ruby 1.9.3 just fine. Switched to JRuby and now, as an example, get :
18:22:16 solr.1 | /home/scott/.rvm/gems/jruby-1.6.8#jruby168-unicon/gems/foreman-0.47.0/bin/foreman-runner: 32: exec: bundle exec rake sunspot:solr:run: not found
When I run bundle exec rake sunspot:solr:run on its own on the command line it runs just fine
Procfile:
web: puma
solr: bundle exec rake sunspot:solr:run
redis: redis-server ./config/redis.conf
sidekiq: bundle exec sidekiq -c $SIDEKIQ_CONCURRENCY -q report -q publish_item -q audio -q import -q email -q enrollment -q bugsnag
bunchball: bundle exec sidekiq -c 2 -q bunchball
sidekiq_solr: bundle exec sidekiq -c 1 -q solr

You have install bundler in Jruby.
gem install bundler

Related

Delayed_job restarting manually works, but not via crontab

If I run my script manually, i.e. sh /home/deploy/scripts/cleanup.sh, everything works fine, but when executing the same script via crontab, the delayed_job part does not work (everything else works!)
# Restart all processes
cd ~/apps/kosher/current
~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/kosher/shared/tmp/pids/puma.state -F /home/deploy/apps/kosher/shared/puma.rb stop
~/.rvm/bin/rvm default do bundle exec puma -C /home/deploy/apps/kosher/shared/puma.rb --daemon
if RAILS_ENV=production bin/delayed_job restart
then
echo "kosher delayed_job restarted" >> /home/deploy/scripts/cleanup.log
else
echo "kosher delayed_job restart failed" >> /home/deploy/scripts/cleanup.log
fi
I tried to use ~/.rvm/bin/rvm default do bundle exec bin/delayed_job -n 1 restart instead of RAILS_ENV=production bin/delayed_job restart, but then I receive an error, stating, that I'm missing the listen-gem:
bundler: failed to load command: bin/delayed_job (bin/delayed_job)
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
However, my Gemfile does indeed include the gem.
Why can't I restart delayed_job via crontab?

Why I am not able to run Unicorn RoR

I am trying to install a RoR server on Amazon EC2 using Amazon Linux and Ansible. Everything goes through fine, at the end I am not able to run unicorn. I have checked that unicorn gem is installed
`gem list | grep unicorn`
showed unicorn installed.
When I type
`unicorn_rails`
I get command not found error. I checked my gem file and it has the line gem unicorn then I run bundle install and the output has unicorn in the list. Still not able to run it.
Thanks.
I'm not sure that you can run unicorn_rails. Just use:
bundle exec unicorn -p <port> -c <path_to_config_file>
For example:
bundle exec unicorn -p 3000 -c ./config/unicorn.rb
If you are using bundler run unicorn with bundle exec:
$ bundle exec unicorn_rails
Find out more here.

God using sudo fails to find the environment parameter SECRET_KEY_BASE in the .bash_profile file

I added those rows to /home/web/.bash_profile. The web is the user of Rails app.
SECRET_KEY_BASE=xxxxxxxxxxxxxxxxxxxxx
export SECRET_KEY_BASE
I added this row into /etc/sudoers.
Defaults env_keep += "SECRET_KEY_BASE"
This command returns expected result.
sudo ruby -e 'puts ENV["SECRET_KEY_BASE"]'
If I run Unicorn without God, it can find SECRET_KEY_BASE from environment, and performs normally.
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
Running Unicorn using sudo without God performs normally, too.
sudo bundle exec unicorn_rails -c config/unicorn.rb -E production -D
But when I run Unicorn with God using sudo, it failed to find SECRET_KEY_BASE and becomes error.
sudo god start my_app
The start command in the my_app.god is this.
God.watch do |w|
w.start = "cd #{rails_root} && bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D"
w.uid = 'web'
w.gid = 'web'
...
end
It seems that the problem exists around God rather than .bash_profile and Unicorn. Besides what should I try?
I added this line into the my_app.god
ENV["SECRET_KEY_BASE"] = 'xxxxxxxxxxxxxxxxxxxxxxxx'
I know that this isn't a cool solution, but it works. And SECRET_KEY_BASE isn't included in a Git repository as source code.

Trying to connect to my Rails web app results in a directory listing

Rails 3.2.18
Ruby 2.1.5
Capistrano
Apache2
Phusion Passenger
Ubuntu 14.04.2
I have been using Capistrano to deploy my application. The set of commands that Capistrano executes (after connecting to the repo and copying all the files):
cd /home/myapp/current
RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
cp /home/myapp/shared/assets/manifest.yml /home/myapp/current/assets_manifest.yml
touch /home/myapp/current/tmp/restart.txt
echo \"DEPLOY SIDEKIQ RELOAD $(date)\" >> /home/myapp/current/log/sidekiq.log
screen -d -m sh -c 'cd /home/myapp/current && RAILS_ENV=production bundle exec sidekiq'
cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:stop
cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:start
screen -d -m sh -c 'cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:reindex'
Recently, following a deployment, instead going into the web application, when I enter the URL, all I see is a directory listing of the /home/myapp/current/public in my browser.
I can start the application manually by doing:
cd ~/current
sudo service apache2 stop
rvmsudo bundle exec rails s -e production -p 80 -d
The problem here is that some of the Rails app tasks start running as root (writing files, files uploaded, etc), which is problematic and is probably a security risk. Any ideas?

Why heroku does not run my procfile processes?

When I run foreman start on localhost all the process inside the Procfile run normally:
#Procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
resque: env TERM_CHILD=1 QUEUE=* bundle exec rake resque:work
sqs_converted: bundle exec rake sqs:listen_converted
sqs_failed: bundle exec rake sqs:listen_failed
$ foreman start
13:52:07 sqs_failed.1 | started with pid 3521
13:52:07 web.1 | started with pid 3518
13:52:07 sqs_converted.1 | started with pid 3520
13:52:07 resque.1 | started with pid 3519
But when I deploy to heroku and run heroku ps all I have running is a web.1 instance
=== web: `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: up for 8m
Can't figure out what is happening...
Thanks
You still need to scale your processes with heroku ps:scale resque=1 sqs_convert=1 sqs_failed=1. You can read all about scaling your processes and the commands you can use in Scaling your process formation in the Heroku docs.

Resources