Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 21:08:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 21:08:10 +0300
commit175b4fa261259ab0d033482d10bb4159fee8e538 (patch)
treee1f1dba5e41177f11ffded5a505e0e7f692b8df5 /lib/gitlab/runtime.rb
parent4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/runtime.rb')
-rw-r--r--lib/gitlab/runtime.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb
new file mode 100644
index 00000000000..07a3afb8834
--- /dev/null
+++ b/lib/gitlab/runtime.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+module Gitlab
+ # Provides routines to identify the current runtime as which the application
+ # executes, such as whether it is an application server and which one.
+ module Runtime
+ class << self
+ def name
+ matches = []
+ matches << :puma if puma?
+ matches << :unicorn if unicorn?
+ matches << :console if console?
+ matches << :sidekiq if sidekiq?
+
+ raise "Ambiguous process match: #{matches}" if matches.size > 1
+
+ matches.first || :unknown
+ end
+
+ def puma?
+ !!(defined?(::Puma) && bin == 'puma')
+ end
+
+ # For unicorn, we need to check for actual server instances to avoid false positives.
+ def unicorn?
+ !!(defined?(::Unicorn) && defined?(::Unicorn::HttpServer))
+ end
+
+ def sidekiq?
+ !!(defined?(::Sidekiq) && Sidekiq.server? && bin == 'sidekiq')
+ end
+
+ def console?
+ !!defined?(::Rails::Console)
+ end
+
+ def app_server?
+ puma? || unicorn?
+ end
+
+ def multi_threaded?
+ puma? || sidekiq?
+ end
+
+ private
+
+ # Some example values from my system:
+ # puma: /data/cache/bundle-2.5/bin/puma
+ # unicorn: unicorn_rails master -E development -c /tmp/unicorn.rb -l 0.0.0.0:8080
+ # sidekiq: /data/cache/bundle-2.5/bin/sidekiq
+ # thin: bin/rails
+ # console: bin/rails
+ def script_name
+ $0
+ end
+
+ def bin
+ File.basename(script_name)
+ end
+ end
+ end
+end