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.
Related
I'm trying to deploy my Ruby app using capistrano (repository is on gitlab) and I get this error:
>> cap production deploy
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Net::SSH::AuthenticationFailed: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer>
My ~/.ssh/config:
Host gitlab.com
IdentityFile ~/.ssh/id_rsa
User git
PreferredAuthentications publickey
ForwardAgent yes
My deploy.rb:
set :branch, ENV['BRANCH'] || 'master'
set :application, 'example'
set :repo_url, 'ssh://git#gitlab.com/xxxx/xxxxxxxxx.git'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'
set :deploy_to, '/home/deployer/example'
set :scm, :git
set :log_level, :debug
set :linked_files, %w{config/database.yml config/initializers/s3.rb config/redis.yml config/skylight.yml config/sunspot.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads solr}
set :keep_releases, 10
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :whenever_roles, :app
namespace :deploy do
desc 'Compile assets'
task :gulp_build do
on roles(:app) do
within "#{release_path}/app/assets/javascripts/app" do
with bower_registry: 'http://registry.bower.io' do
execute :bower, 'install -s'
end
end
within release_path do
execute :npm, 'install --silent'
execute :bundle, 'exec gulp build --production'
end
end
end
%i(start stop restart force_stop reload).each do |task_name|
namespace :unicorn do
task task_name do
invoke "unicorn:#{task_name}"
end
end
end
%i(start stop restart).each do |task_name|
namespace :solr do
task task_name do
invoke "solr:#{task_name}"
end
end
end
after :publishing, 'deploy:gulp_build'
after :publishing, 'deploy:unicorn:restart'
end
set :unicorn_conf_path, "#{release_path}/config/unicorn/#{fetch(:stage)}.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
namespace :unicorn do
def run_unicorn
execute :bundle, 'exec unicorn', '-c', fetch(:unicorn_conf_path), '-E', fetch(:rails_env), '-D'
end
desc 'Start unicorn'
task :start do
on roles(:app) do
within current_path do
run_unicorn
end
end
end
desc 'Stop unicorn'
task :stop do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-QUIT `cat #{fetch(:unicorn_pid_path)}`"
end
end
end
end
desc 'Force stop unicorn (kill -9)'
task :force_stop do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-9 `cat #{fetch(:unicorn_pid_path)}`"
execute :rm, fetch(:unicorn_pid_path)
end
end
end
end
desc 'Restart unicorn; use this when preload_app: true'
task :restart do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-USR2 `cat #{fetch(:unicorn_pid_path)}`"
else
run_unicorn
end
end
end
end
desc 'Restart unicorn; use this when preload_app: false'
task :reload do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-HUP `cat #{fetch(:unicorn_pid_path)}`"
else
run_unicorn
end
end
end
end
end
namespace :solr do
%i(start stop).each do |task_name|
desc "Sunspot solr #{task_name}"
task task_name do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env, 'production') do
execute :bundle, 'exec', :rake, "sunspot:solr:#{task_name}"
end
end
end
end
end
desc "Sunspot solr restart"
task :restart do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env, 'production') do
execute :bundle, 'exec', :rake, "sunspot:solr:stop"
sleep 5
execute :bundle, 'exec', :rake, "sunspot:solr:start"
end
end
end
end
end
My production:
set :rails_env, :production
set :application, 'example-production'
set :rbenv_ruby, '2.2.10'
set :branch, 'api'
set :deploy_to, '/home/deployer/api'
set :unicorn_conf_path, "#{release_path}/config/unicorn/proapi.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
server 'xxx.xxx.xx.xx', user: 'deployer', roles: %w{web app db}
Try add the allowed ssh keys to your production machine/ server. That is:
run cat ~/.ssh/id_rsa.pub on your local machine
Then run ~/.ssh/authorized_keys on your server/production machine
Copypaste the result of step 1 above in your authorized_keys file on your server
then run cap production deploy command again
Incase you don't see authorized_keys file when run ~/.ssh/authorized_keys
you can combine all the above commands that is 1 to 3 by running
cat ~/.ssh/id_rsa.pub | ssh USER#HOST "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys".
Thanks for the help!
Unfortunately, yesterday I was tired and inattentive. The problem was really the wrong user. I replaced git with a deployer and everything started up.
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 trying to deploy my rails 4 application in development mode. When I try cap deploy:setup, it says staging is not set. Next I tried cap development deploy according to its suggestion and got the following error. Please help me with the deployment.
command: cap development deploy
cap aborted!
wrong number of arguments (5 for 1..2)
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/dsl/env.rb:38:in `server'
config/deploy/development.rb:5:in `<top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/setup.rb:15:in `load'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/setup.rb:15:in `block (2 levels) in <top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/application.rb:15:in `run'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/bin/cap:3:in `<top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/bin/cap:23:in `load'
/home/divya/.rvm/gems/ruby-2.1.0/bin/cap:23:in `<main>'
/home/divya/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
/home/divya/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => development
(See full trace by running task with --trace)
Using the following files:
deploy.rb
set :application, 'timeTracker'
set :scm, :git
set :repository, "git#github.com:p/project.git"
set :user, "r"
set :scm_passphrase, "r"
set :branch, "master"
set :deploy_via, :remote_cache
set :stages, ["staging", "development", "production"]
set :default_stage, "development"
#set :rvm_ruby_string, :local
#before 'deploy:setup', 'rvm:install_rvm'
#set :default_shell, "/bin/bash -l"
#set :rvm_type, :user
#set :rvm_install_with_sudo, true
#default_run_options[:pty] = true
#ssh_options[:forward_agent] = true
#ssh_options[:auth_methods] = "publickey"
# ssh_options[:keys] = "il.pem"
# set :ssh_options, {:auth_methods => "publickey"}
# set :ssh_options, {:keys => ["/home/c/mbk.pem"]}
# default_environment['PATH'] = '/usr/local/rvm/gems/ruby-1.9.3-p392:$PATH'
# default_environment['GEM_PATH']= '/usr/local/rvm/gems/ruby-1.9.3-p392'
# set :location, "http://ec2-23-23-59-41.compute-1.amazonaws.com"
# set :use_sudo, false
# ssh_options[:keys] = ["/home/c/ec2/mbk.pem"]
config/development.rb
require "rvm/capistrano"
require 'capistrano/bundler'
server "IP", :app, :web, :db, :primary => true
set :deploy_to, "/var/www/t/"
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, "development" #added for delayed job
set :rvm_type, :system
after 'deploy:update_code' do
# run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
run "cd #{release_path};"
run "mkdir -p #{release_path}/tmp/cache;"
run "chmod -R 777 #{release_path}/tmp/cache;"
run "mkdir -p #{release_path}/public/uploads;"
run "chmod -R 777 #{release_path}/public/uploads"
run "rm -rf #{release_path}/public/system"
# run "unlink #{release_path}/public/db_admin"
# run "unlink #{release_path}/public/blog"
run "ln -s #{shared_path}/system/ #{release_path}/public/"
run "ln -s '/var/www/blog' #{release_path}/public/"
run "mv #{release_path}/config/database.example.yml #{release_path}/config/database.yml"
run "cd #{release_path} && bundle install"
run "cd #{release_path} && rake db:create"
run "cd #{release_path} && rake db:migrate"
# run "cd #{release_path} && RAILS_ENV=production rake assets:precompile"
# run "chown -R www-data:www-data #{release_path}/*"
# run "chmod -R 777 #{release_path}/log"
end
namespace :deploy do
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
wrong number of arguments (5 for 1..2)
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/dsl/env.rb:38:in `server'
It's telling you you're passing too many arguments to server. Try replacing the first line with the second:
server "151.236.218.85", :app, :web, :db, :primary => true
server "151.236.218.85", roles: [:app, :web, :db], :primary => true
It's also possible to use roles: %w(app web db) if you find that cleaner.
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.
I'm trying to deploy some changes to an existing ROR application using capistrano. I'm running MAC OSX and the server is Ubuntu 12.0.4. I'm new to ROR and capistrano, so here's an overview of what I've done so far. I cloned our github repo to a local folder, made my code changes, updated the github repo, installed capistrano using: gem install capistrano, opened terminal, changed directory into the local folder where my ROR app is located, and tried cap deploy:check. Note, I did not capify the project because there is an existing Deploy and Cap file in the project. When I run cap deploy:check I get the following output:
/Users/ben/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- delayed/recipes (LoadError)
from /Users/ben/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:152:in `require'
from ./config/deploy.rb:2:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `instance_eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:89:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `block in load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `load'
from Capfile:4:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `instance_eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:89:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `block in load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `block in load_recipes'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `load_recipes'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:31:in `execute!'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:14:in `execute'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/gems/capistrano-2.15.4/bin/cap:4:in `<top (required)>'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/bin/cap:19:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/bin/cap:19:in `<main>'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194#myapp/bin/ruby_noexec_wrapper:14:in `<main>'
Here is a sample of my deploy.rb file (with edits to user names, server name, etc.)
require "bundler/capistrano"
require "delayed/recipes"
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
require 'rvm/capistrano'
set :rails_env, "production" #added for delayed job
server "myservername", :web, :app, :db, primary: true
set :application, "myapp"
set :user, "deploy"
set :deploy_to, "/home/#{user}/apps/#{application}"
#set :deploy_via, :remote_cache
set :use_sudo, false
set :shared_children, shared_children + %w{public/uploads}
set :scm, "git"
set :scm_passphrase, "mypassword"
set :repository, "git#github.com:myusername/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
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_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
namespace :mailman do
desc "Mailman::Start"
task :start, :roles => [:app] do
run "cd #{current_path};RAILS_ENV=#{rack_env} bundle exec script/mailman_daemon start"
end
desc "Mailman::Stop"
task :stop, :roles => [:app] do
run "cd #{current_path};RAILS_ENV=#{rack_env} bundle exec script/mailman_daemon stop"
end
desc "Mailman::Restart"
task :restart, :roles => [:app] do
mailman.stop
mailman.start
end
end
And here is a copy of the cap file:
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
I would really appreciate some help with this. I just need to deploy a few changes to the production environment, but I'm kind of at a stand still right now. Hopefully, I've provided enough info. However, being really new to cap and ruby, I might be overlooking something really obvious. Thanks in advance!
Looks like a pathing issue. What path is your 'delayed/recipes' a part of? Please keep in mind that require will load files from the $LOAD_PATH .