From 2b9d48ccd020a4ff62741118be94ab8d8f3b08b9 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 23 Aug 2013 10:28:07 +0200 Subject: [PATCH] Fix the `service gitlab restart` command This commit addresses two related issues: - Sidekiq should shut down completely before we restart it; - If we restart unicorn with USR2 we need to kill the old master and worker processes. --- config/unicorn.rb.example | 26 +++++++++++++------------- lib/support/init.d/gitlab | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config/unicorn.rb.example b/config/unicorn.rb.example index e010de6d6a9..294d521b66e 100644 --- a/config/unicorn.rb.example +++ b/config/unicorn.rb.example @@ -64,19 +64,19 @@ before_fork do |server, worker| # installations. It is not needed if your system can house # twice as many worker_processes as you have configured. # - # # This allows a new master process to incrementally - # # phase out the old master process with SIGTTOU to avoid a - # # thundering herd (especially in the "preload_app false" case) - # # when doing a transparent upgrade. The last worker spawned - # # will then kill off the old master process with a SIGQUIT. - # old_pid = "#{server.config[:pid]}.oldbin" - # if old_pid != server.pid - # begin - # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU - # Process.kill(sig, File.read(old_pid).to_i) - # rescue Errno::ENOENT, Errno::ESRCH - # end - # end + # This allows a new master process to incrementally + # phase out the old master process with SIGTTOU to avoid a + # thundering herd (especially in the "preload_app false" case) + # when doing a transparent upgrade. The last worker spawned + # will then kill off the old master process with a SIGQUIT. + old_pid = "#{server.config[:pid]}.oldbin" + if old_pid != server.pid + begin + sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU + Process.kill(sig, File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + end + end # # Throttle the master from forking too quickly by sleeping. Due # to the implementation of standard Unix signal handlers, this diff --git a/lib/support/init.d/gitlab b/lib/support/init.d/gitlab index 29c9d98965d..6f97643f9e0 100644 --- a/lib/support/init.d/gitlab +++ b/lib/support/init.d/gitlab @@ -81,7 +81,7 @@ restart() { if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then echo "Restarting $DESC..." kill -USR2 `cat $WEB_SERVER_PID` - execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" + execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1" if [ `whoami` = root ]; then execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" fi