Commit a483fcda2f9c410a275992f7ff1094f2ee43015f

Authored by Jacob Vosmaer
1 parent 0d138f59

Add sidekiq service

files/gitlab-cookbooks/gitlab/attributes/default.rb
@@ -70,6 +70,13 @@ default['gitlab']['unicorn']['tcp_nopush'] = true @@ -70,6 +70,13 @@ default['gitlab']['unicorn']['tcp_nopush'] = true
70 default['gitlab']['unicorn']['backlog_socket'] = 64 70 default['gitlab']['unicorn']['backlog_socket'] = 64
71 default['gitlab']['unicorn']['worker_timeout'] = 30 71 default['gitlab']['unicorn']['worker_timeout'] = 30
72 72
  73 +####
  74 +# Sidekiq
  75 +####
  76 +default['gitlab']['sidekiq']['enable'] = true
  77 +default['gitlab']['sidekiq']['ha'] = false
  78 +default['gitlab']['sidekiq']['log_directory'] = "/var/log/gitlab/sidekiq"
  79 +
73 80
74 ### 81 ###
75 # gitlab-shell 82 # gitlab-shell
files/gitlab-cookbooks/gitlab/libraries/gitlab.rb
@@ -30,6 +30,7 @@ module Gitlab @@ -30,6 +30,7 @@ module Gitlab
30 redis Mash.new 30 redis Mash.new
31 gitlab_rails Mash.new 31 gitlab_rails Mash.new
32 unicorn Mash.new 32 unicorn Mash.new
  33 + sidekiq Mash.new
33 node nil 34 node nil
34 35
35 class << self 36 class << self
@@ -77,6 +78,7 @@ module Gitlab @@ -77,6 +78,7 @@ module Gitlab
77 "redis", 78 "redis",
78 "gitlab_rails", 79 "gitlab_rails",
79 "unicorn", 80 "unicorn",
  81 + "sidekiq",
80 "postgresql" 82 "postgresql"
81 ].each do |key| 83 ].each do |key|
82 rkey = key.gsub('_', '-') 84 rkey = key.gsub('_', '-')
files/gitlab-cookbooks/gitlab/recipes/default.rb
@@ -49,10 +49,15 @@ include_recipe &quot;gitlab::users&quot; @@ -49,10 +49,15 @@ include_recipe &quot;gitlab::users&quot;
49 include_recipe "gitlab::gitlab-shell" 49 include_recipe "gitlab::gitlab-shell"
50 include_recipe "gitlab::gitlab-rails" 50 include_recipe "gitlab::gitlab-rails"
51 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 [] 52 +# Create dummy unicorn and sidekiq services to receive notifications, in case
  53 +# the corresponding service recipe is not loaded below.
  54 +[
  55 + "unicorn",
  56 + "sidekiq"
  57 +].each do |dummy|
  58 + service dummy do
  59 + supports []
  60 + end
56 end 61 end
57 62
58 # Install our runit instance 63 # Install our runit instance
@@ -63,6 +68,7 @@ include_recipe &quot;runit&quot; @@ -63,6 +68,7 @@ include_recipe &quot;runit&quot;
63 "redis", 68 "redis",
64 "postgresql", # Postgresql depends on Redis because of `rake db:seed_fu` 69 "postgresql", # Postgresql depends on Redis because of `rake db:seed_fu`
65 "unicorn", 70 "unicorn",
  71 + "sidekiq",
66 "bootstrap", 72 "bootstrap",
67 ].each do |service| 73 ].each do |service|
68 if node["gitlab"][service]["enable"] 74 if node["gitlab"][service]["enable"]
files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb
@@ -40,6 +40,7 @@ gitlab_rails_log_dir = node[&#39;gitlab&#39;][&#39;gitlab-rails&#39;][&#39;log_directory&#39;] @@ -40,6 +40,7 @@ gitlab_rails_log_dir = node[&#39;gitlab&#39;][&#39;gitlab-rails&#39;][&#39;log_directory&#39;]
40 end 40 end
41 41
42 should_notify_unicorn = OmnibusHelper.should_notify?("unicorn") 42 should_notify_unicorn = OmnibusHelper.should_notify?("unicorn")
  43 +should_notify_sidekiq = OmnibusHelper.should_notify?("sidekiq")
43 44
44 template_symlink File.join(gitlab_rails_etc_dir, "secret") do 45 template_symlink File.join(gitlab_rails_etc_dir, "secret") do
45 link_from File.join(gitlab_rails_source_dir, ".secret") 46 link_from File.join(gitlab_rails_source_dir, ".secret")
@@ -48,6 +49,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;secret&quot;) do @@ -48,6 +49,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;secret&quot;) do
48 group "root" 49 group "root"
49 mode "0644" 50 mode "0644"
50 notifies :restart, 'service[unicorn]' if should_notify_unicorn 51 notifies :restart, 'service[unicorn]' if should_notify_unicorn
  52 + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq
