Last active
August 29, 2015 13:59
-
-
Save chroju/10531064 to your computer and use it in GitHub Desktop.
Capistrano - lib/capistrano/tasks/unicorn.cap
This file contains hidden or 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
| # vim: set ft=ruby : | |
| namespace :unicorn do | |
| task :environment do | |
| set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" | |
| set :unicorn_config, "#{current_path}/config/unicorn.rb" | |
| set :rails_path, "/Rails-app" | |
| end | |
| def start_unicorn | |
| within current_path do | |
| execute :bundle, :exec, "unicorn_rails -c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D --path #{fetch(:rails_path)}" | |
| end | |
| end | |
| def stop_unicorn | |
| execute :kill, "-s QUIT $(< #{fetch(:unicorn_pid)})" | |
| end | |
| def reload_unicorn | |
| execute :kill, "-s USR2 $(< #{fetch(:unicorn_pid)})" | |
| end | |
| def force_stop_unicorn | |
| execute :kill, "$(< #{fetch(:unicorn_pid)})" | |
| end | |
| desc "Start unicorn server" | |
| task :start => :environment do | |
| on roles(:app) do | |
| start_unicorn | |
| end | |
| end | |
| desc "Stop unicorn server gracefully" | |
| task :stop => :environment do | |
| on roles(:app) do | |
| stop_unicorn | |
| end | |
| end | |
| desc "Restart unicorn server gracefully" | |
| task :restart => :environment do | |
| on roles(:app) do | |
| if test("[ -f #{fetch(:unicorn_pid)} ]") | |
| reload_unicorn | |
| else | |
| start_unicorn | |
| end | |
| end | |
| end | |
| desc "Stop unicorn server immediately" | |
| task :force_stop => :environment do | |
| on roles(:app) do | |
| force_stop_unicorn | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment