From b7ea4bd853e4735be68b7438815c02aa56f51a15 Mon Sep 17 00:00:00 2001 From: Qingyu Zhao Date: Wed, 3 Jul 2019 14:11:48 +1000 Subject: [PATCH] Enable puma by default in GDK Two changes: 1. Move bin/web to bin/web_unicorn(removed PUMA switching logic) Introduce new shadow script bin/web. Now we have 3 scripts working together: bin/web, bin/web_puma, bin/web_unicorn In bin/web, it checks ENV['USE_WEB_SERVER']: - if value is 'puma' or value is not set, call bin/web_puma - if value is 'unicorn', call bin/web_unicorn - report error if other values given 2. Gitlab rails allow ENV setting to override timeout - ENV['GITLAB_RAILS_RACK_TIMEOUT'] for service_timeout - ENV['GITLAB_RAILS_WAIT_TIMEOUT'] for wait_timeout --- bin/web | 68 ++++++----------------------- bin/web_unicorn | 58 ++++++++++++++++++++++++ config/initializers/rack_timeout.rb | 4 +- 3 files changed, 73 insertions(+), 57 deletions(-) create mode 100755 bin/web_unicorn diff --git a/bin/web b/bin/web index 06ff7c39296..f640abf0fbc 100755 --- a/bin/web +++ b/bin/web @@ -1,63 +1,21 @@ #!/bin/sh +set -e + cd $(dirname $0)/.. app_root=$(pwd) -# Switch to experimental PUMA configuration -if [ -n "${EXPERIMENTAL_PUMA}" ]; then - exec bin/web_puma "$@" -fi +case "$USE_WEB_SERVER" in + puma|"") # and the "" defines default + exec bin/web_puma "$@" + ;; -unicorn_pidfile="$app_root/tmp/pids/unicorn.pid" -unicorn_config="$app_root/config/unicorn.rb" -unicorn_cmd="bundle exec unicorn_rails -c $unicorn_config -E $RAILS_ENV" + unicorn) + exec bin/web_unicorn "$@" + ;; -get_unicorn_pid() -{ - local pid=$(cat $unicorn_pidfile) - if [ -z "$pid" ] ; then - echo "Could not find a PID in $unicorn_pidfile" - exit 1 - fi - unicorn_pid=$pid -} - -start() -{ - exec $unicorn_cmd -D -} - -start_foreground() -{ - exec $unicorn_cmd -} - -stop() -{ - get_unicorn_pid - kill -QUIT $unicorn_pid -} - -reload() -{ - get_unicorn_pid - kill -USR2 $unicorn_pid -} - -case "$1" in - start) - start - ;; - start_foreground) - start_foreground - ;; - stop) - stop - ;; - reload) - reload - ;; - *) - echo "Usage: RAILS_ENV=your_env $0 {start|stop|reload}" - ;; + *) + echo "Unkown web server used by USE_WEB_SERVER: $USE_WEB_SERVER." + exit 1 + ;; esac diff --git a/bin/web_unicorn b/bin/web_unicorn new file mode 100755 index 00000000000..ecd0bbd10b0 --- /dev/null +++ b/bin/web_unicorn @@ -0,0 +1,58 @@ +#!/bin/sh + +cd $(dirname $0)/.. +app_root=$(pwd) + +unicorn_pidfile="$app_root/tmp/pids/unicorn.pid" +unicorn_config="$app_root/config/unicorn.rb" +unicorn_cmd="bundle exec unicorn_rails -c $unicorn_config -E $RAILS_ENV" + +get_unicorn_pid() +{ + local pid=$(cat $unicorn_pidfile) + if [ -z "$pid" ] ; then + echo "Could not find a PID in $unicorn_pidfile" + exit 1 + fi + unicorn_pid=$pid +} + +start() +{ + exec $unicorn_cmd -D +} + +start_foreground() +{ + exec $unicorn_cmd +} + +stop() +{ + get_unicorn_pid + kill -QUIT $unicorn_pid +} + +reload() +{ + get_unicorn_pid + kill -USR2 $unicorn_pid +} + +case "$1" in + start) + start + ;; + start_foreground) + start_foreground + ;; + stop) + stop + ;; + reload) + reload + ;; + *) + echo "Usage: RAILS_ENV=your_env $0 {start|stop|reload}" + ;; +esac diff --git a/config/initializers/rack_timeout.rb b/config/initializers/rack_timeout.rb index 58f46b55725..246cf3482a4 100644 --- a/config/initializers/rack_timeout.rb +++ b/config/initializers/rack_timeout.rb @@ -14,8 +14,8 @@ if defined?(::Puma) && !Rails.env.test? Gitlab::Application.configure do |config| config.middleware.insert_before(Rack::Runtime, Rack::Timeout, - service_timeout: 60, - wait_timeout: 90) + service_timeout: ENV.fetch('GITLAB_RAILS_RACK_TIMEOUT', 60).to_i, + wait_timeout: ENV.fetch('GITLAB_RAILS_WAIT_TIMEOUT', 90).to_i) end observer = Gitlab::Cluster::RackTimeoutObserver.new