From 5a2b69278d021a37dd5616337f4f1f39db84ad9b Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 10 Feb 2014 14:31:33 +0100 Subject: [PATCH] Separate Rails setup from Unicorn service --- files/gitlab-cookbooks/gitlab/attributes/default.rb | 20 +++++++++++++------- files/gitlab-cookbooks/gitlab/libraries/gitlab.rb | 2 ++ files/gitlab-cookbooks/gitlab/recipes/default.rb | 3 ++- files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb | 50 +++++--------------------------------------------- files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb | 21 --------------------- files/gitlab-cookbooks/gitlab/recipes/unicorn.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb | 21 +++++++++++++++++++++ 7 files changed, 96 insertions(+), 74 deletions(-) delete mode 100644 files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb create mode 100644 files/gitlab-cookbooks/gitlab/recipes/unicorn.rb create mode 100644 files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index c1cd5a4..5c1bb70 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -44,14 +44,7 @@ default['gitlab']['gitlab-core']['ha'] = false default['gitlab']['gitlab-core']['dir'] = "/var/opt/gitlab/gitlab-core" default['gitlab']['gitlab-core']['log_directory'] = "/var/log/gitlab/gitlab-core" default['gitlab']['gitlab-core']['environment'] = 'production' -default['gitlab']['gitlab-core']['listen'] = '127.0.0.1' -default['gitlab']['gitlab-core']['port'] = 8080 -default['gitlab']['gitlab-core']['unicorn_socket'] = '/var/opt/gitlab/gitlab-core/tmp/sockets/gitlab.socket' -default['gitlab']['gitlab-core']['tcp_nopush'] = true -default['gitlab']['gitlab-core']['backlog_socket'] = 64 -default['gitlab']['gitlab-core']['worker_timeout'] = 30 default['gitlab']['gitlab-core']['umask'] = "0022" -default['gitlab']['gitlab-core']['worker_processes'] = 2 default['gitlab']['gitlab-core']['repositories_path'] = "/var/opt/gitlab/repositories" default['gitlab']['gitlab-core']['satellites_path'] = "/var/opt/gitlab/gitlab-satellites" @@ -66,6 +59,19 @@ default['gitlab']['gitlab-core']['rate_limit_requests_per_period'] = 10 default['gitlab']['gitlab-core']['rate_limit_period'] = 60 +#### +# Unicorn +#### +default['gitlab']['unicorn']['log_directory'] = "/var/log/gitlab/unicorn" +default['gitlab']['unicorn']['worker_processes'] = 2 +default['gitlab']['unicorn']['listen'] = '127.0.0.1' +default['gitlab']['unicorn']['port'] = 8080 +default['gitlab']['unicorn']['socket'] = '/var/opt/gitlab/gitlab-core/tmp/sockets/gitlab.socket' +default['gitlab']['unicorn']['tcp_nopush'] = true +default['gitlab']['unicorn']['backlog_socket'] = 64 +default['gitlab']['unicorn']['worker_timeout'] = 30 + + ### # gitlab-shell ### diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb index a5c96bd..ed13ff5 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb @@ -29,6 +29,7 @@ module Gitlab postgresql Mash.new redis Mash.new gitlab_core Mash.new + unicorn Mash.new node nil class << self @@ -75,6 +76,7 @@ module Gitlab "bootstrap", "redis", "gitlab_core", + "unicorn", "postgresql" ].each do |key| rkey = key.gsub('_', '-') diff --git a/files/gitlab-cookbooks/gitlab/recipes/default.rb b/files/gitlab-cookbooks/gitlab/recipes/default.rb index 6d8bf53..a954242 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -47,6 +47,7 @@ end include_recipe "gitlab::users" include_recipe "gitlab::gitlab-shell" +include_recipe "gitlab::gitlab-core" # Install our runit instance include_recipe "runit" @@ -55,7 +56,7 @@ include_recipe "runit" [ "postgresql", "redis", - "gitlab-core", + "unicorn", "bootstrap", ].each do |service| if node["gitlab"][service]["enable"] diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb index 6bad1db..9c246e2 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb @@ -21,7 +21,6 @@ gitlab_core_dir = node['gitlab']['gitlab-core']['dir'] gitlab_core_etc_dir = File.join(gitlab_core_dir, "etc") gitlab_core_working_dir = File.join(gitlab_core_dir, "working") gitlab_core_tmp_dir = File.join(gitlab_core_dir, "tmp") -gitlab_core_sockets_dir = File.dirname(node['gitlab']['gitlab-core']['unicorn_socket']) gitlab_core_public_uploads_dir = node['gitlab']['gitlab-core']['uploads_directory'] gitlab_core_log_dir = node['gitlab']['gitlab-core']['log_directory'] @@ -30,7 +29,6 @@ gitlab_core_log_dir = node['gitlab']['gitlab-core']['log_directory'] gitlab_core_etc_dir, gitlab_core_working_dir, gitlab_core_tmp_dir, - gitlab_core_sockets_dir, gitlab_core_public_uploads_dir, gitlab_core_log_dir ].each do |dir_name| @@ -41,7 +39,7 @@ gitlab_core_log_dir = node['gitlab']['gitlab-core']['log_directory'] end end -should_notify = OmnibusHelper.should_notify?("gitlab-core") +should_notify_unicorn = OmnibusHelper.should_notify?("unicorn") template_symlink File.join(gitlab_core_etc_dir, "secret") do link_from File.join(gitlab_core_source_dir, ".secret") @@ -49,7 +47,7 @@ template_symlink File.join(gitlab_core_etc_dir, "secret") do owner "root" group "root" mode "0644" - notifies :restart, 'service[gitlab-core]' if should_notify + notifies :restart, 'service[unicorn]' if should_notify_unicorn end template_symlink File.join(gitlab_core_etc_dir, "database.yml") do @@ -59,7 +57,7 @@ template_symlink File.join(gitlab_core_etc_dir, "database.yml") do group "root" mode "0644" variables(node['gitlab']['postgresql'].to_hash) - notifies :restart, 'service[gitlab-core]' if should_notify + notifies :restart, 'service[unicorn]' if should_notify_unicorn end template_symlink File.join(gitlab_core_etc_dir, "gitlab.yml") do @@ -69,7 +67,7 @@ template_symlink File.join(gitlab_core_etc_dir, "gitlab.yml") do group "root" mode "0644" variables(node['gitlab']['gitlab-core'].to_hash) - notifies :restart, 'service[gitlab-core]' if should_notify + notifies :restart, 'service[unicorn]' if should_notify_unicorn end template_symlink File.join(gitlab_core_etc_dir, "rack_attack.rb") do @@ -79,7 +77,7 @@ template_symlink File.join(gitlab_core_etc_dir, "rack_attack.rb") do group "root" mode "0644" variables(node['gitlab']['gitlab-core'].to_hash) - notifies :restart, 'service[gitlab-core]' if should_notify + notifies :restart, 'service[unicorn]' if should_notify_unicorn end directory node['gitlab']['gitlab-core']['satellites_path'] do @@ -88,30 +86,6 @@ directory node['gitlab']['gitlab-core']['satellites_path'] do recursive true end - -unicorn_listen_tcp = node['gitlab']['gitlab-core']['listen'] -unicorn_listen_tcp << ":#{node['gitlab']['gitlab-core']['port']}" -unicorn_listen_socket = node['gitlab']['gitlab-core']['unicorn_socket'] - -unicorn_config File.join(gitlab_core_etc_dir, "unicorn.rb") do - listen( - unicorn_listen_tcp => { - :tcp_nopush => node['gitlab']['gitlab-core']['tcp_nopush'] - }, - unicorn_listen_socket => { - :backlog => node['gitlab']['gitlab-core']['backlog_socket'], - } - ) - worker_timeout node['gitlab']['gitlab-core']['worker_timeout'] - working_directory gitlab_core_working_dir - worker_processes node['gitlab']['gitlab-core']['worker_processes'] - preload_app true - owner "root" - group "root" - mode "0644" - notifies :restart, 'service[gitlab-core]' if should_notify -end - # replace empty directories in the Git repo with symlinks to /var/opt/gitlab { "/opt/gitlab/embedded/service/gitlab-core/tmp" => gitlab_core_tmp_dir, @@ -129,17 +103,3 @@ end end execute "chown -R #{node['gitlab']['user']['username']} /opt/gitlab/embedded/service/gitlab-core/public" - -runit_service "gitlab-core" do - down node['gitlab']['gitlab-core']['ha'] - options({ - :log_directory => gitlab_core_log_dir - }.merge(params)) -end - -if node['gitlab']['bootstrap']['enable'] - execute "/opt/gitlab/bin/gitlab-ctl start gitlab-core" do - retries 20 - end -end - diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb deleted file mode 100644 index eef2361..0000000 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Copyright:: Copyright (c) 2012 Opscode, Inc. -# Copyright:: Copyright (c) 2014 GitLab.com -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -runit_service "gitlab-core" do - action :disable -end diff --git a/files/gitlab-cookbooks/gitlab/recipes/unicorn.rb b/files/gitlab-cookbooks/gitlab/recipes/unicorn.rb new file mode 100644 index 0000000..f09d039 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/unicorn.rb @@ -0,0 +1,53 @@ +gitlab_core_dir = node['gitlab']['gitlab-core']['dir'] +gitlab_core_etc_dir = File.join(gitlab_core_dir, "etc") +gitlab_core_working_dir = File.join(gitlab_core_dir, "working") + +unicorn_listen_socket = node['gitlab']['unicorn']['socket'] +unicorn_log_dir = node['gitlab']['unicorn']['log_directory'] +unicorn_socket_dir = File.dirname(unicorn_listen_socket) + +[ + unicorn_log_dir, + unicorn_socket_dir +].each do |dir_name| + directory dir_name do + owner node['gitlab']['user']['username'] + mode '0700' + recursive true + end +end + +unicorn_listen_tcp = node['gitlab']['gitlab-core']['listen'] +unicorn_listen_tcp << ":#{node['gitlab']['gitlab-core']['port']}" + +unicorn_config File.join(gitlab_core_etc_dir, "unicorn.rb") do + listen( + unicorn_listen_tcp => { + :tcp_nopush => node['gitlab']['unicorn']['tcp_nopush'] + }, + unicorn_listen_socket => { + :backlog => node['gitlab']['unicorn']['backlog_socket'], + } + ) + worker_timeout node['gitlab']['unicorn']['worker_timeout'] + working_directory gitlab_core_working_dir + worker_processes node['gitlab']['unicorn']['worker_processes'] + preload_app true + owner "root" + group "root" + mode "0644" + notifies :restart, 'service[unicorn]' if OmnibusHelper.should_notify?("unicorn") +end + +runit_service "unicorn" do + down node['gitlab']['unicorn']['ha'] + options({ + :log_directory => unicorn_log_dir + }.merge(params)) +end + +if node['gitlab']['bootstrap']['enable'] + execute "/opt/gitlab/bin/gitlab-ctl start unicorn" do + retries 20 + end +end diff --git a/files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb new file mode 100644 index 0000000..9aa2327 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb @@ -0,0 +1,21 @@ +# +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# Copyright:: Copyright (c) 2014 GitLab.com +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +runit_service "unicorn" do + action :disable +end -- libgit2 0.21.2