On Rails 6 app I had Rails.application.credentials in cap deploy.rb file. Now, when I try to deploy the new app with Rails 7 I'm getting
# bin/bundle exec cap production deploy --trace
NameError: uninitialized constant Rails
set :repo_url, Rails.application.credentials.git[:repo_url]
^^^^^
config/deploy.rb:5:in `<top (required)>'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/setup.rb:27:in `load'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capistrano-3.17.1/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/home/agasanov/.rbenv/versions/3.1.3/lib/ruby/3.1.0/delegate.rb:87:in `method_missing'
^^^^^
Is this because autoloading from initializers have been removed from Rails 7?
Here is my deploy.rb
lock "~> 3.17.1"
set :application, "my app"
set :repo_url, Rails.application.credentials.git[:repo_url]
set :deploy_to, "/home/myapp/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
There's an old issue here that suggests that Capistrano might raise this error if your deployment sees the Rails constant anywhere at deploy time (in the case of that issue, in config/database.yml, but if what it says is true the same would apply to deploy.rb).
That doesn't explain why it might have changed from Rails 6 to 7 though. Was your deploy.rb referring to Rails.application before you migrated?
Related
I've been at this for about 16 hours and throwing in the towel. I've successfully deployed an rails app with capistrano before and I copied everything initially, but I can't get past assets:precompile. Migration doesn't work either, but one thing at the time.
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require "capistrano/rbenv"
#require "capistrano/bundler"
require "capistrano/rails"
#require "capistrano/rails/assets"
#require "capistrano/rails/migrations"
require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
config/deploy.rb
set :application, 'livelyteams'
set :repo_url, 'https://github.com/unusualslim/livelyteams'
set :puma_threads, [4,16]
set :puma_workers, 0
set :rbenv_ruby, '2.6.5'
set :rails_env, 'production'
append :linked_files, "config/master.key"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# append :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/dev/apps/livelyteams'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, File.read('.ruby-version').strip
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :default_env, {
PATH: '$HOME/.npm-packages/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
desc 'Run rake yarn:install'
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install")
end
end
end
end
namespace :deploy do
namespace :check do
before :linked_files, :set_master_key do
on roles(:app), in: :sequence, wait: 10 do
unless test("[ -f #{shared_path}/config/master.key ]")
upload! 'config/master.key', "#{shared_path}/config/master.key"
end
end
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app) do
execute "#{fetch(:rbenv_prefix)} pumactl -P ~/app/current/tmp/pids/puma.pid phased-restart"
end
end
end
after 'deploy:publishing', 'deploy:restart'
config/deploy/production.rb
set :stage, :production
set :branch, "master"
server 'livelyteams.com', user: "dev", port: 22, roles: %w{app db web}, primary: true
I think it's related to RAILS_ENV=production, but I've tried everything I could think of.
and the capistrano.log
DEBUG [b2a3647b] Command: cd /home/dev/apps/livelyteams/releases/20200918213106 && yarn install
DEBUG [b2a3647b] yarn install v1.21.1
DEBUG [b2a3647b] info No lockfile found.
DEBUG [b2a3647b] [1/4] Resolving packages...
DEBUG [b2a3647b] [2/4] Fetching packages...
DEBUG [b2a3647b] [3/4] Linking dependencies...
DEBUG [b2a3647b] [4/4] Building fresh packages...
DEBUG [b2a3647b] success Saved lockfile.
DEBUG [b2a3647b] Done in 0.15s.
INFO [b2a3647b] Finished in 0.592 seconds with exit status 0 (successful).
DEBUG [d8f59b17] Running if test ! -d /home/dev/apps/livelyteams/releases/20200918213106; then echo "Directory does not exist '/home/dev/apps/livelyteams/releases/20200918213106'" 1>&2; false; fi as dev#livelyteams.com
DEBUG [d8f59b17] Command: if test ! -d /home/dev/apps/livelyteams/releases/20200918213106; then echo "Directory does not exist '/home/dev/apps/livelyteams/releases/20200918213106'" 1>&2; false; fi
DEBUG [d8f59b17] Finished in 0.042 seconds with exit status 0 (successful).
INFO [cbdabd40] Running RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as dev#livelyteams.com
DEBUG [cbdabd40] Command: cd /home/dev/apps/livelyteams/releases/20200918213106 && ( export PATH="$HOME/.npm-packages/bin/:$PATH" NODE_ENVIRONMENT="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.5" RAILS_ENV="production" RAILS_GROUPS="" ; RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG [cbdabd40] rake aborted!
DEBUG [cbdabd40] ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
DEBUG [cbdabd40] /home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:183:in `_decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:79:in `decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:42:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:21:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:33:in `config'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:38:in `options'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:10:in `find'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `instance_exec'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `run'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:60:in `run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:361:in `initialize!'
/home/dev/apps/livelyteams/releases/20200918213106/config/environment.rb:5:in `<main>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:337:in `require_environment!'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
DEBUG [cbdabd40]
Caused by:
DEBUG [cbdabd40] OpenSSL::Cipher::CipherError:
DEBUG [cbdabd40] /home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:201:in `final'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:201:in `_decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:79:in `decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:42:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:21:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:33:in `config'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:38:in `options'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:10:in `find'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `instance_exec'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `run'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:60:in `run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:361:in `initialize!'
/home/dev/apps/livelyteams/releases/20200918213106/config/environment.rb:5:in `<main>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:337:in `require_environment!'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
DEBUG [cbdabd40] Tasks: TOP => environment
DEBUG [cbdabd40] (See full trace by running task with --trace)
Rails is complaining about your config/master.key file. First (back them up, just in case) rm config/credentials.yml.enc and rm config/master.key then try running bundle exec rails credentials:edit.
My solution ended up being to destroy the current production server and create and new one. Now my project deploys via capistrano like it should.
I'm trying to upgrade some of my Ruby on Rails projects from Capistrano 2.x to Capistrano 3.x.
I followed this great tutorial to setup configuration files. My configuration files looks like this:
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
deploy.rb
lock '3.4.0'
set :scm, :git
set :deploy_user, "deploy"
set :repo_url, "git_url"
set :application, "app_name"
set :local_app, "193/#{application}"
set :deploy_to, "/home/#{deploy_user}/rails/#{application}"
set :pty, true
set :ssh_options, {:forward_agent => true}
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
###
# BBDD settings
#
set :db_passwd, "db_password"
set :db_name, "db_name_production"
deploy/production.rb
set :stage, :production
set :rails_env, :production
set :server_ip, "xxx.xxx.xxx.xxx"
server server_ip, user: 'deploy', roles: %w{web app db}
role :app, server_ip
role :web, server_ip
role :db, server_ip, :primary => true
Now, when I try to show my Capistrano tasks or when I try to deploy my project, Capistrano throws me an error.
(Backtrace restricted to imported tasks) cap aborted! NoMethodError:
undefined method `map' for :roles:Symbol
(See full trace by running task with --trace)
I spent one day Googling with no results. Any idea?
EDIT
cap production deploy:setup --trace
cap aborted!
NoMethodError: undefined method `map' for :roles:Symbol
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/task.rb:309:in `set_arg_names'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/task_manager.rb:40:in `define_task'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/task.rb:365:in `define_task'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/dsl_definition.rb:66:in `task'
/Users/carro/Sites/193/capistrano/lib/capistrano/tasks/deploy.rake:4:in `block in <top (required)>'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/task_manager.rb:209:in `in_namespace'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/dsl_definition.rb:147:in `namespace'
/Users/carro/Sites/193/capistrano/lib/capistrano/tasks/deploy.rake:1:in `<top (required)>'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/default_loader.rb:10:in `load'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:767:in `load_imports'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/capistrano-3.4.0/lib/capistrano/application.rb:93:in `load_imports'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:697:in `raw_load_rakefile'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:77:in `block in run'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/capistrano-3.4.0/lib/capistrano/application.rb:15:in `run'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/gems/capistrano-3.4.0/bin/cap:3:in `<top (required)>'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/bin/cap:23:in `load'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/bin/cap:23:in `<main>'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/carro/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
This is happening because Capistrano tasks are now Rake tasks and Rake expects a construct like this:
task :name, [:arg, :arg] => :dependency do
...
end
Judging from your stack trace you have custom Capistrano tasks defined in /Users/carro/Sites/193/capistrano/lib/capistrano/tasks/. You need to convert those to the Capistrano 3 on ... roles syntax to make them work.
For example, you would change a Capistrano 2 task like this:
task :dump, :roles => :db do
...
end
to this for Capistrano 3:
task :dump do
on primary roles :db do
...
end
end
See here for more details.
I have been deploying rails 4.1 application with capistrano 3. it has been working fine. but
when i tried to do rake tasks (uncommenting require 'capistrano/rails/assets'). i get this error
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
ArgumentError: Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:261:in `handle_settings'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:98:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/storage.rb:26:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:8:in `block in <top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:5:in `<top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
the config.eager_load is set to true. the thing with google_storage_access_key_id the keys are initialized inside a initializer with values config.secrets.yml
require 'fog'
require 'rails'
require 'carrierwave'
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'Google',
:google_storage_access_key_id => Rails.application.secrets.storage_access_key,
:google_storage_secret_access_key => Rails.application.secrets.storage_access_secret
}
config.fog_directory = 'yelostore'
end
config.secrets.yml
storage_access_key: <%= ENV['STORAGE_ACCESS_KEY']%>
storage_access_secret: <%= ENV['STORAGE_ACCESS_SECRET']%>
i stored my environmental variables in /etc/profile.
there issues arise only if i do some rake or execute tasks.
if i removed the initializer file i get another error
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '6b88a299ed1361b5c0275e.....'
this is essentiall because of secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> not getting loaded at that point.
Finally i can run all tasks i go to the root path. only while doing it through capistarno these errors arise. as capistarno not getting the config.scecrets env variables which is stored in /etc/profile
capistrano seems like to look into environmental variables from /etc/environment rather than shell so bashrc or profile didnt't work.
The config.eager_load issue was solved after i upgraded to capistrano 3.0rc to 3.2
The Error has nothing to do with the secret_key_base.
In the file config/initializers/devise.rb add the config.secret_key='6b88...' within the setup block:
Devise.setup do |config|
config.secret_key = '6b88a299ed1361b5c0275e...'
...
end
I'm using capistrano and the whenever gem.
Capistrano deploys and updates the crontab on our ubuntu server with the cronjob detailed out in our schedule.rb file.
But the cronjob doesn't happen. It fails and emails me every 5 minutes this error:
/etc/profile.d/rvm.sh: line 67: __rvm_add_to_path: command not found
/home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /[REMOVED]/releases/20140204194143/config/boot.rb:6:in `<top (required)>'
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/rails:4:in `<main>'
The weird part is we're deploying with a different username than pkatepalli. pkatepalli is my username on the server. That explains why it's emailing me the error - I think.
Also, we're using ruby 1.9.3 not 1.9.1. I'm not sure why it's not using the right ruby version.
On server:
Bundler version 1.3.5
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
$ rbenv version
1.9.3-p448 (set by /[REMOVED]/current/.ruby-version)
But interestingly enough in the current directory there's ruby 1.9.1, which I'm confused by:
/current/vendor/bundle/ruby/1.9.1
gemfile:
gem 'whenever', require: false
schedule.rb:
I've tried uncommenting: env 'PATH', ENV['PATH'], but the PATH that gets put into the schedule.rb file doesn't help.
Locally we're using RVM instead of rbenv (which is being used on the server). I'm not sure if that screws up the path if we set: env 'PATH', ENV['PATH']
#env 'PATH', ENV['PATH']
#set :output, "/log/cron.log"
#set :stage, :environment_variable
every 5.minutes, :roles => [:app] do
runner "Model.method"
end
deploy.rb:
require 'capistrano/log_with_awesome'
require "bundler/capistrano"
set :application, "[REMOVED]"
set :scm, :git
set :repository, "[REMOVED]"
set :branch, "master"
set :deploy_via, :remote_cache
set :user, "[REMOVED]"
set :password, "[REMOVED]"
set :deploy_to, "[REMOVED]"
set :keep_releases, 5
task :qa do
set :domain, "[REMOVED]"
role :web, "[REMOVED]", {:port => [REMOVED]} # Your HTTP server, Nginx
role :app, "[REMOVED]", {:port => [REMOVED]} # This may be the same as your `Web` server
set :env, "test"
end
task :production do
set :domain, "[REMOVED]"
role :web, "[REMOVED]", {:port => [REMOVED]} # Your HTTP server, Nginx
role :app, "[REMOVED]", {:port => [REMOVED]} # This may be the same as your `Web` server
set :env, "production"
end
set :use_sudo, false
default_run_options[:pty] = true
role :db, "[REMOVED]", {:port => [REMOVED], primary: true, :no_release => true}
after "deploy:setup", "deploy:chown"
namespace :bundle do
task :install, {:roles => :app} do
run "cd #{release_path} && bundle install --deployment --without development test"
end
end
before "deploy:assets:precompile" do
transfer :up, "config/application.yml", "#{shared_path}/application.yml", :via => :scp
run "ln -nfs #{shared_path}/application.yml #{release_path}/config/application.yml"
end
namespace :whenever do
task :start, :roles => :app do
run "cd #{release_path} && bundle exec whenever --update-crontab"
end
end
namespace :deploy do
task :execute_migrations, :roles => :app do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; bundle exec rake RAILS_ENV=#{env} db:migrate"
end
task :chown do
run "#{try_sudo} chown -R #{user} #{deploy_to}"
end
task :restart_nginx, {:roles => :web} do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
before "deploy:restart_nginx", "deploy:execute_migrations"
after :deploy, "deploy:restart_nginx"
after "deploy:restart_nginx", "deploy:cleanup"
after "deploy:update", "whenever:start"
end
When I ssh into the server and run crontab -l in the app's current directory:
# Begin Whenever generated tasks for: /[REMOVED]/releases/20140204194143/config/schedule.rb
#0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /[REMOVED]/releases/20140204194143 && script/rails runner -e production '\''Model.method'\'''
# End Whenever generated tasks for: [REMOVED]/releases/20140204194143/config/schedule.rb
When I run the cron job on the server like this I get this result:
:/[REMOVED]/current$ rails runner -e production '\''Model.method'\'''
Rails Error: Unable to access log file. Please ensure that /[REMOVED]/releases/20140204194143/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval': (eval):1: syntax error, unexpected $undefined (SyntaxError)
\Model.method'
^
(eval):1: unterminated string meets end of file
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
When I do it like this. I get this:
[REMOVED]/current$ rails runner Model.method
Rails Error: Unable to access log file. Please ensure that [REMOVED]/releases/20140204194143/log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
[REMOVED]/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" ([REMOVED]) and accepting
TCP/IP connections on port 5432?
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:418:in `_run__249672195884464632__prepare__2220886522034318467__callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /[REMOVED]/releases/20140204194143/config/environment.rb:5:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:44:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
In response to Leonid Shevtsov's answer:
I ran:
rails runner -e production 'Model.method'
and I got this:
[REMOVED]/current$ rails runner -e production 'Model.methodName'
/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval': undefined method `methodName' for #<Class:0x0000000570d668> (NoMethodError)
from (eval):1:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
when I run crontab -l, I get the whenever generated crons
a) 1.9.1 is the "base" version of Ruby 1.9.3 (1.9.3 is considered to be a version of Ruby 1.9.1); it's normal that you see it in the paths.
b) the command line in cron is escaping quotes; the proper way to check it manually is rails runner -e production 'Model.method'
c) are you sure the error isn't arriving from a locally installed cron job? (check with crontab -l)
Ok this is kind of complicated and some debugging info is missing so I will try to take a guess.
First of all it seems that you have both rvm and rbenv installed on your system which is not a very good idea. Try uninstalling one of the two, or better yet uninstall both and reinstall the one you prefer.
In your deploy script it seems you have rolled your own whenever capistrano tasks. This is not bad, but whenever already provides this out of the box with better support (e.g. rollbacks). You can also get better feedback on your future problems.
Those are potential pitfalls but their are not probably the cause of your problems. You seem to have messed things up regarding the linux users and their permissions. As far as I understand there are two users on your production system: pkatepalli and another one which you commented out, lets call him deployer.
From what I see you are trying to set everything up to work from the perspective of deployer which is a good practice.
I assume the capistrano user variable is set to deployer. If not this is the root of your problem. This is the user which capistrano uses to log in and issue your commands.
Also it seems that when you run crontab -l you see the cron jobs correctly but if you are logged in with pkatepalli when you run the command then this is your problem. You have written your tasks to the wrong user's crontab. If this has happened it more likely means either that you run the whenever command from the wrong user during cap deploy (in which case you need to check which is the logged in user during cap) or you have actually run the whenever command from both users and you are only getting errors for pkatepalli (clear your crontab before experimenting again). If it still looks it is ok then you can try passing the -u username option to whenever command (you probably need sudo for this).
To set up the deployer user properly you can follow the instructions by capistrano
I am deploying to Ubuntu with Capistrano.
I have God + Resque set up for background process.
App runs fine and Resque workers are going to their queues, but are stuck there. When I looked into logs, I found out that it's Rake failing. Here is the trace:
FIRST THERE IS ABOUT 1000 OF THE BELOW LINE
/home/ubuntu/myapp/releases/20120724024732/config/application.rb:68:in `invoke'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p125#global/bin/rake:19:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p125#global/bin/rake:19:in `<main>'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
/home/ubuntu/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
rake aborted!
Too many open files - rake_tasks_log.log
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open-uri.rb:35:in `initialize'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open-uri.rb:35:in `open'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open-uri.rb:35:in `open'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/logger.rb:592:in `open_logfile'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/logger.rb:549:in `initialize'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/logger.rb:314:in `new'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/logger.rb:314:in `initialize'
/home/ubuntu/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/core_ext/logger.rb:72:in `initialize'
Here is the function from application.rb line 68 is marked with comment:
module Rake
class Task
alias_method :origin_invoke, :invoke if method_defined?(:invoke)
def invoke(*args)
logger = Logger.new('rake_tasks_log.log')
logger.info "#{Time.now} -- #{name} -- #{args.inspect}"
puts args
origin_invoke(args) ### LINE 68
end
end
end
**EDIT:: Here is a clue, but don't know what to do with it:: Apparently the *args that are being passed is an empty array...
Here is my deploy.rb
require "bundler/capistrano"
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :rvm_type, :user
# -*- encoding : utf-8 -*-
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \
specify additional environment variables to pass to rake via the \
asset_env variable. The defaults are:
set :rake, "rake"
set :rails_env, "production"
set :asset_env, "RAILS_GROUPS=assets"
set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
DESC
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} #{assets_dependencies.join ' '} | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
set :application, "myapp"
set :repository, "git#github.com:..."
set :scm, :git
set :git_shallow_clone, 1
set :branch, "master"
set :location, "ec2-....amazonaws.com"
role :app, location
role :web, location
role :db, location, :primary => true
set :deploy_via, :remote_cache
set :user, "ubuntu"
set :use_sudo, false
set :deploy_to, "/home/ubuntu/myapp"
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
ssh_options[:keys] = ["#{ENV['HOME']}/...pem"]
set :keep_releases, 1
# setup some Capistrano roles
role :app, location
role :web, location
role :db, location, :primary => true
set :default_environment, {
'PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p125/bin:/home/ubuntu/.rvm/gems/ruby-1.9.3-p125#global/bin:/home/ubuntu/.rvm/rubies/ruby-1.9.3-p194/bin:/home/ubuntu/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/lib/pkgconfig:/usr/lib/jvm/java-1.6.0-openjdk-amd64:/usr/lib/jvm/java-6-openjdk-amd64:$PATH",
'JAVA_HOME' => "/usr/lib/jvm/java-6-openjdk-amd64",
'PKG_CONFIG_PATH' => '$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig'
}
desc "show path"
task :show_path do
run "echo $PATH"
end
###PASSENGER:
namespace :passenger do
desc "Restart Application"
task :restart do
run 'sudo /etc/init.d/nginx stop'
run 'sudo /etc/init.d/nginx start'
end
end
after :deploy, "passenger:restart"
after :deploy, "deploy:migrate"
Last note - everything works fine if I don't use Capistrano (e.g. just copy Rails app folder to server).. so I guess I am missing something on Capistrano side..
So it turns out that my redis folder had permissions problem and could not write to the database. So I checked where the database file is being saved (or rather not saved in my case) and did sudo chown redis:redis now all is good.