Skip to content

Instantly share code, notes, and snippets.

@Olefine
Forked from ryancheung/deploy.rb
Created August 30, 2013 21:03
Show Gist options
  • Save Olefine/6394255 to your computer and use it in GitHub Desktop.
Save Olefine/6394255 to your computer and use it in GitHub Desktop.
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "git@github.com:ryancheung/blog.git"
set :scm, :git
set :user, 'ryan'
set :use_sudo, false
set :deploy_to, "/var/apps/#{application}"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "ubuntu-server" # Your HTTP server, Apache/etc
role :app, "ubuntu-server" # This may be the same as your `Web` server
role :db, "ubuntu-server", :primary => true # This is where Rails migrations will run
set :rails_env, 'production'
# 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
namespace :deploy do
task :start, :roles => :app do
run "cd #{deploy_to}/current/; RAILS_ENV=#{rails_env} ./unicorn.sh start"
end
task :stop, :roles => :app do
run "cd #{deploy_to}/current/; RAILS_ENV=#{rails_env} ./unicorn.sh stop"
end
desc "Restart Application"
task :restart, :roles => :app do
run "cd #{deploy_to}/current/; RAILS_ENV=#{rails_env} ./unicorn.sh restart"
end
end
namespace :resque do
desc "Start resque worker"
task :start, :roles => :db do
run "cd #{deploy_to}/current/; RAILS_ENV=production PIDFILE=./tmp/pids/resque.pid BACKGROUND=yes QUEUE=* bundle exec rake resque:work"
end
desc "Stop resque worker"
task :stop, :roles => :db do
run "cd #{deploy_to}/current/; kill -QUIT $(cat ./tmp/pids/resque.pid)"
end
desc "Restart resque worker"
task :restart do
run "cd #{deploy_to}/current/; kill -QUIT $(cat ./tmp/pids/resque.pid)"
run "cd #{deploy_to}/current/; RAILS_ENV=production PIDFILE=./tmp/pids/resque.pid BACKGROUND=yes QUEUE=* bundle exec rake resque:work"
end
desc "Start resque scheduler worker"
task :start_scheduler, :roles => :db do
run "cd #{deploy_to}/current/; RAILS_ENV=production PIDFILE=./tmp/pids/resque_scheduler.pid BACKGROUND=yes QUEUE=* bundle exec rake resque:scheduler"
end
desc "Stop resque scheduler worker"
task :stop_scheduler, :roles => :db do
run "cd #{deploy_to}/current/; kill $(cat ./tmp/pids/resque_scheduler.pid)"
end
desc "Restart resque scheduler worker"
task :restart_scheduler, :roles => :db do
run "cd #{deploy_to}/current/; kill $(cat ./tmp/pids/resque_scheduler.pid)"
run "cd #{deploy_to}/current/; RAILS_ENV=production PIDFILE=./tmp/pids/resque_scheduler.pid BACKGROUND=yes QUEUE=* bundle exec rake resque:scheduler"
end
end
after "deploy:restart", "resque:restart"
after "resque:restart", "resque:restart_scheduler"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment