I am deploying with Capistrano to my new VPS. After the first deploy(cap deploy) everything was OK (site was running), but the second deploy failed on assets:precompile error.
I am running rails 3.2.13, ruby 2.0.0, rvm.
error:
* executing "cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile"
servers: ["IP"]
[IP] executing command
*** [err :: IP] bash: line 1: 23406 Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
command finished in 84187ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/rails/releases/20140116121250; true"
servers: ["IP"]
[IP] executing command
command finished in 519ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'" on IP
deploy.rb file:
set :application, "app_name"
set :repository, "git_repository"
role :web, "IP"
role :app, "IP"
role :db, "IP", :primary => true
set :user, "rails"
set :password, "password"
set :use_sudo, false
set :deploy_to, "/home/rails/"
set :deploy_via, :copy
set :normalize_asset_timestamps, false
require 'bundler/capistrano'
require "rvm/capistrano"
set :rvm_type, :system
Capfile
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 am quite new to Capistrano, so please try to explain the solution clearly. Thank You for your support!
It seems as you have low operation memory size on your vpn server. (Vpn supplies without memory-swap for now) thus operation system kills your deploy process.
The solution is to compile assets locally (on your development machine)
Add deploy:assets:precompile task to your deploy.rb file (this is for Capistrano 2)
namespace :deploy do
. . .
namespace :assets do
task :precompile, :roles => :web do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
end
end
Then just redeploy you app
$ bundle exec cap deploy
wish it helps
Related
I'm using Capistrano for deploying my Rails app. and now Im facing error below when I enter commandcap production deploy` :
✔ 02 deploy#82.196.13.29 0.475s
04:44 webpacker:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber
(Backtrace restricted to imported tasks)
cap aborted!
Errno::ENOENT: No such file or directory - ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber )
Tasks: TOP => webpacker:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: No such file or directory - ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber )
And this is my deploy.rb file:
lock "~> 3.11.0"
set :application, "appName"
set :repo_url, "git#github.com:githubusername/appName"
# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"
set :default_env, {
'RBENV_ROOT' => '$HOME/.rbenv',
'RBENV_VERSION' => '2.5.5',
'RAILS_ENV' => 'production'
}
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# Only keep the last 5 releases to save disk space
set :keep_releases, 5
before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
desc 'Run rake yarn:install'
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install")
end
end
end
end
after 'deploy:updated', 'webpacker:precompile'
I'm using Rails 5.2.3 and Ruby 2.5.5 in this application. I also have a file .rbenv in /home/deploy/appName and contains these variables:
RAILS_MASTER_KEY=ohai
SECRET_KEY_BASE=1234567890
STRIPE_PUBLIC_KEY=x
STRIPE_PRIVATE_KEY=y
How can I fix this problem?
I'm running a rails app using JRuby 1.7.4 (1.9.3p392) with Torquebox and trying to deploy to Digital ocean VPS, when I run 'cap deploy' everything runs perfectly fine, however when i try to go to visit the site i still see "502 Bad Gateway nginx/1.1.19
This is my deploy.rb file
`require 'torquebox-capistrano-support'
require 'bundler/capistrano'
# SCM
# Update this part to match your server and location of your application code.
server "000.000.00.000", :web, :app, :primary => true
set :repository, 'git#github.com:jrgrammont/EmployToy.git'
set :branch, "master"
set :ssh_options, { :forward_agent => true }
set :user, "torquebox"
set :scm, :git
set :scm_verbose, true
set :use_sudo, false
set :deploy_to, '/opt/apps/employtoy.com'
set :torquebox_home, "/opt/torquebox/current"
set :jboss_init_script, "/etc/init.d/jboss-as-standalone"
set :rails_env, 'development'
set :app_context, "/"
set :app_ruby_version, '1.9'
set :application, 'employtoy.com'
default_environment['JRUBY_OPTS'] = '--1.9'
default_environment['PATH'] = '/opt/torquebox/current/jboss/bin:/opt/torquebox/current/jruby/bin:/usr/lib64/qt- 3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/root/bin'
after 'deploy:update_code', 'deploy:assets:precompile'
after 'deploy:update', 'deploy:resymlink', 'deploy:nginx'
before 'deploy:finalize_update', 'deploy:assets:symlink'
default_run_options[:pty] = true # Must be set for the password prompt from git to work
set :deploy_via, :remote_cache
namespace :deploy do
desc "relink db directory"
#if you use sqlite
task :resymlink, :roles => :app do
run "mkdir -p #{shared_path}/db; rm -rf #{current_path}/db && ln -s # {shared_path}/db #{current_path}/db && chown -R torquebox:torquebox #{current_path}/db"
end
# This is a weird part. I've found that asset complation with JRuby can really hog up the memory, which can cause the application to crash
# when doing a deploy. So, I like to compile the assets locally and SCP them to the server instead.
# Just make sure you've commented out the load deploy/assets in your Capfile.
namespace :assets do
# If you want to force the compilation of assets, just set the ENV['COMPILE_ASSETS']
task :precompile, :roles => :web do
force_compile = ENV['COMPILE_ASSETS']
begin # on first deploys, there is no current_revision so an error gets raised. in this case we want to just compile assets and upload them.
from = source.next_revision(current_revision)
rescue
force_compile = true
end
if ( force_compile) or (capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 )
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
end
I just ran the tutorial again...not really sure, but it looks like Capistrano is not starting Torquebox.
Try ssh'ing into the box and starting it with:
sudo service jboss-as-standalone start
also look at the torquebox log at /var/log/jboss-as/console.log .. is that throwing any errors?
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.
After first success deployment using Capistrano, running cap deploy failed:
no old releases to clean up
Triggering after callbacks for `deploy'
2013-04-16 10:59:15 executing `rvm:trust_rvmrc'
executing "rvm rvmrc trust /home/app/xxxx/releases/20130415225133"
servers: ["191.199.74.146"]
[191.199.74.146] executing command
[err :: 191.199.74.146] Marked /home/app/xxxx/releases/20130415225133/.rvmrc as trusted - failed
Error occurred when putting following code to the deploy.rb:
namespace :assets do
desc "Precompile assets locally and then rsync to app servers"
task :precompile, :only => { :primary => true } do
run_locally "mkdir -p public/__assets; mv public/__assets public/assets;"
run_locally "bundle exec rake assets:clean_expired; bundle exec rake assets:precompile;"
servers = find_servers :roles => [:app], :except => { :no_release => true }
servers.each do |server|
run_locally "rsync -av ./public/assets/ #{user}##{server}:#{current_path}/public/assets/;"
end
run_locally "mv public/assets public/__assets"
end
end
Update
I executed rvm rvmrc trust on my local, also failed..
xxxx-iMac:iv Owner$ rvm rvmrc trust Marked
/Users/Owner/Documents/workspace/iv/.rvmrc as trusted - failed
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