kjvarga / sitemap_generator

SitemapGenerator is a framework-agnostic XML Sitemap generator written in Ruby with automatic Rails integration. It supports Video, News, Image, Mobile, PageMap and Alternate Links sitemap extensions and includes Rake tasks for managing your sitemaps, as well as many other great features.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when deploying with Capistrano 3

himadriganguly opened this issue · comments

When trying to deploy with Capistrano 3 (cap production deploy:sitemap:refresh) it gives the following error

DEBUG [b73ccd27] config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
DEBUG [b73ccd27]
DEBUG [b73ccd27] * development - set it to false
DEBUG [b73ccd27] * test - set it to false (unless you use a tool that preloads your test environment)
DEBUG [b73ccd27] * production - set it to true
DEBUG [b73ccd27]
DEBUG [b73ccd27] rake aborted!
DEBUG [b73ccd27] ActiveRecord::AdapterNotSpecified: '' database is not configured. Available: ["default", "production"]
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:257:in resolve_symbol_connection' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:224:inresolve_connection'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:152:in resolve' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:182:inspec'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/connection_handling.rb:50:in establish_connection' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/railtie.rb:129:inblock (2 levels) in class:Railtie'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:38:in instance_eval' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:38:inexecute_hook'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:28:in block in on_load' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:27:ineach'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:27:in on_load' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.0/lib/active_record/railtie.rb:118:inblock in class:Railtie'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/initializable.rb:30:in instance_exec' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/initializable.rb:30:inrun'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/initializable.rb:55:in block in run_initializers' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/initializable.rb:54:inrun_initializers'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/application.rb:288:in initialize!' DEBUG [b73ccd27] /var/www/[APP_NAME]/releases/20140604061057/config/environment.rb:5:in<top (required)>'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in require' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:inblock in require'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in load_dependency' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:inrequire'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/application.rb:264:in require_environment!' DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/railties-4.1.0/lib/rails/application.rb:367:inblock in run_tasks_blocks'
DEBUG [b73ccd27] /var/www/[APP_NAME]/shared/bundle/ruby/2.1.0/gems/sitemap_generator-5.0.4/lib/sitemap_generator/tasks.rb:26:in `block (2 levels) in <top (required)>'
DEBUG [b73ccd27] Tasks: TOP => environment
DEBUG [b73ccd27](See full trace by running task with --trace)

although config.eager_load is set to true in production.rb

The problem appears to be that the environment is not being detected/loaded. As a result, the database is not being configured and so you get this error ActiveRecord::AdapterNotSpecified: '' database is not configured. Available: ["default", "production"].

I've not actually used the Capistrano deploy tasks myself.

Hi buddy thanks for reply.

But the environment is configured as all other work is working fine but only the sitemap is not working. I also added crontab with whenever as instructed in the manual as
every 1.day, :at => '5:00 am', :roles => [:app] do
rake "-s sitemap:refresh"
end
it is added in the crontab but not running

I ran into this issue and think I have a theory about what is going on. I am going to make a fork, attempt the fix, then will report back if it worked. If so, I can do a pull request.

If you take a look here: https://github.com/kjvarga/sitemap_generator/blob/master/lib/capistrano/tasks/sitemap_generator.cap at the cap tasks, it has something like this for all of them:

with rails_env: fetch(:rails_env) do
    execute :rake, "sitemap:create"
end

I took a look at the source code for capistrano that sets the environment, which you can find here:
https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/set_rails_env.rake
which looks something like this:

namespace :deploy do
  task :set_rails_env do
    set :rails_env, (fetch(:rails_env) || fetch(:stage))
  end
end

Specifically, note that it fetches the stage. I think that since capistrano 3 uses stage more than environment (production vs staging ex), that the environment is not setting the produciton mode, but that the stage is suppose to. I am thinking it would be pretty easy to fix those capistrano tasks to read something like this:

with rails_env: (fetch(:rails_env) || fetch(:stage)) do
    execute :rake, "sitemap:create"
end

Tested the proposed fix and it works. I created a pull request with the change.

Thanks! In v5.0.5