Capistrano Rollback breaking Whenever Cronjob - ruby-on-rails

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

Related

Capistrano deploy and assets:precompile too slow

"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!

Assets won't precompile when deploying with capistrano to production on amazon EC2

I worked on being able to deploy to production using capistrano. I face several issues and while fixing most of them we still have a last one.
Our precompile assets options are not properly compiling them on production and because of that, we are unable to use the last developed features as they rely heavily on JS.
Without trying to influence on how anyone would analyze this problem, this is some of what I did trying to make it work:
Precompiled assets locally, pushed to github repo, cap deployed from local machines to ec2. cap deploy is local, the code being pushed to ec2 is the one on github.
Tried using capistrano tasks as suggested. Using load 'deploy'assets' in the Capfile and letting the cap deploy:setup task do its thing.
Used the option cap deploy:assets:clean and then cap deploy:assets:precompile
Tried removing assets from public and then use a pipeline_precompile task in deploy.rb
Expired assets, forcing rails to precompile everything changing assets.versions in application.rb
Tried different combinations on config.assets in environments/production.rb
Finally, tried deleting public/assets in production and precompiling up there using RAILS_ENV=production bundle exec rake assets:precompile
The app is just not using the new JS files. If you check the code either on the repo or in the server itself, I introduced a simple comment to the name.js.coffee ("# Shows and hides menus depending on the data on DB" on line xxx) and this is not in the compiled assets.js in production. This is a quick test to be sure the recent assets are being used.
The whole problem here is the js and css files, not so much rails. Which is why it is so difficult to test or find.. Thus one of the reasons for the popularity of js frameworks lately. In case of problems, you don't have to kill yourself looking for where the problem is.. If the prob is in ruby or rails, usually doesn't take that long to find out. Once you get to js, css and cross browser compatibility, well, this IS the problem at hand.
Here's my deploy.rb file. Running rails 3.2.12 ruby-1.9.3-p327:
# $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
# Load rvm's capistrono plugins
require 'rvm/capistrano'
require 'bundler/capistrano'
set :rvm_type, :user
set :user, 'username'
set :domain, 'ip_address'
set :application, "app_pro"
set :keep_releases, 2 # It keeps on two old releases.
# git repo details
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
set :repository, "git#github.com:user/app.git"
set :scm_username, 'user'
set :git_enable_submodules, 1
set :git_shallow_clone, 1
set :branch, 'master'
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true# 'ec2-23-23-156-118.compute-1.amazonaws.com' This is where Rails migrations will run
# role :db, "your slave db-server here"
# deply options
default_run_options[:pty] = true
set :ssh_options, {:forward_agent => true}
set :ssh_options, {:auth_methods => "publickey"}
set :ssh_options, {:keys => ["~/Downloads/key.pem"]}
set :deploy_to, "/home/user/appdir"
set :deploy_via, :remote_cache
set :use_sudo, false
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do
# run COMMAND="/etc/init.d/nginx restart" invoke SUDO=1
run "sudo /etc/init.d/nginx restart"
# exit
end
after "deploy:start", "deploy:cleanup"
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :setup_config, roles: :app do
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts 'now edit the config file database in #{shared_path}'
end
after 'deploy:setup', 'deploy:setup_config'
desc "Symlink shared resources on each release - not used"
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 "It helps to seed database with values"
task :seed do
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
end
task :create_schema do
run "cd #{current_path}; bundle exec rake db:create RAILS_ENV=#{rails_env} --trace"
end
end
On-working new/alternative (deploy_new2.rb) file:
# On-working new/alternative deploy.rb file:
require 'rvm/capistrano'
require 'bundler/capistrano'
set :rvm_type, :user
set :application, "ip_address"
set :domain, 'ip_address'
# Roles
role :web, domain
role :app, domain
role :db, domain, :primary => true
#deployment details
set :deploy_via, :remote_cache
set :user, "username"
set :copy_compression, :bz2
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
set :deploy_to, "/home/user/dir"
default_run_options[:pty] = true
set :ssh_options, {:forward_agent => true}
set :ssh_options, {:auth_methods => "publickey"}
set :ssh_options, {:keys => ["~/Downloads/key.pem"]}
#repo details
set :scm, :git
set :repository, "git#github.com:user/app.git"
set :scm_username, 'user'
set :keep_releases, 2
set :branch, "master"
namespace :deploy do
# task :start, :roles => :app, :except => { :no_release => true } do
# # not need to restart nginx every time
# # run "service nginx start"
# run "cd #{release_path} && touch tmp/restart.txt"
# end
# after "deploy:start", "deploy:cleanup"
# after 'deploy:cleanup', 'deploy:symlink_config'
# You do not need reload nginx every time, eventhought if you use passenger or unicorn
# task :stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :graceful_stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :reload, :roles => :app, :except => { :no_release => true } do
# run "cd #{release_path} && touch tmp/restart.txt"
# run "service nginx restart"
# end
task :restart, :roles => :app, :except => { :no_release => true } do
run "cd #{release_path} && touch tmp/restart.txt"
end
# If you enable assets/deploy in Capfile, you do not need this
# task :pipeline_precompile do
# # run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
# # precompile assets before deploy and upload them to server
# # run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile")
# # top.upload "public/assets", "#{release_path}/public/assets", :via =>:scp, :recursive => true
# end
end
# you do not need to this, because you already add require 'bundler/capistrano'
# before "deploy:assets:precompile", "bundle:install"
And ./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
Thank you in advance for any help! Let me know if you need more info.
You don't need your own :precompile_assets task. You are using Capistrano's by including load 'deploy/assets' in your Capfile.
Removing the :precompile_assets task from your deploy.rb may resolve the issue. If you look at the source code for Capistrano, you'll see it implements :precompile_assets quite differently: https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy/assets.rb
You can try this code
# On-working new/alternative deploy.rb file:
require 'rvm/capistrano'
require 'bundler/capistrano'
set :rvm_type, :user
set :application, "ip_address"
set :domain, 'ip_address'
# Roles
role :web, domain
role :app, domain
role :db, domain, :primary => true
#deployment details
set :deploy_via, :remote_cache
set :user, "username"
set :copy_compression, :bz2
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
set :deploy_to, "/home/user/dir"
default_run_options[:pty] = true
set :ssh_options, {:forward_agent => true}
set :ssh_options, {:auth_methods => "publickey"}
set :ssh_options, {:keys => ["~/Downloads/key.pem"]}
#repo details
set :scm, :git
set :repository, "git#github.com:user/app.git"
set :scm_username, 'user'
set :keep_releases, 2
set :branch, "master"
namespace :deploy do
# task :start, :roles => :app, :except => { :no_release => true } do
# # not need to restart nginx every time
# # run "service nginx start"
# run "cd #{release_path} && touch tmp/restart.txt"
# end
# after "deploy:start", "deploy:cleanup"
# after 'deploy:cleanup', 'deploy:symlink_config'
# You do not need reload nginx every time, eventhought if you use passenger or unicorn
# task :stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :graceful_stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :reload, :roles => :app, :except => { :no_release => true } do
# run "cd #{release_path} && touch tmp/restart.txt"
# run "service nginx restart"
# end
task :restart, :roles => :app, :except => { :no_release => true } do
run "cd #{release_path} && touch tmp/restart.txt"
end
# If you enable assets/deploy in Capfile, you do not need this
# task :pipeline_precompile do
# # run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
# # precompile assets before deploy and upload them to server
# # run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile")
# # top.upload "public/assets", "#{release_path}/public/assets", :via =>:scp, :recursive => true
# end
end
# you do not need to this, because you already add require 'bundler/capistrano'
# before "deploy:assets:precompile", "bundle:install"
Solution: Here's the working deploy file-
require 'rvm/capistrano'
require 'bundler/capistrano'
set :rvm_type, :user
set :application, "ip_address"
set :domain, 'ip_address'
# Roles
role :web, domain
role :app, domain
role :db, domain, :primary => true
#deployment details
set :deploy_via, :remote_cache
set :user, "user"
set :copy_compression, :bz2
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
set :deploy_to, "/home/user/app_dir"
default_run_options[:pty] = true
set :ssh_options, {:forward_agent => true}
set :ssh_options, {:auth_methods => "publickey"}
set :ssh_options, {:keys => ["~/sites/app/config/key.pem"]}
#repo details
set :scm, :git
set :repository, "git#github.com:github_id/app.git"
set :scm_username, 'github_id'
set :keep_releases, 2
set :branch, "master"
after 'deploy:update_code', 'deploy:symlink_db'
namespace :deploy do
# task :start, :roles => :app, :except => { :no_release => true } do
# # not need to restart nginx every time
# # run "service nginx start"
# run "cd #{release_path} && touch tmp/restart.txt"
# end
# after "deploy:start", "deploy:cleanup"
# after 'deploy:cleanup', 'deploy:symlink_config'
# You do not need reload nginx every time, eventhought if you use passenger or unicorn
# task :stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :graceful_stop, :roles => :app, :except => { :no_release => true } do
# run "service nginx stop"
# end
# task :reload, :roles => :app, :except => { :no_release => true } do
# run "cd #{release_path} && touch tmp/restart.txt"
# run "service nginx restart"
# end
task :restart, :roles => :app, :except => { :no_release => true } do
run "cd #{release_path} && touch tmp/restart.txt"
end
desc "Symlinks the database.yml"
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
# If you enable assets/deploy in Capfile, you do not need this
# task :pipeline_precompile do
# # run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
# # precompile assets before deploy and upload them to server
# # run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile")
# # top.upload "public/assets", "#{release_path}/public/assets", :via =>:scp, :recursive => true
# end
end
# you do not need to this, because you already add require 'bundler/capistrano'
# before "deploy:assets:precompile", "bundle:install"
I found that the capistrano asset compile rules got run before the bundler rules, so nothing worked, I wrote my own:
after "bundle:install" do
run "cd #{release_path}; RAILS_ENV=production bundle exec rake assets:precompile"
end
I then found that I really wasn't interested in installing a js runtime on my production machines. I went back to just putting my assets into a deploy branch of my git tree.
First time I did this, I forgot to include the manifest.yml file.
http://jimneath.org/2012/05/05/precompile-assets-using-a-git-hook.html
If you have uglifier in Gemfile, which runs during asset compilation, it may have been configured to remove just the sort of comment you are using as a test for whether the changed Javascript assets are being deployed.
Uglifier's Readme says this is possible, and distinguishes several kinds of comments. So it's possible you may have been misled by seeing another comment still remaining after asset compilation.
Another clue to judging this possibility is that (as you say) this problem arose after a long (tiring) process of fixing other problems. Often, this can block people from a perception like this; a long effort can 'lock them in' to an assumption.
So, try adding a variable declaration instead of a comment, in your Javascript.
I had an issue similar to this but the solution was to remove the assets group in the Gemfile, as the default task cap uses to precompile depends on the assets not being in a separate group seemingly.
I encountered this problem. Turns out I had to install node and yarn on my servers for rake assets:precompile to work
I also had this issue recently, asset precompilation with Capistrano deployment was hanging in AWS. I solved the issue by switching from a t3.micro instance to a t3.small instance temporarily while I deployed. It looks like the micro instance did not have enough resources for the precompilation step.

