diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index dfd0306..efff72b 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -258,3 +258,14 @@ default['gitlab']['logging']['svlogd_timeout'] = 24 * 60 * 60 # rotate after 24 default['gitlab']['logging']['svlogd_filter'] = "gzip" # compress logs with gzip default['gitlab']['logging']['svlogd_udp'] = nil # transmit log messages via UDP default['gitlab']['logging']['svlogd_prefix'] = nil # custom prefix for log messages + +### +# Remote syslog +### +default['gitlab']['remote-syslog']['enable'] = false +default['gitlab']['remote-syslog']['ha'] = false +default['gitlab']['remote-syslog']['dir'] = "/var/opt/gitlab/remote-syslog" +default['gitlab']['remote-syslog']['log_directory'] = "/var/log/gitlab/remote-syslog" +default['gitlab']['remote-syslog']['destination_host'] = "localhost" +default['gitlab']['remote-syslog']['destination_port'] = 514 +default['gitlab']['remote-syslog']['services'] = %w{redis nginx unicorn gitlab-rails postgresql sidekiq} diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb index b8f6e44..26905b6 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb @@ -44,6 +44,7 @@ module Gitlab sidekiq Mash.new nginx Mash.new logging Mash.new + remote_syslog Mash.new node nil external_url nil git_data_dir nil @@ -132,6 +133,7 @@ module Gitlab "sidekiq", "nginx", "logging", + "remote_syslog", "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 a3c3c0e..178c477 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -70,6 +70,7 @@ include_recipe "runit" "unicorn", "sidekiq", "nginx", + "remote-syslog", "bootstrap", ].each do |service| if node["gitlab"][service]["enable"] diff --git a/files/gitlab-cookbooks/gitlab/recipes/remote-syslog.rb b/files/gitlab-cookbooks/gitlab/recipes/remote-syslog.rb new file mode 100644 index 0000000..8e38270 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/remote-syslog.rb @@ -0,0 +1,48 @@ +# +# Copyright:: Copyright (c) 2014 GitLab B.V. +# 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. +# + +remote_syslog_dir = node['gitlab']['remote-syslog']['dir'] +remote_syslog_log_dir = node['gitlab']['remote-syslog']['log_directory'] + +[ + remote_syslog_dir, + remote_syslog_log_dir +].each do |dir| + directory dir do + mode "0700" + end +end + +template File.join(remote_syslog_dir, "remote_syslog.yml") do + mode "0644" + variables(node['gitlab']['remote-syslog'].to_hash) + notifies :restart, 'service[remote-syslog]' if OmnibusHelper.should_notify?("remote-syslog") +end + +runit_service "remote-syslog" do + down node['gitlab']['remote-syslog']['ha'] + options({ + :log_directory => remote_syslog_log_dir + }.merge(params)) + log_options node['gitlab']['logging'].to_hash.merge(node['gitlab']['remote-syslog'].to_hash) +end + +if node['gitlab']['bootstrap']['enable'] + execute "/opt/gitlab/bin/gitlab-ctl start remote-syslog" do + retries 20 + end +end diff --git a/files/gitlab-cookbooks/gitlab/recipes/remote-syslog_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/remote-syslog_disable.rb new file mode 100644 index 0000000..30a42c2 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/remote-syslog_disable.rb @@ -0,0 +1,20 @@ +# +# 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 "remote-syslog" do + action :disable +end diff --git a/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb b/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb new file mode 100644 index 0000000..c20be2c --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/remote_syslog.yml.erb @@ -0,0 +1,7 @@ +files: +<% @services.each do |service| %> +- <%= File.join(node['gitlab'][service]['log_directory'], "*.log") %> +<% end %> +destination: + host: <%= @destination_host %> + port: <%= @destination_port %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-log-config.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-log-config.erb new file mode 100644 index 0000000..8902097 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-log-config.erb @@ -0,0 +1,6 @@ +<%= "s#@svlogd_size" if @svlogd_size %> +<%= "n#@svlogd_num" if @svlogd_num %> +<%= "t#@svlogd_timeout" if @svlogd_timeout %> +<%= "!#@svlogd_filter" if @svlogd_filter %> +<%= "u#@svlogd_udp" if @svlogd_udp %> +<%= "p#@svlogd_prefix" if @svlogd_prefix %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-log-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-log-run.erb new file mode 100644 index 0000000..c8ab3e3 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-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-remote-syslog-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb new file mode 100644 index 0000000..fe0f013 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb @@ -0,0 +1,3 @@ +#!/bin/sh +exec 2>&1 +exec /opt/gitlab/embedded/bin/remote_syslog --no-detach --debug-level DEBUG -c <%= node['gitlab']['remote-syslog']['dir'] %>/remote_syslog.yml -- libgit2 0.21.2