When I try to deploy with capistrano, i'hve got an error :
cap production deploy:setup
I've this error message :
/home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/gateway.rb:55: formal argument cannot be an instance variable (SyntaxError)
SSH.connect(server, #options) do |#session|
^
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration/connections.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration.rb:4:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/cli.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/bin/cap:3:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `load'
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `<main>'
Here is my Capfile :
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'
And my deploy.rb :
require "bundler/capistrano"
# allowing shell interactions
default_run_options[:pty] = true
# multistaging
set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
set :application, "myapp"
set :user, "myapp"
set :repository, "git#gitlab.conicrea.com:conicrea/myapp.git"
set :ssh_options, { :forward_agent => true }
set :deploy_to, "/var/www/#{application}"
set :scm, :git
set :deploy_via, :remote_cache
# number of releases we want to keep
set :keep_releases, 3
set :use_sudo, false
# default rails_env, should be overrided in config/deploy/#{environnement}.rb
set :rails_env, "staging"
# unicorn informations
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
set :unicorn_bin, "#{current_path}/bin/unicorn"
# useful for rbenv
set :default_environment, {
'PATH' => "/home/synbioz/.rbenv/shims:/home/synbioz/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}
namespace :maintenance do
task :start do
run "ln -nfs #{shared_path}/system/_maintenance.html #{shared_path}/system/maintenance.html"
end
task :stop do
run "rm -f #{shared_path}/system/maintenance.html"
end
end
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run <<-CMD
cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D
CMD
end
task :force_stop, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [ -e #{unicorn_pid} ]; then
kill -9 $(cat #{unicorn_pid});
fi
CMD
end
task :stop, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [ -e #{unicorn_pid} ]; then
kill $(cat #{unicorn_pid});
fi
CMD
end
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [ -e #{unicorn_pid} ]; then
kill -s QUIT $(cat #{unicorn_pid});
fi
CMD
end
task :reload, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [ -e #{unicorn_pid} ]; then
kill -s USR2 $(cat #{unicorn_pid});
fi
CMD
end
task :restart, :roles => :app, :except => { :no_release => true } do
run <<-CMD
if [ -e #{unicorn_pid} ]; then
kill -9 $(cat #{unicorn_pid});
sleep 5;
cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D;
fi
CMD
end
end
desc "Create shared folders."
after 'deploy:setup', :roles => :app do
# for unicorn
run "mkdir -p #{shared_path}/sockets"
run "mkdir -p #{shared_path}/config"
# only for sqlite
run "mkdir -p #{shared_path}/db"
end
desc "Link db.yml."
after 'deploy:update_code', :roles => :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "Seed datas when cold deploying."
after 'deploy:migrate', :roles => :app, :only => { :no_release => true } do
run "cd #{release_path} && bin/rake db:seed RAILS_ENV=#{rails_env}"
end
desc "Link maintenance, rbenv and precompile assets."
after 'deploy:symlink', :roles => [:web, :app] do
run "ln -nfs #{shared_path}/config/.rbenv-version #{release_path}/config/.rbenv-version"
run "cp #{release_path}/public/_maintenance.html #{shared_path}/system/"
run "cd #{release_path}; RAILS_ENV=#{rails_env} bin/rake assets:precompile"
end
desc "remove unused releases."
after "deploy", "deploy:cleanup"
I don't know what to do !
Can somebody help me ?
Thanks a lot !
That is a very old version of Capistrano (2.0.0 is from July 2007, and doesn't support changes in Ruby 1.9/2.0 -- in this case, Ruby 1.9 no longer allowed using instance variables as arguments to blocks).
You'll need to upgrade to the newest 2.x release (2.15.5).
You could also upgrade to Capistrano v3, but keep in mind it was a complete rewrite and your existing configuration will not be compatible with v3 without some work.
Related
Hi guys i have problem to deploy my rails app to production server. Actually i have install bundle in server via gem install bundler. Unfortunately when i typed cap production deploy it becomes like this:
** [out :: server url] bash: bundle: command not found
command finished in 772ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/crawler/releases/20180326063414; true"
servers: ["server url"]
[server url] executing command
command finished in 833ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-2.2.1' -c 'cd /home/deployer/crawler/releases/20180326063414 && bundle install --gemfile /home/deployer/crawler/releases/20180326063414/Gemfile --path /home/deployer/crawler/shared/bundle --deployment --quiet --without development test'" on server url
it says bash: bundle: command not found. I typed bundle --version the output is:
Bundler version 1.16.1
here is my gemfile
group :development do
gem 'capistrano', '~>2.15.4'
gem 'rvm-capistrano', '1.4.1', require: false
gem 'invoker'
gem 'regularity', require: nil
gem 'pry-rails'
end
and here is my deploy.rb:
require "bundler/capistrano"
require "rvm/capistrano"
require 'capistrano/ext/multistage'
require 'rollbar/capistrano'
#set :rollbar_token, '3dc5b293a0c74c3e8b98ab26f07bea74'
set :rollbar_token, 'de21e333f1d5469ea521c2ef3a29bd3d'
set :application, "crawler"
# set :repository, "git#bitbucket.org:terbang-ventures/linkedin-scraper.git"
set :repository, "git#bitbucket.org:terbang-ventures/linkedin-scraper.git"
set :rails_env, "production"
set :branch, "master"
set :scm, :git
set :default_shell, '/bin/bash -l'
# set :whenever_environment, defer { stage }
# require "whenever/capistrano"
set :stages, %w(production staging)
set :user, 'deployer'
set :rvm_type, :user
set :rvm_ruby_string, 'ruby-2.2.1'
set :rvm_binary, '~/.rvm/bin/rvm'
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :deploy_to, "/home/#{user}/#{application}"
set :use_sudo, false
set :deploy_via, :remote_cache
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
namespace :deploy do
desc 'Load environment variables'
task :load_env_vars do
run "ln -s /home/#{user}/env.yml #{current_release}/config/env.yml"
end
desc "Migrate DB1"
task :migrate_db1 do
# rake db:migrate_db1 RAILS_ENV=staging
run "cd #{current_path} && bundle exec rake db:migrate_db1 RAILS_ENV=#{rails_env}"
end
desc 'Re-establish mongoid.yml'
task :set_database_symlink do
run "ln -s /home/#{user}/mongoid.yml #{current_release}/config/mongoid.yml"
end
desc 'Re-establish database.yml'
task :set_database_symlink_active_record do
run "ln -s /home/#{user}/database.yml #{current_release}/config/database.yml"
end
desc 'run bundle install'
task :install_bundle do
run "cd #{current_path} && bundle install"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "ps axf | grep puma | grep -v grep | awk '{print \"kill -9 \" $1}' | sh"
run "cd #{current_path} && bundle exec puma -e #{rails_env} -p 9292 -d"
run "cd #{current_path} && bundle exec puma -e #{rails_env} -p 9293 -d"
end
task :stop, :roles => :app, :except => { :no_release => true } do
run "ps axf | grep puma | grep -v grep | awk '{print \"kill -9 \" $1}' | sh"
end
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && bundle exec puma -e #{rails_env} -p 9292 -d"
run "cd #{current_path} && bundle exec puma -e #{rails_env} -p 9293 -d"
end
end
namespace :searchkick do
# reindex
namespace :reindex do
# Reindex Contact
task :contact, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake searchkick:reindex CLASS=Contact RAILS_ENV=#{rails_env}"
end
# Reindex Contact
task :company, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake searchkick:reindex CLASS=Company RAILS_ENV=#{rails_env}"
end
task :user, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake searchkick:reindex CLASS=User RAILS_ENV=#{rails_env}"
end
task :all, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake searchkick:reindex:all RAILS_ENV=#{rails_env}"
end
end
end
namespace :importer do
task :department, roles: :app, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake importer:import_department RAILS_ENV=#{rails_env}"
end
task :staff_level, roles: :app, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake importer:import_staff_level RAILS_ENV=#{rails_env}"
end
task :email_format, roles: :app, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake importer:import_email_format RAILS_ENV=#{rails_env}"
end
task :combined_emails, roles: :app, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake importer:import_combined_emails RAILS_ENV=#{rails_env}"
end
task :late_address, roles: :app, except: {no_release: true} do
run "cd #{current_path} && bundle exec rake importer:import_late_address RAILS_ENV=#{rails_env}"
end
end
namespace :rails do
desc "Remote console"
task :console, roles: :app, except: { no_release: true } do
run_interactively "bundle exec rails c -e #{rails_env}"
end
desc "Remote dbconsole"
task :dbconsole, roles: :app, except: { no_release: true } do
run_interactively "bundle exec rails dbconsole -e #{rails_env}"
end
# Short aliases
task :c, roles: :app do
console
end
task :dbc, roles: :app do
dbconsole
end
desc "Monitor log"
task :log, roles: :app, except: { no_release: true } do
run_interactively "tail -f log/#{rails_env}.log"
end
def run_interactively(command)
server ||= find_servers_for_task(current_task).first
puts " running `#{command}` as #{user}##{server}"
exec %Q(ssh #{user}##{server} -t "bash --login -c 'cd #{current_path} && #{command}'")
end
end
after "deploy", "deploy:cleanup"
after "deploy", "deploy:migrate"
after "deploy:migrate", "deploy:migrate_db1"
after "deploy:start", "sidekiq:start"
after "deploy", "sidekiq:restart"
before "deploy:assets:precompile", "deploy:load_env_vars"
before "deploy:assets:precompile", "deploy:set_database_symlink"
before "deploy:assets:precompile", "deploy:set_database_symlink_active_record"
before "deploy:assets:precompile", "deploy:assets:clean"
before "deploy:migrate", "deploy:install_bundle"
My question is, why that capistrano still asking my bundle command not found if i trace it failed in rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-2.2.1' -c 'cd /home/deployer/crawler/releases/20180326065919 && bundle install --gemfile /home/deployer/crawler/releases/20180326065919/Gemfile --path /home/deployer/crawler/shared/bundle --deployment --quiet --without development test'?
The issue seems to be that during a capistrano deploy the created cron job has RAILS_ENV=staging as expected since the deployment environment is staging. However, in a capistrano rollback the created cron job has RAILS_ENV=new_staging where new_staging is the capistrano stage being rolled back.
my schedule file
set :job_template, nil
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task :output"
every 15.minute, roles: [:db] do
rake "jobs:publish", output: lambda { "2>&1 >> /path/to/capistrano_directory/shared/log/jobs.log" }
end
My deploy/new_staging.rb file
set :branch, "develop"
set :deploy_env, 'staging'
set :rails_env, 'staging'
server "user#server_ip", :web, :app, :db, :metrics
role :db, "user#server_ip", :primary => true # This is where Rails migrations will run
ssh_options[:forward_agent] = false # use local SSH keys remotely
ssh_options[:paranoid] = false
set :use_sudo, false
set :deploy_to, "/path/to/capistrano_directory"
set :unicorn_conf, "#{deploy_to}/current/config/environments/#{deploy_env}/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
before 'deploy:finalize_update', 'set_current_release'
before "deploy:finalize_update", "deploy:update_crontab"
after 'deploy:update_code', 'deploy:symlink_db'
namespace :deploy do
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{deploy_env} -D"
end
task :stop do
run "#{try_sudo} kill -QUIT `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
end
task :set_current_release, :roles => :app, :except => { :no_release => true } do
set :current_release, latest_release
end
And my deploy.rb
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
set :whenever_roles, [:db, :metrics]
require "whenever/capistrano"
set :stages, %w(production staging new_staging)
set :application, "###"
set :repository, "###"
set :deploy_via, :remote_cache
set :scm, :git
default_run_options[:shell] = '/bin/bash --login'
ssh_options[:forward_agent] = false
ssh_options[:paranoid] = false
namespace :deploy do
desc "Update the crontab file"
task :update_crontab do
run "cd #{release_path} && RAILS_ENV=#{fetch(:rails_env)} bundle exec whenever --update-crontab #{application} --set environment=#{fetch(:rails_env)}"
end
end
Whenever Version (0.9.7)
Capistrano Version (2.12.0)
What is causing the rollback to use the capistrano stage instead of the rails_env when running Whenever gem? And how can I get it to properly use the rails_env?
I'm a little confused by your staging setup (what is the difference between staging and new_staging?). That said, you should be able to do this by changing your whenever_environment to use rails_env instead of the stage value set by capistrano:
so
set :whenever_environment, defer { stage }
Would become:
set :whenever_environment, defer { rails_env }
whenever README
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.
"rake assets:precompile" and "cap deploy" consume extremely high amount of time whenever I call it (usually more then an hour). Sometimes deploy hang at all.
I use Rails 3.2.13, Ruby 1.9.3, OSX and Backbone's Chaplin Framework for frontend.
How can I speed up assets precompile and deploy task and what can cause such freezing?
My deploy.rb config:
# -*- encoding : utf-8 -*-
require 'bundler/capistrano'
load 'deploy/assets'
set :application, "eyelashes"
set :rails_env, "production"
set :repository, "git#github.com:eyelasher/repo.git"
set :scm, :git
set :deploy_via, :checkout
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
server "75.223.145.3", :app, :web, :db, :primary => true
set :bundle_without, [:test]
set :user, 'deployer'
set :deploy_to, "/home/deployer/eyelasher"
set :branch, "master" unless exists?(:branch)
set :use_sudo, false
set :rvm_type, :user
set :rvm_ruby_string, :local
set :deploy_via, :checkout
before 'deploy:setup', 'rvm:create_gemset'
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
after "deploy", "deploy:migrate"
after "deploy", "deploy:cleanup"
require 'rvm/capistrano'
require 'thinking_sphinx/deploy/capistrano'
#after 'deploy:update_code', :roles => :app do
#run "rm -f #{current_release}/config/database.yml"
#run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml"
#end
namespace :deploy do
task :restart do
run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D;"
end
task :stop do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
end
end
# Thinking Sphinx typing shortcuts
namespace :ts do
task :conf do
thinking_sphinx.configure
end
task :in do
thinking_sphinx.index
end
task :start do
thinking_sphinx.start
end
task :stop do
thinking_sphinx.stop
end
task :restart do
thinking_sphinx.restart
end
task :rebuild do
thinking_sphinx.rebuild
end
end
# http://github.com/jamis/capistrano/blob/master/lib/capistrano/recipes/deploy.rb
# :default -> update, restart
# :update -> update_code, symlink
namespace :deploy do
desc "Link up Sphinx's indexes."
task :symlink_sphinx_indexes, :roles => [:app] do
run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
end
task :activate_sphinx, :roles => [:app] do
symlink_sphinx_indexes
thinking_sphinx.configure
#thinking_sphinx.stop
#thinking_sphinx.start
end
task :copy_images do
run "cp -R #{shared_path}/public/images #{release_path}/public/images"
end
before 'deploy:update_code', 'thinking_sphinx:stop'
after 'deploy:update_code', 'deploy:activate_sphinx'
after 'deploy:update_code', 'deploy:copy_images'
end
Maybe I can speedup somehow by making changes in deploy configuration?
If you are deploying to a memory constrained VPS that sounds plausible. I'd recommend precompiling the assets on a a faster machine and checking them in to your repository.
There are various Gems and packages for speeding up asset precompilation by parallesing them, however in your situation that will likely make things MUCH worse!
I'm trying to deploy the first rails application using Capistrano.
I'm getting an error while capistrano tries to run rake db:migrate.
To be more clear this is the traceback of the exception:
[ip] executing command
*** [err :: ip] bash: rake: command not found
command finished in 124ms
failed: "env RAILS_ENV=production bash -c 'cd /home/deployer/website/current && rake RAILS_ENV=production db:migrate'" on ip
And this is the config/deploy.rb I'm using actually. On the server I've installed RVM (single user installation).
# config/deploy.rb
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :scm, :git
set :repository, "git#bitbucket.org:user/project.git"
set :branch, "origin/master"
set :migrate_target, :current
set :ssh_options, { :forward_agent => true }
set :rails_env, "production"
set :deploy_to, "/home/deployer/website"
set :normalize_asset_timestamps, false
set :rvm_type, :user # Don't use system-wide RVM
set :rvm_ruby_string, "ruby-1.9.3-p194#global"
set :user, "deployer"
set :group, "staff"
set :use_sudo, false
role :web, "IP"
role :app, "IP"
role :db, "IP2", :primary => true
set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }
set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD#{1}").strip }
default_environment["RAILS_ENV"] = 'production'
default_run_options[:shell] = 'bash'
namespace :deploy do
desc "Deploy your application"
task :default do
update
restart
end
desc "Setup your git-based deployment app"
task :setup, :except => { :no_release => true } do
dirs = [deploy_to, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d) }
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
run "git clone #{repository} #{current_path}"
end
task :cold do
update
migrate
end
task :update do
transaction do
update_code
end
end
desc "Update the deployed code."
task :update_code, :except => { :no_release => true } do
run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
finalize_update
end
desc "Update the database (overwritten to avoid symlink)"
task :migrations do
transaction do
update_code
end
migrate
restart
end
task :finalize_update, :except => { :no_release => true } do
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
# mkdir -p is making sure that the directories are there for some SCM's that don't
# save empty folders
run <<-CMD
rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
mkdir -p #{latest_release}/public &&
mkdir -p #{latest_release}/tmp &&
ln -s #{shared_path}/log #{latest_release}/log &&
ln -s #{shared_path}/system #{latest_release}/public/system &&
ln -s #{shared_path}/pids #{latest_release}/tmp/pids &&
ln -sf #{shared_path}/database.yml #{latest_release}/config/database.yml
CMD
if fetch(:normalize_asset_timestamps, true)
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
end
end
desc "Zero-downtime restart of Unicorn"
task :restart, :except => { :no_release => true } do
run "kill -s USR2 `cat /tmp/unicorn.my_site.pid`"
end
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat /tmp/unicorn.my_site.pid`"
end
namespace :rollback do
desc "Moves the repo back to the previous version of HEAD"
task :repo, :except => { :no_release => true } do
set :branch, "HEAD#{1}"
deploy.default
end
desc "Rewrite reflog so HEAD#{1} will continue to point to at the next previous release."
task :cleanup, :except => { :no_release => true } do
run "cd #{current_path}; git reflog delete --rewrite HEAD#{1}; git reflog delete --rewrite HEAD#{1}"
end
desc "Rolls back to the previously deployed version."
task :default do
rollback.repo
rollback.cleanup
end
end
end
def run_rake(cmd)
run "cd #{current_path}; #{rake} #{cmd}"
end
How can I make this run properly?
Of course I already tried to run rake on the server, and it is found properly.
Thanks
you break rvm/capistrano integration by adding this line:
default_run_options[:shell] = 'bash'
You need to remove it.
Also I see a lot of over-engineering in your script, please check my example script which I run from time to time to confirm RVM works as expected:
https://github.com/mpapis/ad/blob/master/config/deploy.rb