capistrano + dreamhost + deploy fails doesnt create the release/release_version dir

i cant get capistrano to fully deploy my rails app to my dreamhost VPS..
as far as i can tell its halting at creating the release directory..
$ cap deploy
i get
failed: "sh -c 'cd /home/gasloggr/gasloggr.com/releases/20120824064241 && bundle install --gemfile /home/gasloggr/gasloggr.com/releases/20120824064241/Gemfile --path /home/gasloggr/gasloggr.com/shared/bundle --deployment --quiet --without development test'" on gasloggr.com
for troubleshooting purposes i ran what was in quotes on the server itself and i received..
bash: cd: /home/gasloggr/gasloggr.com/releases/20120824064241: No such file or directory
a quick ls -alh of the releases dir, and guess what... its empty.
My deploy.rb file
require 'bundler/capistrano'
default_run_options[:pty] = false
ssh_options[:forward_agent] = true
set :use_sudo, false
set :user, "gasloggr"
set :application, "gasloggr.com"
set :repository, "git#github.com:gorelative/GasLoggr.git"
set :scm, :git
set :branch, 'master'
set :git_shallow_clone, 1
set :deploy_via, :copy
set :copy_compression, :bz2
set :rails_env, 'production'
set :deploy_to, "/home/gasloggr/#{application}"
role :web, "#{application}" # Your HTTP server, Apache/etc
role :app, "#{application}" # This may be the same as your `Web` server
role :db, "#{application}", :primary => true # This is where Rails migrations will run
# role :db, "your slave db-server here"
namespace :deploy do
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
end
namespace :deploy do
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
end
i have tried removing :deploy_via as well as all of the below:
set :deploy_via, :remote_cache
set :deploy_via, :copy
Please try again following the methods outlined here: http://wiki.dreamhost.com/Capistrano
This specific part may be of the most help, mentioning cap deploy:setup : http://wiki.dreamhost.com/Capistrano#Deployment_with_Capistrano

