2

My cron job works fine on my local machine after running whenever -w, after deploy to my VPS, I get this error, release 20150415044915 doesn't exist. any idea?

I looked at my crontab -e, the path also looks fine where 20150502114703 is the correct release:

0 1 * * 1 /bin/bash -l -c 'cd /home/hey_production/releases/20150502114703 && bin/rails runner ....

Error Log:

/usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler/definition.rb:22:in `build': /home/hey_production/releases/20150415044915/Gemfile not found (Bundler::GemfileNotFound)
  from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler.rb:154:in `definition'
  from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler.rb:117:in `setup'
  from /usr/local/rvm/gems/ruby-2.1.3/gems/bundler-1.7.3/lib/bundler/setup.rb:17:in `<top (required)>'
  from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
  from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
  from /usr/local/rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
  from bin/rails:14:in `<main>' 
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
user1883793
  • 4,011
  • 11
  • 36
  • 65
  • The `Gemfile` will be found under the `current` folder of the release path. i.e. at `/home/hey_production/releases/20150415044915/current/Gemfile` - not `/home/hey_production/releases/20150415044915/Gemfile`. – Prakash Murthy May 02 '15 at 13:14
  • It should point to `/home/hey_production/current/Gemfile`. Release *20150415044915* might get cleaned up in the future. – Nitish Parkar May 02 '15 at 16:31
  • I dont understand the down vote. – Saad Masood May 04 '15 at 14:03
  • @PrakashMurthy `/home/hey_production/current` points to the release `/home/hey_production/releases/20150415044915`. Not the other way around. Or am i mistaken? The `/home/hey_production/releases/20150415044915` folder would not have any `current` directory because its a release. – Saad Masood May 04 '15 at 14:05
  • can you attach the log output from `/var/log/cron` – Saad Masood May 05 '15 at 14:50

2 Answers2

2

Basically the environment variable is missing that tells the cron where to look for a Gemfile. so you need to add that variable in your environment at the time when cron tries to run this. You can do that in Your schedule.rb:

env BUNDLE_GEMFILE, ENV["/home/hey_production/current/Gemfile"]

or directly inside crontab file with the command crontab -e(before the cron entries):

BUNDLE_GEMFILE="/home/hey_production/current/Gemfile"  

Hope it helps.

EDIT Forgot the symbol above in schedule.rb

The line in schedule.rb should be like this.

env :BUNDLE_GEMFILE, ENV["/#{path}/Gemfile"]

or

env :BUNDLE_GEMFILE, ENV["/home/hey_production/current/Gemfile"]
Saad Masood
  • 11,036
  • 9
  • 32
  • 40
  • Thanks, insert BUNDLE_GEMFILE="/home/hey_production/current/Gemfile" into crontab -e works, and env BUNDLE_GEMFILE, ENV["/home/hey_production/current/Gemfile"] raise BUNDLE_GEMFILE undefined when I deploy using Capistrano, any idea? – user1883793 May 05 '15 at 22:37
  • Yes. I'm not sure of the syntax in the schedule file. I will get back to you soon with the correct syntax. – Saad Masood May 05 '15 at 22:39
0

As a follow up on previous answer, set the env variable in whenever inside schedule.rb before the schedule blocks like:

def production?
  @environment == 'production'
end

set :output, {:error => '/home/current/log/cron_error.log', :standard => '/home/current/log/cron.log'}

every 2.hour, roles: [:utility] do
  runner "/home/current/lib/cron_jobs/launch_pending_emails.rb"
end

and inside your deploy.rb environment specific file ie: staging.rb set the env:

set :whenever_roles, [:utility]
set :whenever_environment, defer { stage }
set(:whenever_command) { "STAGE=#{stage} bundle exec whenever" }
require 'whenever/capistrano'
cnikolaou
  • 3,782
  • 4
  • 25
  • 32