From d90fd6c46a71723eb2617d337f90c82fc67f6eff Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 2 Aug 2016 21:08:41 -0700 Subject: [PATCH] force unicorn to terminate before restarting --- Capfile | 3 ++- lib/capistrano/tasks/unicorn.cap | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/capistrano/tasks/unicorn.cap diff --git a/Capfile b/Capfile index c2c5f1a21..5b1f4eace 100644 --- a/Capfile +++ b/Capfile @@ -13,4 +13,5 @@ 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:reload" +after "deploy:published", "unicorn:terminate" +after "deploy:published", "unicorn:start" diff --git a/lib/capistrano/tasks/unicorn.cap b/lib/capistrano/tasks/unicorn.cap new file mode 100644 index 000000000..3fbc694bf --- /dev/null +++ b/lib/capistrano/tasks/unicorn.cap @@ -0,0 +1,16 @@ +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 + end + end +end