From 7cf2dbc15b28554540305ff4c47c5df2f04b4ede Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Aug 2016 22:12:14 -0700 Subject: [PATCH] terminate unicorn procs on deploy --- Capfile | 3 --- lib/capistrano/tasks/unicorn.cap | 13 ++++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Capfile b/Capfile index 5b1f4eace..3e4831f2e 100644 --- a/Capfile +++ b/Capfile @@ -12,6 +12,3 @@ require 'capistrano3/unicorn' # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } - -after "deploy:published", "unicorn:terminate" -after "deploy:published", "unicorn:start" diff --git a/lib/capistrano/tasks/unicorn.cap b/lib/capistrano/tasks/unicorn.cap index 3fbc694bf..1b8fc56f8 100644 --- a/lib/capistrano/tasks/unicorn.cap +++ b/lib/capistrano/tasks/unicorn.cap @@ -2,15 +2,10 @@ namespace :unicorn do desc "Terminate unicorn processes (blocks until complete)" task :terminate do on roles(:app) do - n = 0 - while n < 10 && !capture("pgrep -f unicorn").blank? - execute "pgrep -f unicorn | xargs -SIGTERM" - n += 1 - end - - if n == 10 - execute "pgrep -f unicorn | xargs -SIGKILL" - end + execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGTERM" end end end + +after "deploy:published", "unicorn:terminate" +after "deploy:published", "unicorn:start"