I'm trying to deploy a Rails app onto a Digital Ocean Ruby on Rails droplet. I thought it would be all set up to go and I'd just have to configure the app. But it's actually just like a standard Linux server.
I'm using this guide to set up the droplet, but had to tweak a few things to get them running. When I run cap production deploy, I get the following error message:
#<Thread:0x0000555b2f0ec948#/home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
12: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
11: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
10: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
9: from /home/michael/.rvm/gems/ruby-2.6.5/gems/capistrano-passenger-0.2.0/lib/capistrano/tasks/passenger.cap:42:in `block (3 levels) in <top (required)>'
8: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:61:in `test'
7: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
6: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
5: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
4: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
3: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
2: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
1: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/home/michael/.rvm/gems/ruby-2.6.5/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user michael#178.128.223.202 (Net::SSH::AuthenticationFailed)
1: from /home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/michael/.rvm/gems/ruby-2.6.5/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as michael#178.128.223.202: Authentication failed for user michael#178.128.223.202 (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as michael#178.128.223.202: Authentication failed for user michael#178.128.223.202
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user michael#178.128.223.202
Tasks: TOP => rvm:hook => passenger:rvm:hook => passenger:test_which_passenger
(See full trace by running task with --trace)
Here is my deploy.rb file:
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "MyApp"
set :repo_url, "git#github.com:MyAccount/MyApp.git"
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/michael/my-app/#{fetch :application}"
# Default value for linked_dirs is []
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system", "public/uploads", "vendor/bundle", ".bundle"
# Default value for keep_releases is 5
set :keep_releases, 5
And the deploy/production.rb file:
server "123.456.789.123", user: "me", roles: %w{app db web}
set :ssh_options, {
config: false,
keys: %w[/home/myhome/.ssh/id_ed25519],
forward_agent: true,
auth_methods: %w[publickey],
user: 'me'
}
Any help here would be good. All the other answers I've seen so far haven't fixed the problem for me (and none have had Tasks: TOP => rvm:hook => passenger:rvm:hook => passenger:test_which_passenger)
Related
Solution:
Added the following to the bottom of deploy.rb
Rake::Task["deploy:assets:restore_manifest"].clear_actions
before 'deploy:finishing_rollback', 'deploy:pre_start_precompile'
task :pre_start_precompile do
on roles(:db) do
with rails_env: "#{fetch(:stage)}" do
path_to_bundler = "/usr/local/rbenv/shims/bundle"
execute "cd #{release_path}; RAILS_ENV=production #{path_to_bundler} exec rake assets:precompile"
end
end
end
This worked!
Original question:
I'm running Rails 4.2 and Ruby 2.5.8 and capistrano 3.14.1. When I try and roll back I get this error;
** Execute bundler:install
00:04 bundler:install
The Gemfile's dependencies are satisfied, skipping installation
** Execute deploy:reverted
** Invoke deploy:rollback_assets (first_time)
** Invoke deploy:set_rails_env
** Execute deploy:rollback_assets
** Invoke deploy:assets:restore_manifest (first_time)
** Execute deploy:assets:restore_manifest
00:04 deploy:assets:restore_manifest
WARN Rails assets manifest file (or backup file) not found.
#<Thread:0x00007ff7f8218548#/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user#<server ip>: Rails assets manifest file (or backup file) not found. (SSHKit::Runner::ExecuteError)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as <user>#<server ip>: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
Caused by:
Capistrano::FileNotFound: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:103:in `block (5 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:92:in `within'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:90:in `block (4 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:assets:restore_manifest
I read somewhere that I have to make two files on the production server which I have and it didn't make a difference;
$ touch public/assets/.manifest.json
$ touch public/assets/.sprockets-manifest.json
The error happens within assets.rake part of capistrano-rails;
task :restore_manifest do
on release_roles(fetch(:assets_roles)) do
within release_path do
targets = detect_manifest_path.split(' ')
sources = targets.map do |target|
release_path.join('assets_manifest_backup', File.basename(target))
end
if test(:ls, *sources) && test(:ls, *targets) # <-- this line
source_map = sources.zip(targets)
source_map.each do |source, target|
execute :cp, source, target
end
else
msg = 'Rails assets manifest file (or backup file) not found.'
warn msg
fail Capistrano::FileNotFound, msg
end
end
end
end
I manually tested sources and targets. I found sources failed and targets passed. Below are both;
(byebug) sources
[#<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest-2df820954d56273c97d9696e88075409.json>, #<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest.json>]
(byebug) targets
["/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json", "/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest.json"]
Update: listing of shared/public
[capistrano root]/shared/public$ find .
.
./system
./assets
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css.gz
./assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js.gz
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js.gz
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css
./assets/.manifest.json
./assets/.sprockets-manifest.json
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css.gz
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css.gz
I have spent the last week trying to set up the following config:
VPS with clean Centos 7 install.
Ruby on Rails which runs Redmine, all to read out a back-up of the redmine database made with bacula.
Now mind you, I come from a Graphical design/Microsoft/Hardware engineering background and am now currently transitioning so I'm still very unfamiliar with most of the stack used at my current employer as I have only been working there for a couple of weeks.
Setting up the VPS and installing Centos7 is easy enough, I then proceed with installing rbenv/httpd/bundler/rmagick/all the gems and restore the redmine back-up (back-up from the entire install).
Now I want to run a rake db:migrate command (just following the wiki's from redmine and digital ocean) and this happens:
[user#machinename redmine]$ rake db:migrate
rake aborted!
ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["production"]
/opt/redmine-3.1.0/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `eval'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `each'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
[user#machinename redmine]$
If I then inspect lets say 00-core_plugins.rb I can't seem to find what is wrong.
# Loads the core plugins located in lib/plugins
Dir.glob(File.join(Rails.root, "lib/plugins/*")).sort.each do |directory|
if File.directory?(directory)
lib = File.join(directory, "lib")
if File.directory?(lib)
$:.unshift lib
ActiveSupport::Dependencies.autoload_paths += [lib]
end
initializer = File.join(directory, "init.rb")
if File.file?(initializer)
config = RedmineApp::Application.config
eval(File.read(initializer), binding, initializer)
end
end
end
If anyone could offer some help/insight to what it is I am doing wrong it would be greatly appreciated.
A standalone installer which sets up redmine and all dependencies is also good as I actually only have to be able to import the back-up of the DB in to redmine.
Full --trace:
[user#machinename redmine]$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["production"]
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:211:in `resolve_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_handling.rb:50:in `establish_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/base.rb:26:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/opt/redmine-3.1.0/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `eval'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `each'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:652:in `block in load_config_initializer'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:651:in `load_config_initializer'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:615:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:615:in `block in <class:Engine>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:415:in `call'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `call'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:328:in `require_environment!'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/rake:22:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/rake:22:in `<main>'
Tasks: TOP => db:migrate => environment
Database.yml:
# Default setup is given for MySQL with ruby1.9.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "therightpassword_icheckeditadozentimes"
encoding: utf8
development:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "therightpassword_icheckeditadozentimes"
encoding: utf8
# PostgreSQL configuration example
#production:
# adapter: postgresql
# database: redmine
# host: localhost
# username: postgres
# password: "postgres"
# SQLite3 configuration example
#production:
# adapter: sqlite3
# database: db/redmine.sqlite3
# SQL Server configuration example
#production:
# adapter: sqlserver
# database: redmine
# host: localhost
# username: jenkins
# password: jenkins
Configuration.yml
# = Redmine configuration file
#
# Each environment has it's own configuration options. If you are only
# running in production, only the production block needs to be configured.
# Environment specific configuration options override the default ones.
#
# Note that this file needs to be a valid YAML file.
# DO NOT USE TABS! Use 2 spaces instead of tabs for identation.
# default configuration options for all environments
default:
# Outgoing emails configuration
# See the examples below and the Rails guide for more configuration options:
# http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
email_delivery:
delivery_method: :smtp
smtp_settings:
enable_starttls_auto: true
#ssl: true
address: smtp.gmail.com
port: "587"
domain: "site.tld"
authentication: :plain
user_name: "ticketing#site.tld"
password: "god our security is atrocious"
# ==== Simple SMTP server at localhost
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# address: "localhost"
# port: 25
#
# ==== SMTP server at example.com using LOGIN authentication and checking HELO for foo.com
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# address: "example.com"
# port: 25
# authentication: :login
# domain: 'foo.com'
# user_name: 'myaccount'
# password: 'password'
#
# ==== SMTP server at example.com using PLAIN authentication
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
configuration.yml # address: "example.com"
# port: 25
# authentication: :plain
# domain: 'example.com'
# user_name: 'myaccount'
# password: 'password'
#
# ==== SMTP server at using TLS (GMail)
# This might require some additional configuration. See the guides at:
# http://www.redmine.org/projects/redmine/wiki/EmailConfiguration
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# enable_starttls_auto: true
# address: "smtp.gmail.com"
# port: 587
# domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
# authentication: :plain
# user_name: "your_email#gmail.com"
# password: "your_password"
#
# ==== Sendmail command
#
# email_delivery:
# delivery_method: :sendmail
# Absolute path to the directory where attachments are stored.
# The default is the 'files' directory in your Redmine instance.
# Your Redmine instance needs to have write permission on this
# directory.
# Examples:
# attachments_storage_path: /var/redmine/files
# attachments_storage_path: D:/redmine/files
attachments_storage_path:
# Configuration of the autologin cookie.
# autologin_cookie_name: the name of the cookie (default: autologin)
# autologin_cookie_path: the cookie path (default: /)
# autologin_cookie_secure: true sets the cookie secure flag (default: false)
autologin_cookie_name:
autologin_cookie_path:
autologin_cookie_secure:
# Configuration of SCM executable command.
#
# Absolute path (e.g. /usr/local/bin/hg) or command name (e.g. hg.exe, bzr.exe)
# On Windows + CRuby, *.cmd, *.bat (e.g. hg.cmd, bzr.bat) does not work.
#
# On Windows + JRuby 1.6.2, path which contains spaces does not work.
# For example, "C:\Program Files\TortoiseHg\hg.exe".
# If you want to this feature, you need to install to the path which does not contains spaces.
# For example, "C:\TortoiseHg\hg.exe".
#
# Examples:
# scm_subversion_command: svn # (default: svn)
# scm_mercurial_command: C:\Program Files\TortoiseHg\hg.exe # (default: hg)
# scm_git_command: /usr/local/bin/git # (default: git)
# scm_cvs_command: cvs # (default: cvs)
# scm_bazaar_command: bzr.exe # (default: bzr)
# scm_darcs_command: darcs-1.0.9-i386-linux # (default: darcs)
#
scm_subversion_command:
scm_mercurial_command:
scm_git_command:
scm_cvs_command:
scm_bazaar_command:
scm_darcs_command:
# SCM paths validation.
#
# You can configure a regular expression for each SCM that will be used to
# validate the path of new repositories (eg. path entered by users with the
# "Manage repositories" permission and path returned by reposman.rb).
# The regexp will be wrapped with \A \z, so it must match the whole path.
# And the regexp is case sensitive.
#
# You can match the project identifier by using %project% in the regexp.
#
# You can also set a custom hint message for each SCM that will be displayed
# on the repository form instead of the default one.
#
# Examples:
# scm_subversion_path_regexp: file:///svnpath/[a-z0-9_]+
# scm_subversion_path_info: SVN URL (eg. file:///svnpath/foo)
#
# scm_git_path_regexp: /gitpath/%project%(\.[a-z0-9_])?/
#
scm_subversion_path_regexp:
scm_mercurial_path_regexp:
scm_git_path_regexp:
scm_cvs_path_regexp:
scm_bazaar_path_regexp:
scm_darcs_path_regexp:
scm_filesystem_path_regexp:
# Absolute path to the SCM commands errors (stderr) log file.
# The default is to log in the 'log' directory of your Redmine instance.
# Example:
# scm_stderr_log_file: /var/log/redmine_scm_stderr.log
scm_stderr_log_file:
# Key used to encrypt sensitive data in the database (SCM and LDAP passwords).
# If you don't want to enable data encryption, just leave it blank.
# WARNING: losing/changing this key will make encrypted data unreadable.
#
# If you want to encrypt existing passwords in your database:
# * set the cipher key here in your configuration file
# * encrypt data using 'rake db:encrypt RAILS_ENV=production'
#
# If you have encrypted data and want to change this key, you have to:
# * decrypt data using 'rake db:decrypt RAILS_ENV=production' first
# * change the cipher key here in your configuration file
# * encrypt data using 'rake db:encrypt RAILS_ENV=production'
database_cipher_key:
# Set this to false to disable plugins' assets mirroring on startup.
# You can use `rake redmine:plugins:assets` to manually mirror assets
# to public/plugin_assets when you install/upgrade a Redmine plugin.
#
#mirror_plugins_assets_on_startup: false
# Your secret key for verifying cookie session data integrity. If you
# change this key, all old sessions will become invalid! Make sure the
# secret is at least 30 characters and all random, no regular words or
# you'll be exposed to dictionary attacks.
#
# If you have a load-balancing Redmine cluster, you have to use the
# same secret token on each machine.
#secret_token: 'change it to a long random string'
secret_token: 'rake output I generated before and copy-pasta'ed'
# Requires users to re-enter their password for sensitive actions (editing
# of account data, project memberships, application settings, user, group,
# role, auth source management and project deletion). Disabled by default.
# Timeout is set in minutes.
#
#sudo_mode: true
#sudo_mode_timeout: 15
# Absolute path (e.g. /usr/bin/convert, c:/im/convert.exe) to
# the ImageMagick's `convert` binary. Used to generate attachment thumbnails.
#imagemagick_convert_command:
# Configuration of RMagcik font.
#
# Redmine uses RMagcik in order to export gantt png.
# You don't need this setting if you don't install RMagcik.
#
# In CJK (Chinese, Japanese and Korean),
# in order to show CJK characters correctly,
pt/redmine-3.1.0/log/"
# you need to set this configuration.
#
# Because there is no standard font across platforms in CJK,
# you need to set a font installed in your server.
#
# This setting is not necessary in non CJK.
#
# Examples for Japanese:
# Windows:
# rmagick_font_path: C:\windows\fonts\msgothic.ttc
# Linux:
# rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf
#
rmagick_font_path:
# Maximum number of simultaneous AJAX uploads
#max_concurrent_ajax_uploads: 2
"/opt/redmine-3.1.0/log/"
# Configure OpenIdAuthentication.store
#
# allowed values: :memory, :file, :memcache
#openid_authentication_store: :memory
# specific configuration options for production environment
# that overrides the default ones
production:
# specific configuration options for development environment
# that overrides the default ones
development:"/opt/redmine-3.1.0/log/"
Thanks to Deepak's suggestion I added a "development" section in my database.yml but now I am getting this error:
[user#machinename redmine]$ rake db:migrate
rake aborted!
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 52 column 3
/opt/redmine-3.1.0/lib/redmine/configuration.rb:86:in `load_from_yaml'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:42:in `load'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:67:in `[]'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:24:in `<module:Thumbnail>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:21:in `<module:Redmine>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:20:in `<top (required)>'
/opt/redmine-3.1.0/lib/redmine.rb:47:in `<top (required)>'
/opt/redmine-3.1.0/config/initializers/30-redmine.rb:6:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Output from #lightalloy's suggestion:
[user#machinename redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 52 column 3
/opt/redmine-3.1.0/lib/redmine/configuration.rb:86:in `load_from_yaml'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:42:in `load'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:67:in `[]'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:24:in `<module:Thumbnail>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:21:in `<module:Redmine>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:20:in `<top (required)>'
/opt/redmine-3.1.0/lib/redmine.rb:47:in `<top (required)>'
/opt/redmine-3.1.0/config/initializers/30-redmine.rb:6:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/bundle:22:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/bundle:22:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I assume that you need to set up the production environment by your database.yml
So you need to specify it when you run rake db:migrate:
bundle exec rake db:migrate RAILS_ENV=production
Make sure you have the configuration for development env in config/database.yml
If not please add the following entry in config/database.yml
# MYSQL
development:
adapter: mysql2
database: development_db
host: localhost
username: username
password: password
encoding: utf8
# # SQLite
# development:
# adapter: sqlite3
# database: db/development.sqlite3
# pool: 5
# timeout: 5000
# # Postgres
# development:
# adapter: postgresql
# encoding: unicode
# database: development_db
# pool: 5
# username: username
# password: password
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'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've been trying to upgrade from Capistrano 2 to Capistrano 3, but have been working through all the errors. I'm stuck on one that I don't know how to solve now. I'm using Unicorn and Nginx.
Error trace:
cap production deploy:cold --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Task Argument Error
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:96:in `resolve_args_with_dependencies'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:62:in `resolve_args'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:24:in `define_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:360:in `define_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/dsl_definition.rb:32:in `task'
config/deploy.rb:31:in `block (2 levels) in <top (required)>'
config/deploy.rb:29:in `each'
config/deploy.rb:29:in `block in <top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:196:in `in_namespace'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/dsl_definition.rb:104:in `namespace'
config/deploy.rb:28:in `<top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:12:in `load'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:12:in `block (2 levels) in <top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in `run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/bin/cap:23:in `load'
/Users/devanb/.rbenv/versions/2.0.0-p247/bin/cap:23:in `<main>'
Tasks: TOP => production
Deploy file:
set :application, 'liveinbham'
set :user, 'deployer'
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :scm, "git"
set :repo_url, 'git#github.com:DevanB/LIveInBham.git'
set :use_sudo, false
set :scm_verbose, true
set :git_shallow_clone, 1
set :git_enable_submodules, 1
set :ssh_options, { :forward_agent => true }
set :stage, :production
set :rails_env, "production"
set :branch, "master"
set :pty, true
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
namespace :deploy do
%w{start stop restart}.each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{fetch(:application)}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{fetch(:application)}"
end
after "deploy:setup", "deploy:setup_config"
after :finishing, 'deploy:cleanup'
end
desc "tail log files"
task :tail, :roles => :app do
run "tail -f /home/#{fetch(:user)}/apps/#{fetch(:application)}/current/log/production.log" do |channel, stream, data|
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{fetch(:user)} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{fetch(:rails_env)}'"
end
Could be a few things but deploy:cold is depreciated in Capistrano 3, I've just tried it and I just get "don't know how to build task" which is what I'd expect. Potentially running deploy:setup_config and then just a straight up deploy may work.
There's a few other things which will need tweaking like you can no longer use that approach for streaming log files, it's just a simple execute instead. E.g.:
namespace :logs do
desc "tail rails logs"
task :tail_rails do
on roles(:app) do
execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log"
end
end
end
In general the task definition format also needs updating, e.g:
task :setup_config, roles: :app do
# some stuff
end
would become
task :setup_config do
on roles(:app) do
#some stuff
end
end
It looks like your Cap 2 configuration is based quite heavily on the Railscast about it. Mine also was and I recently went through the process of migrating all the apps using it to a new Cap 3 one. I've documented the approach I ended up with here including the code.
The stack trace makes it pretty clear. The error comes from line 31 of your file, where you try to define a task using the old Capistrano 2 syntax. The new Capistrano 3 uses Rake, so you must use Rake syntax to define tasks, with the aid of some Capistrano methods. Rake does not recognize "roles" and "except". TalkingQuickly gave a good-looking example of the new way to define tasks.