Commit 5a2b69278d021a37dd5616337f4f1f39db84ad9b

Authored by Jacob Vosmaer
1 parent 74eedc02

Separate Rails setup from 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,19 @@ 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']['log_directory'] = "/var/log/gitlab/unicorn"
  66 +default['gitlab']['unicorn']['worker_processes'] = 2
  67 +default['gitlab']['unicorn']['listen'] = '127.0.0.1'
  68 +default['gitlab']['unicorn']['port'] = 8080
  69 +default['gitlab']['unicorn']['socket'] = '/var/opt/gitlab/gitlab-core/tmp/sockets/gitlab.socket'
  70 +default['gitlab']['unicorn']['tcp_nopush'] = true
  71 +default['gitlab']['unicorn']['backlog_socket'] = 64
  72 +default['gitlab']['unicorn']['worker_timeout'] = 30
  73 +
  74 +
69 75 ###
70 76 # gitlab-shell
71 77 ###
... ...
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,7 @@ end
47 47  
48 48 include_recipe "gitlab::users"
49 49 include_recipe "gitlab::gitlab-shell"
  50 +include_recipe "gitlab::gitlab-core"
50 51  
51 52 # Install our runit instance
52 53 include_recipe "runit"
... ... @@ -55,7 +56,7 @@ include_recipe &quot;runit&quot;
55 56 [
56 57 "postgresql",
57 58 "redis",
58   - "gitlab-core",
  59 + "unicorn",
59 60 "bootstrap",
60 61 ].each do |service|
61 62 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,53 @@
  1 +gitlab_core_dir = node['gitlab']['gitlab-core']['dir']
  2 +gitlab_core_etc_dir = File.join(gitlab_core_dir, "etc")
  3 +gitlab_core_working_dir = File.join(gitlab_core_dir, "working")
  4 +
  5 +unicorn_listen_socket = node['gitlab']['unicorn']['socket']
  6 +unicorn_log_dir = node['gitlab']['unicorn']['log_directory']
  7 +unicorn_socket_dir = File.dirname(unicorn_listen_socket)
  8 +
  9 +[
  10 + unicorn_log_dir,
  11 + unicorn_socket_dir
  12 +].each do |dir_name|
  13 + directory dir_name do
  14 + owner node['gitlab']['user']['username']
  15 + mode '0700'
  16 + recursive true
  17 + end
  18 +end
  19 +
  20 +unicorn_listen_tcp = node['gitlab']['gitlab-core']['listen']
  21 +unicorn_listen_tcp << ":#{node['gitlab']['gitlab-core']['port']}"
  22 +
  23 +unicorn_config File.join(gitlab_core_etc_dir, "unicorn.rb") do
  24 + listen(
  25 + unicorn_listen_tcp => {
  26 + :tcp_nopush => node['gitlab']['unicorn']['tcp_nopush']
  27 + },
  28 + unicorn_listen_socket => {
  29 + :backlog => node['gitlab']['unicorn']['backlog_socket'],
  30 + }
  31 + )
  32 + worker_timeout node['gitlab']['unicorn']['worker_timeout']
  33 + working_directory gitlab_core_working_dir
  34 + worker_processes node['gitlab']['unicorn']['worker_processes']
  35 + preload_app true
  36 + owner "root"
  37 + group "root"
  38 + mode "0644"
  39 + notifies :restart, 'service[unicorn]' if OmnibusHelper.should_notify?("unicorn")
  40 +end
  41 +
  42 +runit_service "unicorn" do
  43 + down node['gitlab']['unicorn']['ha']
  44 + options({
  45 + :log_directory => unicorn_log_dir
  46 + }.merge(params))
  47 +end
  48 +
  49 +if node['gitlab']['bootstrap']['enable']
  50 + execute "/opt/gitlab/bin/gitlab-ctl start unicorn" do
  51 + retries 20
  52 + end
  53 +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
... ...