Commit 84440be2c1139c9b8a46ad33cadf6843c3db7068

Authored by Jacob Vosmaer
2 parents 74eedc02 1a6bf5db

Merge branch 'unicorn_service' into 'master'

Unicorn Service
files/gitlab-cookbooks/gitlab/attributes/default.rb
... ... @@ -44,14 +44,7 @@ default['gitlab']['gitlab-core']['ha'] = false
44 44 default['gitlab']['gitlab-core']['dir'] = "/var/opt/gitlab/gitlab-core"
45 45 default['gitlab']['gitlab-core']['log_directory'] = "/var/log/gitlab/gitlab-core"
46 46 default['gitlab']['gitlab-core']['environment'] = 'production'
47   -default['gitlab']['gitlab-core']['listen'] = '127.0.0.1'
48   -default['gitlab']['gitlab-core']['port'] = 8080
49   -default['gitlab']['gitlab-core']['unicorn_socket'] = '/var/opt/gitlab/gitlab-core/tmp/sockets/gitlab.socket'
50   -default['gitlab']['gitlab-core']['tcp_nopush'] = true
51   -default['gitlab']['gitlab-core']['backlog_socket'] = 64
52   -default['gitlab']['gitlab-core']['worker_timeout'] = 30
53 47 default['gitlab']['gitlab-core']['umask'] = "0022"
54   -default['gitlab']['gitlab-core']['worker_processes'] = 2
55 48  
56 49 default['gitlab']['gitlab-core']['repositories_path'] = "/var/opt/gitlab/repositories"
57 50 default['gitlab']['gitlab-core']['satellites_path'] = "/var/opt/gitlab/gitlab-satellites"
... ... @@ -66,6 +59,20 @@ default['gitlab']['gitlab-core']['rate_limit_requests_per_period'] = 10
66 59 default['gitlab']['gitlab-core']['rate_limit_period'] = 60
67 60  
68 61  
  62 +####
  63 +# Unicorn
  64 +####
  65 +default['gitlab']['unicorn']['enable'] = true
  66 +default['gitlab']['unicorn']['log_directory'] = "/var/log/gitlab/unicorn"
  67 +default['gitlab']['unicorn']['worker_processes'] = 2
  68 +default['gitlab']['unicorn']['listen'] = '127.0.0.1'
  69 +default['gitlab']['unicorn']['port'] = 8080
  70 +default['gitlab']['unicorn']['socket'] = '/var/opt/gitlab/gitlab-core/tmp/sockets/gitlab.socket'
  71 +default['gitlab']['unicorn']['tcp_nopush'] = true
  72 +default['gitlab']['unicorn']['backlog_socket'] = 64
  73 +default['gitlab']['unicorn']['worker_timeout'] = 30
  74 +
  75 +
69 76 ###
70 77 # gitlab-shell
71 78 ###
... ...
files/gitlab-cookbooks/gitlab/libraries/gitlab.rb
... ... @@ -29,6 +29,7 @@ module Gitlab
29 29 postgresql Mash.new
30 30 redis Mash.new
31 31 gitlab_core Mash.new
  32 + unicorn Mash.new
32 33 node nil
33 34  
34 35 class << self
... ... @@ -75,6 +76,7 @@ module Gitlab
75 76 "bootstrap",
76 77 "redis",
77 78 "gitlab_core",
  79 + "unicorn",
78 80 "postgresql"
79 81 ].each do |key|
80 82 rkey = key.gsub('_', '-')
... ...
files/gitlab-cookbooks/gitlab/recipes/default.rb
... ... @@ -47,6 +47,13 @@ end
47 47  
48 48 include_recipe "gitlab::users"
49 49 include_recipe "gitlab::gitlab-shell"
  50 +include_recipe "gitlab::gitlab-core"
  51 +
  52 +# Create a dummy unicorn service to receive notifications, in case the
  53 +# gitlab::unicorn is not loaded below.
  54 +service "unicorn" do
  55 + supports []
  56 +end
