deploy.rb for Linode
#$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require 'bundler/capistrano'
require 'rvm/capistrano'
require "capistrano_colors"
require 'thinking_sphinx/deploy/capistrano'
require 'delayed/recipes'
set :normalize_asset_timestamps, false
set :rvm_type, :user
set :rvm_ruby_string, 'ruby-1.9.3-p125@appname'
set :application, "appname"
set :repository, "git@github.com:yourusername/repo.git"
set :deploy_to, "/home/deployfolder"
set :use_sudo, false
ssh_options[:port] = 30000
ssh_options[:forward_agent] = true
set :user, "username"
set :bundle_cmd, "/home/deployfolder/.rvm/gems/ruby-1.9.3-p125/bin/bundle"
set :bundle_flags, "--deployment --quiet --binstubs"
set :scm, :git
role :web, "ip address"
role :app, "ip address"
role :db, "ip address", :primary => true
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart do ; end
end
namespace :uploads do
task :symlink do
run "cp #{shared_path}/database.yml #{release_path}/config"
end
task :restart do
run "if [ -f /home/deployfolder/current/tmp/pids/unicorn.pid ]; then kill -s USR2 `cat /home/deployfolder/current/tmp/pids/unicorn.pid`;fi"
end
end
namespace :compileassets do
desc "Compress assets in a local file"
task :compress_assets do
run_locally("rm -rf public/assets/*")
run_locally("bundle exec rake assets:precompile")
run_locally("touch assets.tgz && rm assets.tgz")
run_locally("tar zcvf assets.tgz public/assets/")
run_locally("mv assets.tgz public/assets/")
end
desc "Upload assets"
task :upload_assets do
upload("public/assets/assets.tgz", release_path + '/assets.tgz')
run "cd #{release_path}; tar zxvf assets.tgz; rm assets.tgz"
end
end
task :before_update_code, :roles => [:app] do
compileassets.compress_assets
thinking_sphinx.stop
end
task :symlink_sphinx_indexes, :roles => [:app] do
run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
end
task :after_update_code, :roles => [:app] do
symlink_sphinx_indexes
thinking_sphinx.configure
thinking_sphinx.start
end
before "deploy:symlink", "compileassets:upload_assets"
after "deploy", "uploads:symlink", "deploy:migrate", "uploads:restart"