1

I have a Rails 3.2.14 legacy app in production and it's working fine. I'm migrating this app to a new server and will migrate the database from the production at time of switch over. So far I have the app spun up and it's working (for the most part). But when I use Capistrano to deploy to that server, the whenever gem doesn't seem to run (though it does on the original production server and updates crontab).

I'm using whenever gem 0.7.3, capistrano 2.12.0, Ruby 1.9.3p194 to keep the environment identical.

Here's what my deploy.rb in Capistrano looks like (and works on the old server to execute whenever:

require "bundler/capistrano"
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"

server "72.14.181.80", :web, :app, :db, primary: true

set :application, "appname"
set :user, "deploy"
set :deploy_to, "/home/#{user}/#{application}"
set :use_sudo, false
set :rails_env, "production"


set :scm, "git"
set :repository, "git@github.com:username/#{application}.git"
set :branch, "master"


default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases
after "deploy:update", "gps_listener:restart"

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
  end
end

namespace :gps_listener do
  task :start do
    run "#{sudo} start app-gps"
  end

  task :stop do
    run "#{sudo} stop app-gps"
  end

  task :restart do
    run "#{sudo} stop app-gps && sleep 1 && #{sudo} start app-gps"
  end
end

task :after_update_code do
  run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
  run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake gps:listen"
end

What's interesting is, when I deploy to our old production server whenever will execute and update the crontab with the rake tasks. But if I switch the IP in deploy.rb and deploy to our new server it will not execute and the Capistrano output doesn't show anything fishy that I can see.

Is there somewhere I can debug this? I want to keep the Capistrano/Rails configuration the same for both servers. Just not sure what the problem is. Maybe I'm overlooking something.

It should also be noted, that when I'm on the new server in the app/current directory I can run the following and it will update my crontab properly:

RAILS_ENV=production bundle exec whenever -w
nulltek
  • 3,247
  • 9
  • 44
  • 94
  • Possible duplicate of http://stackoverflow.com/questions/4950121/whenever-gem-wont-update-crontab-tasks – AJFaraday Sep 22 '14 at 13:30
  • @AJFaraday Possible duplicate, but in my scenario whenever doesn't run at all during the deploy process and gives no error in the Capistrano output. It works on our legacy server but not on our new server. I have to manually run whenever from the command line. No definitive answers to this or the other question yet. – nulltek Sep 22 '14 at 14:51
  • If the issue is that whenever is not run by capistrano, you may want to modify the title of your question to reflect that. – AJFaraday Sep 23 '14 at 08:29
  • I don't really know what your issue will be, but my best guess would be that you should check which user capistrano is running as, and check the crontab for that user. It might be that it's surfacing somewhere you don't expect. – AJFaraday Sep 23 '14 at 08:30
  • I'll edit my title, thanks. Whenever is ran by the deploy user on both servers. And both servers have the deploy user setup with the same permissions and file structure. I'm not sure what it is. All I know is that I can run it manually and it works on the new server, in old production it runs as capistrano is running no problem. – nulltek Sep 23 '14 at 11:46

0 Answers0