on cap deploy:cold ro cap deploy, is triggered an error
[out :: xxx.xxx.xxx.xxx] Killed
command finished in 9020ms
*** [deploy:update_code] rolling back
* executing [#<Capistrano::Command::Tree::ElseBranch:0x00000100dc5478 #condition="else", #command="rm -rf /home/yasinishyn/apps/mkv/releases/20130506084016; true", #callback=#<Proc:0x00000100dd5da0#/usr/local/rvm/gems/ruby-2.0.0-p0/gems/capistrano-2.15.3/lib/capistrano/configuration/actions/invocation.rb:13>, #options={}, #skip=false>]
servers: ["xxx.xxx.xxx.xxx"]
[xxx.xxx.xxx.xxx] executing command
command finished in 386ms
failed: "sh -c 'cd -- /home/yasinishyn/apps/mkv/releases/20130506084016 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on xxx.xxx.xxx.xxx
I have tryed many advises from stack, but nosing works for me.
my deploy.rb
deploy.rb:
require "bundler/capistrano"
server "xxx.xxx.xxx.xxx", :web, :app, :db, primary: true
set :application, "app"
set :user, "user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#github.com:git_user/#{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
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"
#rake seed task
desc "Seed the database on already deployed code"
task :seed, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:seed"
end
desc "Seed the database on already deployed code"
task :drop, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:drop:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:create:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:migrate"
end
end
in my production.rb I have
config.assets.compress = true
and my capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
local precompile with "bundle exec rake assets:precompile RAILS_ENV=production --trace" executes without any errors.
Where is my mistake? Hot to debug it? Or maybe somewhere is some log file for capistano in which a can look for more details?
I find an answer by my own
delete "load 'deploy/assets'" from capfile, and run
cap deploy:cold
this will work without an error, but only on initial deploy. Then as usual "sudo service nginx restart" on server, and add back deleted snippet.
And BAMM!! It works :)
You are out of RAM by the sounds of it, this question and answer helped me out - I increased the swap on digital ocean server and everything worked fine: deploy with capistrano failing
For anyone who face the same problem and Andrey answer don't work stop the server "sudo service nginx stop" then cap deploy and then start the server again "sudo service nginx start". It worked for me.
Related
I am using this_link for deploying, but I didnt created new user rather I am continuing with root user. I am using unicorn, nginx, capistrano for this.
On running cap deploy:cold, I am getting error bash: bundle: command not found.
deploy.rb
set :stages, %w(production) #various environments
require "bundler/capistrano"
require "rvm/capistrano"
server "xxx.xxx.xxx.xx", :web, :app, :db, primary: true
set :application, "xyz"
set :stage, "production"
set :user, "root"
set :port, 22
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :default_shell, :bash
# set :scm, "git"
set :repository, "git#bitbucket.org:xyz_app/xyz.git"
set :branch, "master"
# set :rvm_ruby_string, :local # use the same ruby as used locally for deployment
set :rvm_autolibs_flag, "read-only" # more info: rvm help autolibs
before 'deploy:setup', 'rvm:install_rvm' # install/update RVM
# before 'deploy:setup', 'rvm:install_ruby'
# before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset,
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
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
cap shell output
cap> echo $PATH
[establishing connection(s) to xxx.xxx.xxx.xx]
** [out :: xxx.xxx.xxx.xx] /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/.rvm/bin
** [out :: xxx.xxx.xxx.xx]
cap> id
** [out :: xxx.xxx.xxx.xx] uid=0(root) gid=0(root) groups=0(root)
** [out :: xxx.xxx.xxx.xx]
cap> exit
cap deploy:check
You appear to have all necessary dependencies installed
Error code
* 2015-09-10 01:49:10 executing `bundle:install'
* executing "cd /home/root/apps/xyz/releases/20150909201909 && bundle install --gemfile /home/root/apps/xyz/releases/20150909201909/Gemfile --path /home/root/apps/xyz/shared/bundle --deployment --quiet --without development test"
servers: ["xxx.xxx.xxx.xx"]
[xxx.xxx.xxx.xx] executing command
** [out :: xxx.xxx.xxx.xx] bash: bundle: command not found
** [out :: xxx.xxx.xxx.xx]
command finished in 338ms
*** [deploy:update_code] rolling back
Please help me out from this issue. Thanks in advance
You need bundler. http://bundler.io/
gem install bundler
This gave it away: bash: bundle: command not found
I have this in my deploy.rb but I don't know how to run this command in the deployment server:
rake db:production RAILS_ENV=production
And what I have is not working. I wait for your answers. And also if you know how to start unicorn when the deploy is complete.
# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/myuser/myapp.git'
set :scm, :git
set :repo_url, 'https://github.com/myuser/myapp.git'
# Define where to put your application code
set :deploy_to, "/home/deployer/apps/myapp"
set :pty, true
set :format, :pretty
set :rails_env, "production"
namespace :rake do
desc "Invoke rake task"
task :invoke do
run "cd #{deploy_to}/current"
run "bundle exec rake #{ENV['task']} RAILS_ENV=#{rails_env}"
end
end
you can do something like this:
%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
and regard your task:
task :your_task, :roles => :app do
run "cd #{release_path}; bundle exec rake db:production RAILS_ENV=#{rails_env}"
end
"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 spent hours on this railscast, http://railscasts.com/episodes/335-deploying-to-a-vps and this tutorial, https://coderwall.com/p/yz8cha(which is based on the railscast)
I am getting this when I do cap deploy:setup or bundle exec cap deploy:setup
I am not quite familiar with the scripts used on the railscast, mainly copy and paste/augment path (insert username/projectname) on the root path. I suspect that I configured the scripts incorrectly?
cap deploy:setup
triggering load callbacks
* 2013-09-06 01:21:56 executing `deploy:setup'
* executing "mkdir -p /home/deployer2/apps/lintong /home/deployer2/apps/lintong/releases /home/deployer2/apps/lintong/shared /home/deployer2/apps/lintong/shared/system /home/deployer2/apps/lintong/shared/log /home/deployer2/apps/lintong/shared/pids"
servers: ["192.241.241.204"]
[192.241.241.204] executing command
** [out :: 192.241.241.204] bash: /home/deployer2/.rvm/bin/rvm-shell: No such file or directory
command finished in 9ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'mkdir -p /home/deployer2/apps/lintong /home/deployer2/apps/lintong/releases /home/deployer2/apps/lintong/shared /home/deployer2/apps/lintong/shared/system /home/deployer2/apps/lintong/shared/log /home/deployer2/apps/lintong/shared/pids'" on 192.241.241.204
here is my deploy.rb file
require "bundler/capistrano"
require "rvm/capistrano"
server "192.241.241.204", :web, :app, :db, primary: true
set :application, "lintong"
set :user, "deployer2"
set :port, 7000
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#github.com:Jngai/#{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
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
its looking for rvm in the wrong place? its living in usr/local. is anyone familiar with deployment using Capistrano ?
I was lacking this in my deploy.rb
set :rvm_ruby_string, :local # use the same ruby as used locally for deployment
before 'deploy:setup', 'rvm:install_rvm' # install/update RVM
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR:
I am new to using git and Capistrano. I have setup everything else on my server and pushed my app onto a git repo (http://github.com/tnederlof/daily-trailer). When I go to run cap deploy:cold everything seems to be working until it tries to rake the db. Below is what I get when I run it, this is the last bunch of information I recieve and where the error occurs:
* executing "cd /var/www/dailytrailer.net/releases/20100205052047; rake RAILS_ENV=production db:migrate"
servers: ["173.203.201.168"]
[173.203.201.168] executing command
** [out :: 173.203.201.168] (in /var/www/dailytrailer.net/releases/20100205052047)
command finished
* executing `deploy:start'
[DEPRECATED] `deploy:start` is going to be removed after 2.5.9 - see http://is.gd/2BPeA
* executing "cd /var/www/dailytrailer.net/current && nohup script/spin"
servers: ["173.203.201.168"]
[173.203.201.168] executing command
** [out :: 173.203.201.168] nohup: ignoring input and appending output to `nohup.out'
** [out :: 173.203.201.168] nohup: cannot run command `script/spin': No such file or directory
command finished
failed: "sh -c 'cd /var/www/dailytrailer.net/current && nohup script/spin'" on 173.203.201.168
Can someone please help me figure out what script/spin is all about?
Thank you!
Do you know what you're trying to use for an app server? If it's Passenger, then you've got something screwed up in your deploy.rb. (Post that file if you want more help debugging this.) If it's mongrel, then this should be helpful.
http://www.rubyrobot.org/article/deploying-rails-20-to-mongrel-with-capistrano-21
so I am having the sam problem here
Everything gets executed expect for
executing `deploy:start'
[DEPRECATED] `deploy:start` is going to be removed after 2.5.9 - see http://is.gd/2BPeA
* executing "cd /srv/www/domain.com/domain/current && nohup script/spin"
servers: ["domain.com"]
[domain.com] executing command
** [out :: domain.com] nohup: ignoring input and appending output to `nohup.out'
** [out :: domain.com] nohup: cannot run command `script/spin': No such file or directory
command finished
failed: "sh -c 'cd /srv/www/domain.com/domain/current && nohup script/spin'" on domain.com
here is my deploy file don't see any problems as is
set :application, "domain"
set :repository, "git#git.assembla.com:domain.git"
set :user, "blitz"
set :use_sudo, false
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :deploy_to, "/srv/www/domain.com/#{application}"
#set :git_enable_submodules, 1 # Make sure git submodules are populated
set :port, 3002 # The port you've setup in the SSH setup section
#set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
role :web, "domain.com" # Your HTTP server, Apache/etc
role :app, "domain.com" # This may be the same as your `Web` server
role :db, "domain.com", :primary => true # This is where Rails migrations will run
#role :db, "domain.com" # for slave db
# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
# task :start do ; end
# task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
desc "Make symlink for database.yml"
task :symlink_dbyaml do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "Create empty database.yml in shared path"
task :create_dbyaml do
run "mkdir -p #{shared_path}/config"
put '', "#{shared_path}/config/database.yml"
end
end
after 'deploy:setup', 'deploy:create_dbyaml'
after 'deploy:update_code', 'deploy:symlink_dbyaml'
after "deploy", "deploy:cleanup"
edit:
never-mind found the ans
was using passenger and needed this in the deploy.rb
[:start, :stop].each do |t|
desc "ignore #{t} since we are using passenger"
task t do ; end
end