Module: CapistranoDeployManagement::Unicorn

Defined in:
lib/capistrano-deploy-management/unicorn.rb

Class Method Summary collapse

Class Method Details

.load_into(configuration) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capistrano-deploy-management/unicorn.rb', line 3

def self.load_into(configuration)
  configuration.load do

    set(:unicorn_config)  { "#{current_path}/config/unicorn.rb" }
    set(:unicorn_pidfile) { "#{previous_release}/tmp/pids/unicorn.pid" }

    namespace :unicorn do
      desc 'Restart unicorn.'
      task :restart, :roles => :app do
        # run "if [ -f #{unicorn_pidfile} ] && [ -e $(cat #{unicorn_pidfile}) ]; then #{try_sudo} kill -s USR2 $(cat #{unicorn_pidfile}); else cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D; fi"
        unicorn.stop
        unicorn.start
      end

      desc 'Start unicorn.'
      task :start, :roles => :app do
        run "cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
      end

      desc 'Stop unicorn.'
      task :stop, :roles => :app do
        run "cd #{current_path} && test -s #{unicorn_pidfile} && #{try_sudo} kill -QUIT $(cat #{unicorn_pidfile}) || echo 'Unicorn not running. Nothing to kill.'"
      end
    end

    after 'deploy:restart', 'unicorn:restart'

  end
end