I'm trying to pipe mail from postfix to a rails tasks. I've got this working successfully when just piping to a vanilla ruby script, but when switching to a rails task I get the following error in the mail.log from Postfix:
(Command died with status 1: "/usr/local/bin/rake". Command output: /usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find rake (>= 0) amongst [] (Gem::LoadError) from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:into_spec' from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in gem' from /usr/local/bin/rake:22:in' )
Here is the piping line from master.cf
email-task unix - n n - 2 pipe
flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/rake RAILS_ENV=production myapp:process_email
Running the command which rake returns /usr/local/bin/rake so I have verified I have the correct rake path.
I've tried setting ENV['PATH'] inside of the .rake file to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games and I've also tried cd'ing to the rails app directory in the pipe command but still causes the same error. I've done bundle install and update etc.
Any help is greatly appreciated...thank you!
UPDATE
I tried using bundle exec rake etc as suggested but am now getting this error:
Command died with status 127: "/usr/local/bin/bundle". Command output: bundler: command not found: rake Install missing gem executables with bundle install
I've tried adding gem 'rake' to the Gemfile as well. I'm assuming bundler can't find the Gemfile?
UPDATE (FIXED)
So the command that finally worked was the following:
email-task unix - n n - 2 pipe
flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/bundle exec /usr/local/bin/rake RAILS_ENV=production mytask
It was a combination of errors on my part.
Full paths need to be used for bundle and rake
app name is not needed in the task param for rake since the directory is being selected before executing
A side issue: an old version of ruby was being used which caused an unrelated gem error after executing the postfix pipe
Appreciate the help everyone.
I think your on the wrong track, it's not the system that can't find rake it's your rubygems. Instead of running rake as your command, try running bundle passing whatever you need to in order for it to basically be bundle exec rake...etc
Update
Based on your new information, it would seem that the rake gem is not installed in your app. Run bundle show rake
Assuming it's not there, I'm wondering why. Did you ship your app with packaged gems or something? Basically, did you not run bundle install in your deployed app?
Related
Rails C and Rails S not working when in the correct directory.
have tried:
$ bundle exec rake rails:update:bin
this returns the following error:
bundler: command not found: rails:update:bin
Install missing gem executables with `bundle install`
I have ran:
Bundle Install
this still returns the same error
Have changed directories (higher and lower), repeated steps and attempted commends for same result.
I was running rails server, when i stopped the server and tried to restart server, the error appeared, so I'm thinking this has something to do with a physical location change (potentially the bin file), which is consistent as when I try and run a bin/rails command, i'm receiving an error of:
bundler: command not found: rails:update:bin
Install missing gem executables with `bundle install`
I have tried to rake the bin folder as below:
rake rails:update:bin
however I am receiving this error:
rake aborted!
Don't know how to build task 'rails:update:bin' (see --tasks)
Finally, I have checked the physical location and there is a .bin file, however this folder is empty and it's not in a .gitignore directory.
Ancillary information
Rails version: 5.1.4
ruby version: 2.3.4
Server: heroku
OS. Ubuntu 16.04 (via virtualbox).
I have not upgraded rails, this is a fresh install
I am at a loss.
rails update:bin or rake update:bin These are the right ways that execute a rake task.
I am in process of installing Redmine app via RedmineInstall documentation I try step 5 :
bundle exec rake db:migrate
then error shows :
bundler: command not found: rake
Install missing gem executables with ´bundle install´
I use redmine 3.3.0 64 for windows
I use redmine gemfile and rake was installed (i see Using rake 11.2.2)
I tried reinstall it via bundle install or gem install/uninstall, but did not help (see Successfully installed rake-11.2.2 but rake do not work).
I tried this command from ruby/bin directory or redmine directory not success.
I do not understand, that rake is successfully installed, but when i try use it with bundle it says that command not found.
The problem may be in the directory where the Redmine or rake?
Try rake db:migrate in your redmine directory without bundle exec and see if that resolves your issue.
Bundler usually provides bin stubs for rake and other gem files, so that bundle exec is not necessary or will even fail because it will look in an other gem directory where, in this case, rake might not be installed.
I am trying to setup solr sunspot search in production mode.
I have followed the below tutorial and got success in setting up tomcat-solr server running.
http://www.arborisoft.com/how-to-install-apache-solr-4-4-on-ubuntu-12-04/
I ran
rails generate sunspot_rails:install
and configured the config/sunspot.yml file.
For development mode I used 'sunspot_solr' gem(which is not advisable for production mode) and got this command working.
bundle exec rake sunspot:solr:start
When I removed this gem
it's giving me following error
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
I have tried adding this to Rakefile:
require 'sunspot/solr/tasks'
when I run the following command
bundle exec rake app:sunspot:solr:start
I am getting the following error
rake aborted!
cannot load such file -- sunspot/solr/tasks
I am using rails 4.
I don't know what I've missed. I have searched for the solution in and out of stackoverflow. But I couldn't get any reference. Even if I find any since I am a rails noob, I couldn't understand what they are talking about. any solution will be really helpful.
You can also change the path to solr/default in config/sunspot.yml file for production mode or any other defined modes.
These are some terminal commands which could follow to solve your problems:
ps aux | grep solr to get solr process ID
through this you can check which server id is running and which one is in your sunspot pid file.
sudo kill <ID>, <ID> is the ID you found from 1
rm -r <path/to/solr>, remove the solr directory inside your project to remove all of previous indexes
RAILS_ENV=production bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=production bundle exec rake sunspot:solr:reindex
this link can also help in understanding problem and issues:https://github.com/sunspot/sunspot/issues/492
I learned Rails using just the rake command like rake db:migrate; however, I read that I should be using the bundle exec rake ... instead of just plain rake. Now I'm confused about which to use.
Should I be using bundle exec rake instead of just plain rake or is it just a preference thing? Any insight would be much appreciated! Thanks!
bundle exec executes a command in the context of your bundle.
That means it uses the gems specified in your Gemfile. Much of the time, running bundle exec rake foo has the same results as if you just ran rake foo, especially if you have the same gems installed systemwide as in your Gemfile. However, some applications may specify different versions of gems than the ones you have installed systemwide, and may want those exact gems and versions to be able to run correctly. If you just run without bundle exec, you may get some weird errors.
Using bundle exec guarantees that the program is run with the environment specified in the gemfile, which hopefully means it is the environment that the creators of the program want it to be run in, which hopefully means it should run correctly no matter what weird setup you have on your computer.
It basically standardizes the environment under which the program is run. This helps avoid version hell and makes life much easier.
See http://bundler.io/v1.3/man/bundle-exec.1.html for more info.
$ bundle exec rake db:migrate
Uses the version of rake specified in the Gemfile to execute the rake task db:migrate.
But there is no rake gem specified in the Gemfile!
Yes, but a rake gem was installed as a dependency of some other gem--look in Gemfile.lock. So the rule must be: Uses the version of rake specified in Gemfile.lock.
But Gemfile.lock doesn't specify a specific version--it specifies a version greater than x.y!
Then the rule must be: Uses the version of rake that was installed in the current gemset.
$ rake db:migrate
Normally, when you issue a command on the command line, e.g. rake, your system searches for the command in the list of directories specified in your PATH environment variable. The first directory that contains the command is the version of the command that is used. To see which directory that is, you can do:
$ which rake
So if you execute,
$ rake db:migrate
that may use a different rake gem than the one you installed with bundle install. But, even if your system finds the same rake version as bundle exec, any gems required by the rake source code will be searched for in places outside your project's gemset. Therefore, there are many ways that just:
$ rake db:migrate
can screw things up.
According to the Ruby on Rails Tutorial Book(free online), section 3.6, if you are using rvm 1.11.x+ then you do not need to preface commands with bundle exec.
running any exacutable without bundle exec will have Rubygems fetching the latest version of the gem installed in your system.
By adding the bundle exec prefix instead will have the executable running in the context of your Gemfile.lock, which means that will be run using the version defined in the gem file.
I am using Ruby Enterprise Edition for my project. When I check all my rake task by run the command rake -T , I got the following error message:
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.
The error message implies that I can use bundle exec to solve the problem, but I am not sure how? So, how to get rid of this error message?
------------------------------ more ---------------------------
I prefer to update my Gemfile instead of run bundle exec rake -T. But when I open my project Gemfile, I did not see rake 0.9.2 in my Gemfile, why the error message complains that I have it? Where could be the place I defined rake 0.9.2??
Run bundle exec rake -T, this ensures that the version of rake that is specified in your Gemfile is running, not another version.
Alternatively, update your Gemfile.
This is because your rake tool does not match the version written in the Gemfile.
You first need to run this command, to ensure rake 0.9.2 get installed:
bundle install
Then, you can run rake 0.9.2 with the following command:
bundle exec rake -T
The bundle thing is a nice tool to help you manage the dependency of your application. You can get more info from here.