Where to add precompile in deploy.rb

Where would I put the precompile info in my deploy.rb file. What do I need to change to get this working? I am able to get my app to run using
RAILS_ENV=production rake assets:precompile
Precompile info
after "deploy:restart", "deploy:precompile"
namespace :deploy do
desc "Compile assets"
task :precompile, :roles => :app do
run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
end
end
My deploy.rb
# The name of your app
set :application, "sample_app"
# The directory on the EC2 node that will be deployed to
set :deploy_to, "/var/www/#{application}"
set :keep_releases, 3
# deploy with git
set :scm, :git
set :repository, "git#github.com:username/sample_app.git"
set :git_shallow_clone, 1
set :branch, "master"
set :use_sudo, true
# gets ssh info
set :user, "ubuntu"
ssh_options[:keys] = ["/Users/User/Documents/ServerKeys/key.pem"]
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
# The address of the remote host on EC2 (the Public DNS address)
set :location, "0.0.0.0"
# setup some Capistrano roles
role :app, location
role :web, location
role :db, location, :primary => true
after 'deploy:update_code', 'deploy:symlink_db'
namespace :deploy do
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{deploy_to}/#{shared_dir}/tmp/restart.txt"
end
desc "Symlinks the database.yml"
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml
#{release_path}/config/database.yml"
end
end
Capistrano (v2.8.0 and above) includes a recipe to handle this in deployment. Add the following line to Capfile:
load 'deploy/assets'
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