50 57  
51 58 # Install our runit instance
52 59 include_recipe "runit"
... ... @@ -55,7 +62,7 @@ include_recipe &quot;runit&quot;
55 62 [
56 63 "postgresql",
57 64 "redis",
58   - "gitlab-core",
  65 + "unicorn",
59 66 "bootstrap",
60 67 ].each do |service|
61 68 if node["gitlab"][service]["enable"]
... ...
files/gitlab-cookbooks/gitlab/recipes/gitlab-core.rb
... ... @@ -21,7 +21,6 @@ gitlab_core_dir = node[&#39;gitlab&#39;][&#39;gitlab-core&#39;][&#39;dir&#39;]
21 21 gitlab_core_etc_dir = File.join(gitlab_core_dir, "etc")
22 22 gitlab_core_working_dir = File.join(gitlab_core_dir, "working")
23 23 gitlab_core_tmp_dir = File.join(gitlab_core_dir, "tmp")
24   -gitlab_core_sockets_dir = File.dirname(node['gitlab']['gitlab-core']['unicorn_socket'])
25 24 gitlab_core_public_uploads_dir = node['gitlab']['gitlab-core']['uploads_directory']
26 25 gitlab_core_log_dir = node['gitlab']['gitlab-core']['log_directory']
27 26  
... ... @@ -30,7 +29,6 @@ gitlab_core_log_dir = node[&#39;gitlab&#39;][&#39;gitlab-core&#39;][&#39;log_directory&#39;]
30 29 gitlab_core_etc_dir,
31 30 gitlab_core_working_dir,
32 31 gitlab_core_tmp_dir,
33   - gitlab_core_sockets_dir,
34 32 gitlab_core_public_uploads_dir,
35 33 gitlab_core_log_dir
36 34 ].each do |dir_name|
... ... @@ -41,7 +39,7 @@ gitlab_core_log_dir = node[&#39;gitlab&#39;][&#39;gitlab-core&#39;][&#39;log_directory&#39;]
41 39 end
42 40 end
43 41  
44   -should_notify = OmnibusHelper.should_notify?("gitlab-core")
  42 +should_notify_unicorn = OmnibusHelper.should_notify?("unicorn")
45 43  
46 44 template_symlink File.join(gitlab_core_etc_dir, "secret") do
47 45 link_from File.join(gitlab_core_source_dir, ".secret")
... ... @@ -49,7 +47,7 @@ template_symlink File.join(gitlab_core_etc_dir, &quot;secret&quot;) do
49 47 owner "root"
50 48 group "root"
51 49 mode "0644"
52   - notifies :restart, 'service[gitlab-core]' if should_notify
  50 + notifies :restart, 'service[unicorn]' if should_notify_unicorn
53 51 end
54 52  
55 53 template_symlink File.join(gitlab_core_etc_dir, "database.yml") do
... ... @@ -59,7 +57,7 @@ template_symlink File.join(gitlab_core_etc_dir, &quot;database.yml&quot;) do
59 57 group "root"
60 58 mode "0644"
61 59 variables(node['gitlab']['postgresql'].to_hash)
62   - notifies :restart, 'service[gitlab-core]' if should_notify
  60 + notifies :restart, 'service[unicorn]' if should_notify_unicorn
63 61 end
64 62  
65 63 template_symlink File.join(gitlab_core_etc_dir, "gitlab.yml") do
... ... @@ -69,7 +67,7 @@ template_symlink File.join(gitlab_core_etc_dir, &quot;gitlab.yml&quot;) do
69 67 group "root"
70 68 mode "0644"
71 69 variables(node['gitlab']['gitlab-core'].to_hash)
72   - notifies :restart, 'service[gitlab-core]' if should_notify
  70 + notifies :restart, 'service[unicorn]' if should_notify_unicorn
73 71 end
74 72  
75 73 template_symlink File.join(gitlab_core_etc_dir, "rack_attack.rb") do
... ... @@ -79,7 +77,7 @@ template_symlink File.join(gitlab_core_etc_dir, &quot;rack_attack.rb&quot;) do
79 77 group "root"
80 78 mode "0644"
81 79 variables(node['gitlab']['gitlab-core'].to_hash)
82   - notifies :restart, 'service[gitlab-core]' if should_notify
  80 + notifies :restart, 'service[unicorn]' if should_notify_unicorn
83 81 end
84 82  
85 83 directory node['gitlab']['gitlab-core']['satellites_path'] do
... ... @@ -88,30 +86,6 @@ directory node[&#39;gitlab&#39;][&#39;gitlab-core&#39;][&#39;satellites_path&#39;] do
88 86 recursive true
89 87 end
90 88  
91   -
92   -unicorn_listen_tcp = node['gitlab']['gitlab-core']['listen']
93   -unicorn_listen_tcp << ":#{node['gitlab']['gitlab-core']['port']}"
94   -unicorn_listen_socket = node['gitlab']['gitlab-core']['unicorn_socket']
95   -
96   -unicorn_config File.join(gitlab_core_etc_dir, "unicorn.rb") do
97   - listen(
98   - unicorn_listen_tcp => {
99   - :tcp_nopush => node['gitlab']['gitlab-core']['tcp_nopush']
100   - },
101   - unicorn_listen_socket => {
102   - :backlog => node['gitlab']['gitlab-core']['backlog_socket'],
103   - }
104   - )
105   - worker_timeout node['gitlab']['gitlab-core']['worker_timeout']
106   - working_directory gitlab_core_working_dir
107   - worker_processes node['gitlab']['gitlab-core']['worker_processes']
108   - preload_app true
109   - owner "root"
110   - group "root"
111   - mode "0644"
112   - notifies :restart, 'service[gitlab-core]' if should_notify
113   -end
114   -
115 89 # replace empty directories in the Git repo with symlinks to /var/opt/gitlab
116 90 {
117 91 "/opt/gitlab/embedded/service/gitlab-core/tmp" => gitlab_core_tmp_dir,
... ... @@ -129,17 +103,3 @@ end
129 103 end
130 104  
131 105 execute "chown -R #{node['gitlab']['user']['username']} /opt/gitlab/embedded/service/gitlab-core/public"
132   -
133   -runit_service "gitlab-core" do
134   - down node['gitlab']['gitlab-core']['ha']
135   - options({
136   - :log_directory => gitlab_core_log_dir
137   - }.merge(params))
138   -end
139   -
140   -if node['gitlab']['bootstrap']['enable']
141   - execute "/opt/gitlab/bin/gitlab-ctl start gitlab-core" do
142   - retries 20
143   - end
144   -end
145   -
... ...
files/gitlab-cookbooks/gitlab/recipes/gitlab-core_disable.rb
... ... @@ -1,21 +0,0 @@
1   -#
2   -# Copyright:: Copyright (c) 2012 Opscode, Inc.
3   -# Copyright:: Copyright (c) 2014 GitLab.com
4   -# License:: Apache License, Version 2.0
5   -#
6   -# Licensed under the Apache License, Version 2.0 (the "License");
7   -# you may not use this file except in compliance with the License.
8   -# You may obtain a copy of the License at
9   -#
10   -# http://www.apache.org/licenses/LICENSE-2.0
11   -#
12   -# Unless required by applicable law or agreed to in writing, software
13   -# distributed under the License is distributed on an "AS IS" BASIS,
14   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   -# See the License for the specific language governing permissions and
16   -# limitations under the License.
17   -#
18   -
19   -runit_service "gitlab-core" do
20   - action :disable
21   -end
files/gitlab-cookbooks/gitlab/recipes/unicorn.rb 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +#
  2 +# Copyright:: Copyright (c) 2012 Opscode, Inc.
  3 +# Copyright:: Copyright (c) 2014 GitLab.com
  4 +# License:: Apache License, Version 2.0
  5 +#
  6 +# Licensed under the Apache License, Version 2.0 (the "License");
  7 +# you may not use this file except in compliance with the License.
  8 +# You may obtain a copy of the License at
  9 +#
  10 +# http://www.apache.org/licenses/LICENSE-2.0
  11 +#
  12 +# Unless required by applicable law or agreed to in writing, software
  13 +# distributed under the License is distributed on an "AS IS" BASIS,
  14 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +# See the License for the specific language governing permissions and
  16 +# limitations under the License.
  17 +#
  18 +
  19 +gitlab_core_dir = node['gitlab']['gitlab-core']['dir']
  20 +gitlab_core_etc_dir = File.join(gitlab_core_dir, "etc")
  21 +gitlab_core_working_dir = File.join(gitlab_core_dir, "working")
  22 +
  23 +unicorn_listen_socket = node['gitlab']['unicorn']['socket']
  24 +unicorn_log_dir = node['gitlab']['unicorn']['log_directory']
  25 +unicorn_socket_dir = File.dirname(unicorn_listen_socket)
  26 +
  27 +[
  28 + unicorn_log_dir,
  29 + unicorn_socket_dir
  30 +].each do |dir_name|
  31 + directory dir_name do
  32 + owner node['gitlab']['user']['username']
  33 + mode '0700'
  34 + recursive true
  35 + end
  36 +end
  37 +
  38 +unicorn_listen_tcp = node['gitlab']['unicorn']['listen']
  39 +unicorn_listen_tcp << ":#{node['gitlab']['unicorn']['port']}"
  40 +
  41 +unicorn_config File.join(gitlab_core_etc_dir, "unicorn.rb") do
  42 + listen(
  43 + unicorn_listen_tcp => {
  44 + :tcp_nopush => node['gitlab']['unicorn']['tcp_nopush']
  45 + },
  46 + unicorn_listen_socket => {
  47 + :backlog => node['gitlab']['unicorn']['backlog_socket'],
  48 + }
  49 + )
  50 + worker_timeout node['gitlab']['unicorn']['worker_timeout']
  51 + working_directory gitlab_core_working_dir
  52 + worker_processes node['gitlab']['unicorn']['worker_processes']
  53 + preload_app true
  54 + owner "root"
  55 + group "root"
  56 + mode "0644"
  57 + notifies :restart, 'service[unicorn]' if OmnibusHelper.should_notify?("unicorn")
  58 +end
  59 +
  60 +runit_service "unicorn" do
  61 + down node['gitlab']['unicorn']['ha']
  62 + options({
  63 + :log_directory => unicorn_log_dir
  64 + }.merge(params))
  65 +end
  66 +
  67 +if node['gitlab']['bootstrap']['enable']
  68 + execute "/opt/gitlab/bin/gitlab-ctl start unicorn" do
  69 + retries 20
  70 + end
  71 +end
... ...
files/gitlab-cookbooks/gitlab/recipes/unicorn_disable.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +#
  2 +# Copyright:: Copyright (c) 2012 Opscode, Inc.
  3 +# Copyright:: Copyright (c) 2014 GitLab.com
  4 +# License:: Apache License, Version 2.0
  5 +#
  6 +# Licensed under the Apache License, Version 2.0 (the "License");
  7 +# you may not use this file except in compliance with the License.
  8 +# You may obtain a copy of the License at
  9 +#
  10 +# http://www.apache.org/licenses/LICENSE-2.0
  11 +#
  12 +# Unless required by applicable law or agreed to in writing, software
  13 +# distributed under the License is distributed on an "AS IS" BASIS,
  14 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +# See the License for the specific language governing permissions and
  16 +# limitations under the License.
  17 +#
  18 +
  19 +runit_service "unicorn" do
  20 + action :disable
  21 +end
... ...
files/gitlab-cookbooks/gitlab/templates/default/sv-gitlab-core-log-run.erb
... ... @@ -1,2 +0,0 @@
1   -#!/bin/sh
2   -exec svlogd -tt <%= @options[:log_directory] %>
files/gitlab-cookbooks/gitlab/templates/default/sv-gitlab-core-run.erb
... ... @@ -1,6 +0,0 @@
1   -#!/bin/sh
2   -
3   -cd /opt/gitlab/embedded/service/gitlab-core
4   -
5   -exec 2>&1
6   -exec chpst -P -U <%= node['gitlab']['user']['username'] %> -u <%= node['gitlab']['user']['username'] %> /usr/bin/env HOME="<%= node['gitlab']['gitlab-core']['dir'] %>" /opt/gitlab/embedded/bin/bundle exec unicorn -E <%= node['gitlab']['gitlab-core']['environment'] %> -c <%= File.join(node['gitlab']['gitlab-core']['dir'], "etc", "unicorn.rb") %> /opt/gitlab/embedded/service/gitlab-core/config.ru
files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-log-run.erb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +#!/bin/sh
  2 +exec svlogd -tt <%= @options[:log_directory] %>
... ...
files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/sh
  2 +
  3 +cd /opt/gitlab/embedded/service/gitlab-core
  4 +
  5 +exec 2>&1
  6 +exec chpst -P -U <%= node['gitlab']['user']['username'] %> -u <%= node['gitlab']['user']['username'] %> /usr/bin/env HOME="<%= node['gitlab']['gitlab-core']['dir'] %>" /opt/gitlab/embedded/bin/bundle exec unicorn -E <%= node['gitlab']['gitlab-core']['environment'] %> -c <%= File.join(node['gitlab']['gitlab-core']['dir'], "etc", "unicorn.rb") %> /opt/gitlab/embedded/service/gitlab-core/config.ru
... ...