51 end 53 end
52 54
53 template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do 55 template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do
@@ -58,6 +60,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;database.yml&quot;) do @@ -58,6 +60,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;database.yml&quot;) do
58 mode "0644" 60 mode "0644"
59 variables(node['gitlab']['postgresql'].to_hash) 61 variables(node['gitlab']['postgresql'].to_hash)
60 notifies :restart, 'service[unicorn]' if should_notify_unicorn 62 notifies :restart, 'service[unicorn]' if should_notify_unicorn
  63 + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq
61 end 64 end
62 65
63 template_symlink File.join(gitlab_rails_etc_dir, "gitlab.yml") do 66 template_symlink File.join(gitlab_rails_etc_dir, "gitlab.yml") do
@@ -68,6 +71,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;gitlab.yml&quot;) do @@ -68,6 +71,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;gitlab.yml&quot;) do
68 mode "0644" 71 mode "0644"
69 variables(node['gitlab']['gitlab-rails'].to_hash) 72 variables(node['gitlab']['gitlab-rails'].to_hash)
70 notifies :restart, 'service[unicorn]' if should_notify_unicorn 73 notifies :restart, 'service[unicorn]' if should_notify_unicorn
  74 + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq
71 end 75 end
72 76
73 template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do 77 template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do
@@ -78,6 +82,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;rack_attack.rb&quot;) do @@ -78,6 +82,7 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;rack_attack.rb&quot;) do
78 mode "0644" 82 mode "0644"
79 variables(node['gitlab']['gitlab-rails'].to_hash) 83 variables(node['gitlab']['gitlab-rails'].to_hash)
80 notifies :restart, 'service[unicorn]' if should_notify_unicorn 84 notifies :restart, 'service[unicorn]' if should_notify_unicorn
  85 + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq
81 end 86 end
82 87
83 directory node['gitlab']['gitlab-rails']['satellites_path'] do 88 directory node['gitlab']['gitlab-rails']['satellites_path'] do
files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  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 +sidekiq_log_dir = node['gitlab']['sidekiq']['log_directory']
  20 +
  21 +directory sidekiq_log_dir do
  22 + owner node['gitlab']['user']['username']
  23 + mode '0700'
  24 + recursive true
  25 +end
  26 +
  27 +runit_service "sidekiq" do
  28 + down node['gitlab']['sidekiq']['ha']
  29 + options({
  30 + :log_directory => sidekiq_log_dir
  31 + }.merge(params))
  32 +end
  33 +
  34 +if node['gitlab']['bootstrap']['enable']
  35 + execute "/opt/gitlab/bin/gitlab-ctl start sidekiq" do
  36 + retries 20
  37 + end
  38 +end
files/gitlab-cookbooks/gitlab/recipes/sidekiq_disable.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -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 "sidekiq" do
  20 + action :disable
  21 +end
files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +#!/bin/sh
  2 +exec svlogd -tt <%= @options[:log_directory] %>
files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +#!/bin/sh
  2 +
  3 +cd <%= node['gitlab']['gitlab-rails']['dir'] %>/working
  4 +
  5 +exec 2>&1
  6 +exec chpst -P -U <%= node['gitlab']['user']['username'] %> -u <%= node['gitlab']['user']['username'] %> /usr/bin/env BUNDLE_GEMFILE=/opt/gitlab/embedded/service/gitlab-rails/Gemfile HOME="<%= node['gitlab']['gitlab-rails']['dir'] %>" /opt/gitlab/embedded/bin/bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e <%= node['gitlab']['gitlab-rails']['environment'] %> -r /opt/gitlab/embedded/service/gitlab-rails