Capistrano Deploy Error

I've recently had to make some updates to an app that I haven't touched in about a year. When attempting to deploy with Capistrano (via Github), I get this error:
[deploy:update_code] exception while rolling back: IOError, closed stream
Full logged error here: https://gist.github.com/2829751
I reinstalled my server's SSH key after the Github SSH security scare. Nothing should have changed on the remote server, and deploying worked fine previously. The only significant change on my local system is moving to RVM.
Any ideas what's causing the error?
Here's my deploy.rb file, if that helps:
default_run_options[:pty] = true
set :domain, 'xxx.xxx.xxx'
set :repository, "XXX MY REPO XXX"
set :branch, 'master'
set :password, 'XXXXXXX'
set :deploy_to, "/var/www/#{domain}"
set :scm, :git
set :repository_cache, "git_cache"
set :deploy_via, :remote_cache
ssh_options[:paranoid] = false
set :user, "XXX"
set :runner, user
set :use_sudo, true
set :rails_env, 'production'
role :app, domain # multiple domains can be added here for parallel deployment (i.e. test_app)
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :start, :roles => :app do
run "touch #{release_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{release_path}/tmp/restart.txt"
end
end
deploy.task :cold do
deploy.update
deploy.create_db
deploy.migrate
deploy.restart # Change to start if we're using mongrels
end
after "deploy:update_code", :update_config
after "deploy:restart", "delayed_job:restart"
after "deploy", "deploy:cleanup"
#links config files from shared to the release path and mongrel path after deployment
desc "Create all symlinks and files needed for app activation ofter deployment"
task :update_config, :roles => :web do
run "ln -s -f /var/www/#{domain}/shared/database.yml #{release_path}/config/database.yml"
run "ln -s -f /var/www/#{domain}/shared/app.yml #{release_path}/config/app.yml"
run "ln -s -f /var/www/#{domain}/shared/cache #{release_path}/public/cache"
run "ln -s -f /var/www/#{domain}/shared/survey_cache #{release_path}/public/surveys"
run "ln -s -f /var/www/#{domain}/shared/surveys #{release_path}/surveys"
end
desc "changes ownership to cbdsm:git"
task :update_permissions, :roles => :web do
sudo "chown -R #{user}:git /var/www/#{domain}"
end
namespace :delayed_job do
desc "Start the delayed_job process"
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job -n 3 start"
end
desc "Stop the delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} script/delayed_job stop"
end
desc "Restart the delayed_job process"
task :restart, :roles => :app do
delayed_job.stop
delayed_job.start
end
end
UPDATE: This seems to be a problem set :use_sudo, true. Removing that line and any commands which require sudo seemed to fix the problem. It's still not entirely clear to me what changed--that made that line problematic. It worked fine before.
Additionally, I removed the default_run_options[:pty] = true line.
As posted above:
This seems to be a problem set :use_sudo, true. Removing that line and any commands which require sudo seemed to fix the problem. It's still not entirely clear to me what changed--that made that line problematic. It worked fine before.
Additionally, I removed the default_run_options[:pty] = true line.
In these cases post the /config/deploy.rb would help...
BTW, how do you set the :deploy_via setting? Try to change this to :remote_cache (from :copy):
set :deploy_via, :remote_cache
and see what happens.

Resources