Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sunny0425/3245368 to your computer and use it in GitHub Desktop.
Save sunny0425/3245368 to your computer and use it in GitHub Desktop.
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
# NOTICE: 不可在此外部使用 current_path,否则将会使用固定此文件下的 deploy_to 或默认的 deploy_to
# set :unicorn_config, "#{current_path}/config/unicorn.rb"
# set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
unicorn_config = "#{current_path}/config/unicorn.rb"
unicorn_pid = "#{current_path}/tmp/pids/unicorn.pid"
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
unicorn_pid = "#{current_path}/tmp/pids/unicorn.pid"
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
unicorn_pid = "#{current_path}/tmp/pids/unicorn.pid"
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
task :reload, :roles => :app, :except => { :no_release => true } do
unicorn_pid = "#{current_path}/tmp/pids/unicorn.pid"
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
stop
start
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment