From a483fcda2f9c410a275992f7ff1094f2ee43015f Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 11 Feb 2014 16:24:52 +0100 Subject: [PATCH] Add sidekiq service --- files/gitlab-cookbooks/gitlab/attributes/default.rb | 7 +++++++ files/gitlab-cookbooks/gitlab/libraries/gitlab.rb | 2 ++ files/gitlab-cookbooks/gitlab/recipes/default.rb | 14 ++++++++++---- files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb | 5 +++++ files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb | 38 ++++++++++++++++++++++++++++++++++++++ files/gitlab-cookbooks/gitlab/recipes/sidekiq_disable.rb | 21 +++++++++++++++++++++ files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb | 2 ++ files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb | 6 ++++++ 8 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb create mode 100644 files/gitlab-cookbooks/gitlab/recipes/sidekiq_disable.rb create mode 100644 files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb create mode 100644 files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index d4156e7..791a3d8 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -70,6 +70,13 @@ default['gitlab']['unicorn']['tcp_nopush'] = true default['gitlab']['unicorn']['backlog_socket'] = 64 default['gitlab']['unicorn']['worker_timeout'] = 30 +#### +# Sidekiq +#### +default['gitlab']['sidekiq']['enable'] = true +default['gitlab']['sidekiq']['ha'] = false +default['gitlab']['sidekiq']['log_directory'] = "/var/log/gitlab/sidekiq" + ### # gitlab-shell diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb index fe133b6..353c6bc 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb @@ -30,6 +30,7 @@ module Gitlab redis Mash.new gitlab_rails Mash.new unicorn Mash.new + sidekiq Mash.new node nil class << self @@ -77,6 +78,7 @@ module Gitlab "redis", "gitlab_rails", "unicorn", + "sidekiq", "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 5945315..d6d7291 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -49,10 +49,15 @@ include_recipe "gitlab::users" include_recipe "gitlab::gitlab-shell" include_recipe "gitlab::gitlab-rails" -# Create a dummy unicorn service to receive notifications, in case the -# gitlab::unicorn is not loaded below. -service "unicorn" do - supports [] +# Create dummy unicorn and sidekiq services to receive notifications, in case +# the corresponding service recipe is not loaded below. +[ + "unicorn", + "sidekiq" +].each do |dummy| + service dummy do + supports [] + end end # Install our runit instance @@ -63,6 +68,7 @@ include_recipe "runit" "redis", "postgresql", # Postgresql depends on Redis because of `rake db:seed_fu` "unicorn", + "sidekiq", "bootstrap", ].each do |service| if node["gitlab"][service]["enable"] diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb index a6f0337..716c84c 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb @@ -40,6 +40,7 @@ gitlab_rails_log_dir = node['gitlab']['gitlab-rails']['log_directory'] end should_notify_unicorn = OmnibusHelper.should_notify?("unicorn") +should_notify_sidekiq = OmnibusHelper.should_notify?("sidekiq") template_symlink File.join(gitlab_rails_etc_dir, "secret") do link_from File.join(gitlab_rails_source_dir, ".secret") @@ -48,6 +49,7 @@ template_symlink File.join(gitlab_rails_etc_dir, "secret") do group "root" mode "0644" notifies :restart, 'service[unicorn]' if should_notify_unicorn + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq end template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do @@ -58,6 +60,7 @@ template_symlink File.join(gitlab_rails_etc_dir, "database.yml") do mode "0644" variables(node['gitlab']['postgresql'].to_hash) notifies :restart, 'service[unicorn]' if should_notify_unicorn + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq end template_symlink File.join(gitlab_rails_etc_dir, "gitlab.yml") do @@ -68,6 +71,7 @@ template_symlink File.join(gitlab_rails_etc_dir, "gitlab.yml") do mode "0644" variables(node['gitlab']['gitlab-rails'].to_hash) notifies :restart, 'service[unicorn]' if should_notify_unicorn + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq end template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do @@ -78,6 +82,7 @@ template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do mode "0644" variables(node['gitlab']['gitlab-rails'].to_hash) notifies :restart, 'service[unicorn]' if should_notify_unicorn + notifies :restart, 'service[sidekiq]' if should_notify_sidekiq end directory node['gitlab']['gitlab-rails']['satellites_path'] do diff --git a/files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb b/files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb new file mode 100644 index 0000000..bf6897c --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/sidekiq.rb @@ -0,0 +1,38 @@ +# +# 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. +# + +sidekiq_log_dir = node['gitlab']['sidekiq']['log_directory'] + +directory sidekiq_log_dir do + owner node['gitlab']['user']['username'] + mode '0700' + recursive true +end + +runit_service "sidekiq" do + down node['gitlab']['sidekiq']['ha'] + options({ + :log_directory => sidekiq_log_dir + }.merge(params)) +end + +if node['gitlab']['bootstrap']['enable'] + execute "/opt/gitlab/bin/gitlab-ctl start sidekiq" do + retries 20 + end +end diff --git a/files/gitlab-cookbooks/gitlab/recipes/sidekiq_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/sidekiq_disable.rb new file mode 100644 index 0000000..f89ae32 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/sidekiq_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 "sidekiq" do + action :disable +end diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb new file mode 100644 index 0000000..c8ab3e3 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-log-run.erb @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd -tt <%= @options[:log_directory] %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb new file mode 100644 index 0000000..abfd982 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd <%= node['gitlab']['gitlab-rails']['dir'] %>/working + +exec 2>&1 +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 -- libgit2 0.21.2