Last active
December 17, 2015 18:49
-
-
Save finger-berlin/5656362 to your computer and use it in GitHub Desktop.
Capistrano deploy.rb for nginx + rvm + unicorn + delayed_job on Ubuntu LTS 12.x (2013)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capistrano/calendar/recipes' | |
require 'bundler/capistrano' | |
require "rvm/capistrano" | |
load 'deploy/assets' | |
set :user, 'deployuser' | |
set :application, 'applicationname' | |
set :rvm_type, :system | |
set :rvm_ruby_string, "ruby-1.9.3-p392@#{application}" | |
set :bundle_flags, "--deployment --quiet --binstubs --shebang ruby-local-exec" | |
set :deploy_to, "/home/#{user}/#{application}" | |
set :keep_releases, 3 | |
set :rails_env, "production" | |
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb" | |
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid" | |
set :scm, "git" | |
set :scm_command, "git" | |
set :repository, "[email protected]:youraccount/#{application}.git" | |
set :deploy_via, :remote_cache | |
set :scm_verbose, true | |
set :use_sudo, false | |
ssh_options[:forward_agent] = true | |
default_run_options[:pty] = true | |
set :branch, ENV['BRANCH'] ? ENV['BRANCH'] : "master" | |
role :web, "rubystack.yourdomain.com" # Your HTTP server, Apache/etc | |
role :app, "rubystack.yourdomain.com" # This may be the same as your `Web` server | |
role :db, "rubystack.yourdomain.com", :primary => true # This is where Rails migrations will run | |
namespace :deploy do | |
task :start do | |
; | |
end | |
task :stop do | |
; | |
end | |
task :restart, :roles => :app, :except => {:no_release => true} do | |
; | |
end | |
end | |
namespace :serverstuff do | |
desc "link server specific scripts" | |
task :symlink do | |
run "sudo ln -s -f #{current_path}/config/#{application}.nginx.conf /etc/nginx/sites-enabled/#{application}" | |
end | |
desc "reload nginx" | |
task :reload do | |
run "sudo service nginx reload" | |
end | |
after 'deploy:create_symlink', 'serverstuff:symlink' | |
after 'serverstuff:symlink', 'serverstuff:reload' | |
end | |
namespace :unicorn do | |
desc "start unicorn" | |
task :start, :roles => :app, :except => {:no_release => true} do | |
run "cd #{current_path} && unicorn -c #{current_path}/config/unicorn.rb -E #{rails_env} -D" | |
end | |
desc "stop unicorn" | |
task :stop, :roles => :app, :except => {:no_release => true} do | |
run "#{try_sudo} kill -TERM `cat #{unicorn_pid}`" | |
end | |
desc "graceful stop unicorn" | |
task :graceful_stop, :roles => :app, :except => {:no_release => true} do | |
run "#{try_sudo} kill -QUIT `cat #{unicorn_pid}`" | |
end | |
desc "reload unicorn" | |
task :reload, :roles => :app, :except => {:no_release => true} do | |
run "#{try_sudo} kill -HUP `cat #{unicorn_pid}`" | |
end | |
after "deploy:restart", "unicorn:reload" | |
after "deploy:start", "unicorn:start" | |
after "deploy:stop", "unicorn:stop" | |
end | |
namespace :delayed_job do | |
desc "Restart the delayed_job process" | |
task :restart, :roles => :app do | |
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job restart" | |
end | |
task :stop, :roles => :app do | |
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job stop" | |
end | |
task :start, :roles => :app do | |
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job start" | |
end | |
after "unicorn:reload", "delayed_job:restart" | |
after "unicorn:start", "delayed_job:start" | |
after "unicorn:stop", "delayed_job:stop" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment