New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whenever gem 'failed to load command: rake' #656

Closed
Awatatah opened this Issue Aug 8, 2016 · 9 comments

Comments

Projects
None yet
6 participants
@Awatatah

Awatatah commented Aug 8, 2016

looking for some help.

I am running a rails app (v3.2.5) with the whenever gem (v0.9.7) and rake (v11.2.2). I am also doing this in a docker container image ruby:2.3 (cron was installed and bundle install was ran)

Here is my schedule.rb

set :environment, ENV['RAILS_ENV']

every '*/2 9,10,11,12,13,14,15,16 * * 1-5' do
    rake "import_csv", output: {:error => 'log/import_csv_errors.log', :standard => 'log/import_csv.log'}'
end

note RAILS_ENV is set at container launch to development

Here is my cron job that is on the container after build (crontab -l):

# Begin Whenever generated tasks for: /usr/src/app/config/schedule.rb
*/2 9,10,11,12,13,14,15,16 * * 1-5 /bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'

# End Whenever generated tasks for: /usr/src/app/config/schedule.rb

When this cron job runs, the logs return:

import_csv_errors.log

Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>'
  /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

import_csv.log

bundler: failed to load command: rake (/usr/local/bin/rake)

Now here is the odd thing. If I copy the cron job command:

/bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'

and run this in the container, it works fine, but if the cron job runs it, I get thos errors in the logs!!! I am at a lost here...

I've tried adding

env :PATH, ENV['PATH']
env :GEM_PATH, '/usr/local/bundle'

to the top of schedule.rb and I tried doing

command 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log'

Instead of using rake in the task and I get the same errors..

Any help is appriciated

@benlangfeld

This comment has been minimized.

Show comment
Hide comment
@benlangfeld

benlangfeld Aug 8, 2016

Collaborator

How did you install Ruby?

Collaborator

benlangfeld commented Aug 8, 2016

How did you install Ruby?

@Awatatah

This comment has been minimized.

Show comment
Hide comment
@Awatatah

Awatatah Aug 8, 2016

Ruby was installed with the image - Ruby 2.3 (Docker hub)

Awatatah commented Aug 8, 2016

Ruby was installed with the image - Ruby 2.3 (Docker hub)

@Awatatah

This comment has been minimized.

Show comment
Hide comment
@Awatatah

Awatatah Aug 9, 2016

In case you need it:
Ruby
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
Rails
Rails 3.2.5
OS
Distributor ID: Debian
Description: Debian GNU/Linux 8.5 (jessie)
Release: 8.5
Codename: jessie
Kernel
Linux 3.13.0-74-generic x86_64

Awatatah commented Aug 9, 2016

In case you need it:
Ruby
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
Rails
Rails 3.2.5
OS
Distributor ID: Debian
Description: Debian GNU/Linux 8.5 (jessie)
Release: 8.5
Codename: jessie
Kernel
Linux 3.13.0-74-generic x86_64

@joe11051105

This comment has been minimized.

Show comment
Hide comment
@joe11051105

joe11051105 commented Aug 11, 2016

+1 me too

@joe11051105

This comment has been minimized.

Show comment
Hide comment
@joe11051105

joe11051105 Aug 11, 2016

I fix this issue, there are two reasons

  • docker ruby 2. 3 image reinstall bundler,see this issue
  • setting ENV.each { |k, v| env(k, v) } in your config/schedule.rb, see this blogs

joe11051105 commented Aug 11, 2016

I fix this issue, there are two reasons

  • docker ruby 2. 3 image reinstall bundler,see this issue
  • setting ENV.each { |k, v| env(k, v) } in your config/schedule.rb, see this blogs
@Awatatah

This comment has been minimized.

Show comment
Hide comment
@Awatatah

Awatatah Aug 11, 2016

I was also able to resolve by using a Ubuntu image instead. Here is partially my Dockerfile incase anyone wants to use my method:

FROM ubuntu:15.10
# Installs needed to run rails on ubuntu
RUN apt-get update && apt-get install -y apache2 curl git build-essential libmysqlclient-dev mysql-server-5.6 nodejs make
RUN apt-get update && apt-get install -y ruby-dev zlib1g-dev
RUN gem install rails --version 3.2.5 --no-ri --no-rdoc

# Finish the build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Copy your code over to the dir
COPY . /usr/src/app/.
RUN bundle config --global frozen 1
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle install

#Install cron and start
RUN apt-get install -y cron && cron -f

# Update the crontab
RUN whenever -w

# set command
CMD ["passenger start"]

Awatatah commented Aug 11, 2016

I was also able to resolve by using a Ubuntu image instead. Here is partially my Dockerfile incase anyone wants to use my method:

FROM ubuntu:15.10
# Installs needed to run rails on ubuntu
RUN apt-get update && apt-get install -y apache2 curl git build-essential libmysqlclient-dev mysql-server-5.6 nodejs make
RUN apt-get update && apt-get install -y ruby-dev zlib1g-dev
RUN gem install rails --version 3.2.5 --no-ri --no-rdoc

# Finish the build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Copy your code over to the dir
COPY . /usr/src/app/.
RUN bundle config --global frozen 1
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle install

#Install cron and start
RUN apt-get install -y cron && cron -f

# Update the crontab
RUN whenever -w

# set command
CMD ["passenger start"]

@Awatatah Awatatah closed this Aug 11, 2016

@againer

This comment has been minimized.

Show comment
Hide comment
@againer

againer Jun 16, 2017

@joe11051105
"- setting ENV.each { |k, v| env(k, v) } in your config/schedule.rb, see this blogs"

my savior

againer commented Jun 16, 2017

@joe11051105
"- setting ENV.each { |k, v| env(k, v) } in your config/schedule.rb, see this blogs"

my savior

@mysterytree

This comment has been minimized.

Show comment
Hide comment
@mysterytree

mysterytree Jul 14, 2017

@joe11051105
I follow the blog and get the error

"-":36: bad minute
crontab: errors in crontab file, can't install
[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid.

mysterytree commented Jul 14, 2017

@joe11051105
I follow the blog and get the error

"-":36: bad minute
crontab: errors in crontab file, can't install
[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid.
@goetzc

This comment has been minimized.

Show comment
Hide comment
@goetzc

goetzc Jul 27, 2018

@mysterytree Might have been caused by using the 0/1 syntax, try using */1 instead.

goetzc commented Jul 27, 2018

@mysterytree Might have been caused by using the 0/1 syntax, try using */1 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment