From 075d62bfd9e795f458749d2e9f32f1dba964d971 Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Thu, 13 Jun 2019 11:36:55 +0200 Subject: Attach the Puma Worker Killer through Lifecycle Events This approach is the new favoured way of attaching lifecycle events, as it does not require additional changes to be made to the puma.rb file in GitLab-CE, Omnibus and Cloud Native GitLab. If these changes are not synchronized, they may fail in certain environments. Moving to lifecycle events avoids having to do this. Additionally, this change will only install the puma-worker-killer when Puma is running in multi-process mode. Puma can also run in single process mode. In this mode, the puma-worker-killer would be ineffective. --- .../unreleased/an-move-puma-killer-to-an-initializer.yml | 5 +++++ config/initializers/puma.rb | 11 +++++++++++ config/puma.example.development.rb | 3 --- config/puma.rb.example | 4 ---- lib/gitlab/cluster/lifecycle_events.rb | 2 -- 5 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 changelogs/unreleased/an-move-puma-killer-to-an-initializer.yml create mode 100644 config/initializers/puma.rb diff --git a/changelogs/unreleased/an-move-puma-killer-to-an-initializer.yml b/changelogs/unreleased/an-move-puma-killer-to-an-initializer.yml new file mode 100644 index 00000000000..5a38bb2e339 --- /dev/null +++ b/changelogs/unreleased/an-move-puma-killer-to-an-initializer.yml @@ -0,0 +1,5 @@ +--- +title: Attach the Puma Worker Killer through Lifecycle Events +merge_request: 29594 +author: +type: other diff --git a/config/initializers/puma.rb b/config/initializers/puma.rb new file mode 100644 index 00000000000..bf56be41b9b --- /dev/null +++ b/config/initializers/puma.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "gitlab/cluster/lifecycle_events" + +if Gitlab::Cluster::LifecycleEvents.in_clustered_puma? + unless ENV['DISABLE_PUMA_WORKER_KILLER'] + require "gitlab/cluster/puma_worker_killer_initializer" + + Gitlab::Cluster::PumaWorkerKillerInitializer.start @config.options unless ENV['DISABLE_PUMA_WORKER_KILLER'] + end +end diff --git a/config/puma.example.development.rb b/config/puma.example.development.rb index 9df24bf74e3..061825d866e 100644 --- a/config/puma.example.development.rb +++ b/config/puma.example.development.rb @@ -49,9 +49,6 @@ on_restart do end before_fork do - # Signal to the puma killer - Gitlab::Cluster::PumaWorkerKillerInitializer.start @config.options unless ENV['DISABLE_PUMA_WORKER_KILLER'] - # Signal application hooks that we're about to fork Gitlab::Cluster::LifecycleEvents.do_before_fork end diff --git a/config/puma.rb.example b/config/puma.rb.example index 6558dbc6cfe..4d1dcef30b6 100644 --- a/config/puma.rb.example +++ b/config/puma.rb.example @@ -36,7 +36,6 @@ bind 'unix:///home/git/gitlab/tmp/sockets/gitlab.socket' workers 3 require_relative "/home/git/gitlab/lib/gitlab/cluster/lifecycle_events" -require_relative "/home/git/gitlab/lib/gitlab/cluster/puma_worker_killer_initializer" on_restart do # Signal application hooks that we're about to restart @@ -44,9 +43,6 @@ on_restart do end before_fork do - # Signal to the puma killer - Gitlab::Cluster::PumaWorkerKillerInitializer.start @config.options unless ENV['DISABLE_PUMA_WORKER_KILLER'] - # Signal application hooks that we're about to fork Gitlab::Cluster::LifecycleEvents.do_before_fork end diff --git a/lib/gitlab/cluster/lifecycle_events.rb b/lib/gitlab/cluster/lifecycle_events.rb index e0f9eb59924..1bd3bb942c7 100644 --- a/lib/gitlab/cluster/lifecycle_events.rb +++ b/lib/gitlab/cluster/lifecycle_events.rb @@ -80,8 +80,6 @@ module Gitlab @puma_options = options end - private - def in_clustered_environment? # Sidekiq doesn't fork return false if Sidekiq.server? -- cgit v1.2.1