# HG changeset patch
# User Balasankar C <balasankar@gitlab.com>
# Date 1509113925 0
#      Fri Oct 27 14:18:45 2017 +0000
# Node ID c7c58a3ccb6c672fb7b931789a187b94ad2908c2
# Parent  cb81d57ab6cfe4fd0f9f5f45ecd2dd964ab7106a
Extract gitaly to own cookbook

diff --git a/Rakefile b/Rakefile
--- a/Rakefile
+++ b/Rakefile
@@ -17,6 +17,7 @@
                'files/gitlab-cookbooks/runit',
                'files/gitlab-cookbooks/package',
                'files/gitlab-cookbooks/registry',
+               'files/gitlab-cookbooks/gitaly',
                'files/gitlab-cookbooks/repmgr',
                'files/gitlab-cookbooks/mattermost',
                'files/gitlab-cookbooks/gitlab/attributes',
diff --git a/files/gitlab-cookbooks/gitaly/attributes/default.rb b/files/gitlab-cookbooks/gitaly/attributes/default.rb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/attributes/default.rb
@@ -0,0 +1,16 @@
+default['gitaly']['enable'] = false
+default['gitaly']['ha'] = false
+default['gitaly']['dir'] = "/var/opt/gitlab/gitaly"
+default['gitaly']['log_directory'] = "/var/log/gitlab/gitaly"
+default['gitaly']['env_directory'] = "/opt/gitlab/etc/gitaly"
+default['gitaly']['bin_path'] = "/opt/gitlab/embedded/bin/gitaly"
+default['gitaly']['socket_path'] = "#{node['gitaly']['dir']}/gitaly.socket"
+default['gitaly']['listen_addr'] = nil
+default['gitaly']['prometheus_listen_addr'] = nil
+default['gitaly']['logging_format'] = nil
+default['gitaly']['logging_sentry_dsn'] = nil
+default['gitaly']['prometheus_grpc_latency_buckets'] = nil
+default['gitaly']['storage'] = []
+default['gitaly']['auth_token'] = nil
+default['gitaly']['auth_transitioning'] = false
+default['gitaly']['concurrency'] = nil
diff --git a/files/gitlab-cookbooks/gitaly/libraries/gitaly.rb b/files/gitlab-cookbooks/gitaly/libraries/gitaly.rb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/libraries/gitaly.rb
@@ -0,0 +1,42 @@
+#
+# Copyright:: Copyright (c) 2017 GitLab Inc.
+# 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.
+#
+
+module Gitaly
+  class << self
+    def gitaly_address
+      socket_path = user_config['socket_path'] || package_default['socket_path']
+      listen_addr = user_config['listen_addr'] || package_default['listen_addr']
+
+      # Default to using socket path if available
+      if socket_path && !socket_path.empty?
+        "unix:#{socket_path}"
+      elsif listen_addr && !listen_addr.empty?
+        "tcp://#{listen_addr}"
+      end
+    end
+
+    private
+
+    def user_config
+      Gitlab['gitaly']
+    end
+
+    def package_default
+      Gitlab['node']['gitaly'].to_hash
+    end
+  end
+end
diff --git a/files/gitlab-cookbooks/gitaly/metadata.rb b/files/gitlab-cookbooks/gitaly/metadata.rb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/metadata.rb
@@ -0,0 +1,13 @@
+name 'gitaly'
+maintainer 'GitLab.com'
+maintainer_email 'support@gitlab.com'
+license 'Apache 2.0'
+description 'Installs/Configures Gitaly'
+long_description 'Installs/Configures Gitaly'
+version '0.1.0'
+chef_version '>= 12.1' if respond_to?(:chef_version)
+
+issues_url 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues'
+source_url 'https://gitlab.com/gitlab-org/omnibus-gitlab'
+
+depends 'package'
diff --git a/files/gitlab-cookbooks/gitaly/recipes/disable.rb b/files/gitlab-cookbooks/gitaly/recipes/disable.rb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/recipes/disable.rb
@@ -0,0 +1,20 @@
+#
+# Copyright:: Copyright (c) 2016 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.
+#
+
+runit_service "gitaly" do
+  action :disable
+end
diff --git a/files/gitlab-cookbooks/gitaly/recipes/enable.rb b/files/gitlab-cookbooks/gitaly/recipes/enable.rb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/recipes/enable.rb
@@ -0,0 +1,79 @@
+#
+# Copyright:: Copyright (c) 2017 GitLab Inc.
+# 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.
+#
+account_helper = AccountHelper.new(node)
+
+working_dir = node['gitaly']['dir']
+log_directory = node['gitaly']['log_directory']
+env_directory = node['gitaly']['env_directory']
+config_path = File.join(working_dir, "config.toml")
+
+directory working_dir do
+  owner account_helper.gitlab_user
+  mode '0700'
+  recursive true
+end
+
+directory log_directory do
+  owner account_helper.gitlab_user
+  mode '0700'
+  recursive true
+end
+
+# Doing this in attributes/default.rb will need gitlab cookbook to be loaded
+# before gitaly cookbook. This means gitaly cookbook has to depend on gitlab
+# cookbook.  Since gitlab cookbook already depends on gitaly cookbook, this
+# causes a circular dependency. To avoid it, the default value is set in the
+# recipe itself.
+node.default.gitaly.env = {
+  'HOME' => node['gitlab']['user']['home'],
+  'PATH' => "#{node['package']['install-dir']}/bin:#{node['package']['install-dir']}/embedded/bin:/bin:/usr/bin",
+  'TZ' => ':/etc/localtime'
+}
+
+env_dir env_directory do
+  variables node['gitaly']['env']
+  restarts ["service[gitaly]"]
+end
+
+template "Create Gitaly config.toml" do
+  path config_path
+  source "gitaly-config.toml.erb"
+  owner "root"
+  group "root"
+  mode "0644"
+  variables node['gitaly'].to_hash
+  notifies :restart, "service[gitaly]"
+end
+
+runit_service 'gitaly' do
+  down node['gitaly']['ha']
+  options({
+    user: account_helper.gitlab_user,
+    working_dir: working_dir,
+    env_dir: env_directory,
+    bin_path: node['gitaly']['bin_path'],
+    config_path: config_path,
+    log_directory: log_directory
+  }.merge(params))
+  log_options node['gitlab']['logging'].to_hash.merge(node['gitaly'].to_hash)
+end
+
+if node['gitlab']['bootstrap']['enable']
+  execute "/opt/gitlab/bin/gitlab-ctl start gitaly" do
+    retries 20
+  end
+end
diff --git a/files/gitlab-cookbooks/gitaly/templates/default/gitaly-config.toml.erb b/files/gitlab-cookbooks/gitaly/templates/default/gitaly-config.toml.erb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/templates/default/gitaly-config.toml.erb
@@ -0,0 +1,63 @@
+# Gitaly configuration file
+# This file is managed by gitlab-ctl. Manual changes will be
+# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
+# and run:
+# sudo gitlab-ctl reconfigure
+
+socket_path = '<%= @socket_path %>'
+
+<% if @listen_addr %>
+# Optional: listen on a TCP socket. This is insecure (no authentication)
+listen_addr = '<%= @listen_addr %>'
+<% end %>
+
+<% if @prometheus_listen_addr %>
+# Optional: export metrics via Prometheus
+prometheus_listen_addr = '<%= @prometheus_listen_addr %>'
+<% end %>
+
+<% @storage.each do |shard| %>
+[[storage]]
+<% if shard.has_key?('name') %>
+name = '<%= shard['name'] %>'
+<% end %>
+<% if shard.has_key?('path') %>
+path = '<%= shard['path'] %>'
+<% end %>
+<% end %>
+
+[logging]
+<% if @logging_format %>
+format = '<%= @logging_format %>'
+<% end %>
+<% if @logging_sentry_dsn %>
+sentry_dsn = '<%= @logging_sentry_dsn %>'
+<% end %>
+
+<% if @prometheus_grpc_latency_buckets %>
+# # You can optionally configure Gitaly to record histogram latencies on GRPC method calls
+[prometheus]
+grpc_latency_buckets = <%= @prometheus_grpc_latency_buckets %>
+<% end %>
+
+[auth]
+<% if @auth_token %>
+token = '<%= @auth_token %>'
+<% end %>
+<% if @auth_transitioning %>
+transitioning = <%= @auth_transitioning %>
+<% end %>
+
+[gitaly-ruby]
+dir = "/opt/gitlab/embedded/service/gitaly-ruby"
+
+[gitlab-shell]
+dir = "/opt/gitlab/embedded/service/gitlab-shell"
+<% if @concurrency %>
+  <% @concurrency.each do |endpoint| %>
+
+[[concurrency]]
+rpc = "<%= endpoint['rpc'] %>"
+max_per_repo = <%= endpoint['max_per_repo'] %>
+  <% end %>
+<% end %>
diff --git a/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-log-config.erb b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-log-config.erb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-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/gitaly/templates/default/sv-gitaly-log-run.erb b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-log-run.erb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-log-run.erb
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec svlogd -tt <%= @options[:log_directory] %>
diff --git a/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-run.erb b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-run.erb
new file mode 100644
--- /dev/null
+++ b/files/gitlab-cookbooks/gitaly/templates/default/sv-gitaly-run.erb
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -e # fail on errors
+
+# Redirect stderr -> stdout
+exec 2>&1
+
+<%= render("mount_point_check.erb", cookbook: 'gitlab') %>
+
+cd <%= @options[:working_dir] %>
+
+exec chpst -e <%= @options[:env_dir] %> -P \
+  -U <%= @options[:user] %> \
+  -u <%= @options[:user] %> \
+  <%= @options[:bin_path] %> <%= @options[:config_path] %>
diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb
--- a/files/gitlab-cookbooks/gitlab/attributes/default.rb
+++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb
@@ -782,31 +782,6 @@
 default['gitlab']['prometheus-monitoring']['enable'] = true
 
 ####
-# Gitaly
-####
-default['gitlab']['gitaly']['enable'] = false
-default['gitlab']['gitaly']['ha'] = false
-default['gitlab']['gitaly']['dir'] = "/var/opt/gitlab/gitaly"
-default['gitlab']['gitaly']['log_directory'] = "/var/log/gitlab/gitaly"
-default['gitlab']['gitaly']['env_directory'] = "/opt/gitlab/etc/gitaly"
-default['gitlab']['gitaly']['env'] = {
-  'PATH' => "#{node['package']['install-dir']}/bin:#{node['package']['install-dir']}/embedded/bin:/bin:/usr/bin",
-  'HOME' => node['gitlab']['user']['home'],
-  'TZ' => ':/etc/localtime'
-}
-default['gitlab']['gitaly']['bin_path'] = "/opt/gitlab/embedded/bin/gitaly"
-default['gitlab']['gitaly']['socket_path'] = "#{node['gitlab']['gitaly']['dir']}/gitaly.socket"
-default['gitlab']['gitaly']['listen_addr'] = nil
-default['gitlab']['gitaly']['prometheus_listen_addr'] = nil
-default['gitlab']['gitaly']['logging_format'] = nil
-default['gitlab']['gitaly']['logging_sentry_dsn'] = nil
-default['gitlab']['gitaly']['prometheus_grpc_latency_buckets'] = nil
-default['gitlab']['gitaly']['storage'] = []
-default['gitlab']['gitaly']['auth_token'] = nil
-default['gitlab']['gitaly']['auth_transitioning'] = false
-default['gitlab']['gitaly']['concurrency'] = nil
-
-####
 # Geo (EE-only)
 ####
 default['gitlab']['gitlab-rails']['geo_primary_role_enabled'] = false
diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitaly.rb b/files/gitlab-cookbooks/gitlab/libraries/gitaly.rb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/libraries/gitaly.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright:: Copyright (c) 2017 GitLab Inc.
-# 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.
-#
-
-module Gitaly
-  class << self
-    def gitaly_address
-      socket_path = user_config['socket_path'] || package_default['socket_path']
-      listen_addr = user_config['listen_addr'] || package_default['listen_addr']
-
-      # Default to using socket path if available
-      if socket_path && !socket_path.empty?
-        "unix:#{socket_path}"
-      elsif listen_addr && !listen_addr.empty?
-        "tcp://#{listen_addr}"
-      else
-        nil
-      end
-    end
-
-    private
-
-    def user_config
-      Gitlab['gitaly']
-    end
-
-    def package_default
-      Gitlab['node']['gitlab']['gitaly'].to_hash
-    end
-  end
-end
diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb
--- a/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb
+++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab_rails.rb
@@ -15,7 +15,7 @@
 #
 
 require_relative 'nginx.rb'
-require_relative 'gitaly.rb'
+require_relative '../../gitaly/libraries/gitaly.rb'
 
 module GitlabRails
   class << self
diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab_shell.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab_shell.rb
--- a/files/gitlab-cookbooks/gitlab/libraries/gitlab_shell.rb
+++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab_shell.rb
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-require_relative 'gitaly.rb'
+require_relative '../../gitaly/libraries/gitaly.rb'
 
 module GitlabShell
   class << self
diff --git a/files/gitlab-cookbooks/gitlab/metadata.rb b/files/gitlab-cookbooks/gitlab/metadata.rb
--- a/files/gitlab-cookbooks/gitlab/metadata.rb
+++ b/files/gitlab-cookbooks/gitlab/metadata.rb
@@ -13,3 +13,4 @@
 depends 'registry'
 depends 'mattermost'
 depends 'consul'
+depends 'gitaly'
diff --git a/files/gitlab-cookbooks/gitlab/recipes/default.rb b/files/gitlab-cookbooks/gitlab/recipes/default.rb
--- a/files/gitlab-cookbooks/gitlab/recipes/default.rb
+++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb
@@ -113,7 +113,6 @@
 [
   "unicorn",
   "sidekiq",
-  "gitaly",
   "gitlab-workhorse",
   "mailroom",
   "nginx",
@@ -131,6 +130,7 @@
 
 %w(
   registry
+  gitaly
   mattermost
 ).each do |service|
   if node[service]["enable"]
diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitaly.rb b/files/gitlab-cookbooks/gitlab/recipes/gitaly.rb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/recipes/gitaly.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Copyright:: Copyright (c) 2017 GitLab Inc.
-# 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.
-#
-account_helper = AccountHelper.new(node)
-
-working_dir = node['gitlab']['gitaly']['dir']
-log_directory = node['gitlab']['gitaly']['log_directory']
-env_directory = node['gitlab']['gitaly']['env_directory']
-config_path = File.join(working_dir, "config.toml")
-
-directory working_dir do
-  owner account_helper.gitlab_user
-  mode '0700'
-  recursive true
-end
-
-directory log_directory do
-  owner account_helper.gitlab_user
-  mode '0700'
-  recursive true
-end
-
-env_dir env_directory do
-  variables node['gitlab']['gitaly']['env']
-  restarts ["service[gitaly]"]
-end
-
-template "Create Gitaly config.toml" do
-  path config_path
-  source "gitaly-config.toml.erb"
-  owner "root"
-  group "root"
-  mode "0644"
-  variables node['gitlab']['gitaly'].to_hash
-  notifies :restart, "service[gitaly]"
-end
-
-runit_service 'gitaly' do
-  down node['gitlab']['gitaly']['ha']
-  options({
-    user: account_helper.gitlab_user,
-    working_dir: working_dir,
-    env_dir: env_directory,
-    bin_path: node['gitlab']['gitaly']['bin_path'],
-    config_path: config_path,
-    log_directory: log_directory
-  }.merge(params))
-  log_options node['gitlab']['logging'].to_hash.merge(node['gitlab']['gitaly'].to_hash)
-end
-
-if node['gitlab']['bootstrap']['enable']
-  execute "/opt/gitlab/bin/gitlab-ctl start gitaly" do
-    retries 20
-  end
-end
diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitaly_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/gitaly_disable.rb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/recipes/gitaly_disable.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Copyright:: Copyright (c) 2016 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.
-#
-
-runit_service "gitaly" do
-  action :disable
-end
diff --git a/files/gitlab-cookbooks/gitlab/templates/default/gitaly-config.toml.erb b/files/gitlab-cookbooks/gitlab/templates/default/gitaly-config.toml.erb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/templates/default/gitaly-config.toml.erb
+++ /dev/null
@@ -1,63 +0,0 @@
-# Gitaly configuration file
-# This file is managed by gitlab-ctl. Manual changes will be
-# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
-# and run:
-# sudo gitlab-ctl reconfigure
-
-socket_path = '<%= @socket_path %>'
-
-<% if @listen_addr %>
-# Optional: listen on a TCP socket. This is insecure (no authentication)
-listen_addr = '<%= @listen_addr %>'
-<% end %>
-
-<% if @prometheus_listen_addr %>
-# Optional: export metrics via Prometheus
-prometheus_listen_addr = '<%= @prometheus_listen_addr %>'
-<% end %>
-
-<% @storage.each do |shard| %>
-[[storage]]
-<% if shard.has_key?('name') %>
-name = '<%= shard['name'] %>'
-<% end %>
-<% if shard.has_key?('path') %>
-path = '<%= shard['path'] %>'
-<% end %>
-<% end %>
-
-[logging]
-<% if @logging_format %>
-format = '<%= @logging_format %>'
-<% end %>
-<% if @logging_sentry_dsn %>
-sentry_dsn = '<%= @logging_sentry_dsn %>'
-<% end %>
-
-<% if @prometheus_grpc_latency_buckets %>
-# # You can optionally configure Gitaly to record histogram latencies on GRPC method calls
-[prometheus]
-grpc_latency_buckets = <%= @prometheus_grpc_latency_buckets %>
-<% end %>
-
-[auth]
-<% if @auth_token %>
-token = '<%= @auth_token %>'
-<% end %>
-<% if @auth_transitioning %>
-transitioning = <%= @auth_transitioning %>
-<% end %>
-
-[gitaly-ruby]
-dir = "/opt/gitlab/embedded/service/gitaly-ruby"
-
-[gitlab-shell]
-dir = "/opt/gitlab/embedded/service/gitlab-shell"
-<% if @concurrency %>
-  <% @concurrency.each do |endpoint| %>
-
-[[concurrency]]
-rpc = "<%= endpoint['rpc'] %>"
-max_per_repo = <%= endpoint['max_per_repo'] %>
-  <% end %>
-<% end %>
diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-log-config.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-log-config.erb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-log-config.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-<%= "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-gitaly-log-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-log-run.erb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-log-run.erb
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-exec svlogd -tt <%= @options[:log_directory] %>
diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-run.erb
deleted file mode 100644
--- a/files/gitlab-cookbooks/gitlab/templates/default/sv-gitaly-run.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-set -e # fail on errors
-
-# Redirect stderr -> stdout
-exec 2>&1
-
-<%= render("mount_point_check.erb") %>
-
-cd <%= @options[:working_dir] %>
-
-exec chpst -e <%= @options[:env_dir] %> -P \
-  -U <%= @options[:user] %> \
-  -u <%= @options[:user] %> \
-  <%= @options[:bin_path] %> <%= @options[:config_path] %>
diff --git a/files/gitlab-cookbooks/package/libraries/config/gitlab.rb b/files/gitlab-cookbooks/package/libraries/config/gitlab.rb
--- a/files/gitlab-cookbooks/package/libraries/config/gitlab.rb
+++ b/files/gitlab-cookbooks/package/libraries/config/gitlab.rb
@@ -40,6 +40,7 @@
   attribute('repmgr')
   attribute('repmgrd')
   attribute('consul')
+  attribute('gitaly')
   attribute('mattermost', priority: 30).use { GitlabMattermost } # Mattermost checks if GitLab is enabled on the same box
 
   ## Attributes under node['gitlab']
@@ -81,7 +82,6 @@
     attribute('logrotate')
     attribute('high_availability')
     attribute('web_server')
-    attribute('gitaly')
     attribute('node_exporter')
     attribute('redis_exporter')
     attribute('postgres_exporter')
diff --git a/spec/chef/recipes/config_spec.rb b/spec/chef/recipes/config_spec.rb
--- a/spec/chef/recipes/config_spec.rb
+++ b/spec/chef/recipes/config_spec.rb
@@ -13,7 +13,7 @@
       expect(node['gitlab']['unicorn']['enable']).to eq false
       expect(node['gitlab']['sidekiq']['enable']).to eq false
       expect(node['gitlab']['gitlab-workhorse']['enable']).to eq false
-      expect(node['gitlab']['gitaly']['enable']).to eq false
+      expect(node['gitaly']['enable']).to eq false
       expect(node['gitlab']['nginx']['enable']).to eq false
       expect(node['gitlab']['postgresql']['enable']).to eq false
       expect(node['gitlab']['mailroom']['enable']).to eq false
diff --git a/spec/chef/recipes/gitaly_spec.rb b/spec/chef/recipes/gitaly_spec.rb
--- a/spec/chef/recipes/gitaly_spec.rb
+++ b/spec/chef/recipes/gitaly_spec.rb
@@ -1,6 +1,6 @@
 require 'chef_helper'
 
-describe 'gitlab::gitaly' do
+describe 'gitaly' do
   let(:chef_run) { ChefSpec::SoloRunner.new(step_into: %w(env_dir)).converge('gitlab::default') }
   let(:config_path) { '/var/opt/gitlab/gitaly/config.toml' }
   let(:gitaly_config) { chef_run.template(config_path) }
@@ -210,4 +210,22 @@
       it_behaves_like 'empty concurrency configuration'
     end
   end
+
+  context 'populates default env variables' do
+    it_behaves_like "enabled gitaly env", "TZ", ':/etc/localtime'
+    it_behaves_like "enabled gitaly env", "HOME", '/var/opt/gitlab'
+  end
+
+  context 'computes env variables based on other values' do
+    before do
+      stub_gitlab_rb(
+        {
+          user: {
+            home: "/my/random/path"
+          }
+        }
+      )
+    end
+    it_behaves_like "enabled gitaly env", "HOME", '/my/random/path'
+  end
 end
diff --git a/spec/chef_helper.rb b/spec/chef_helper.rb
--- a/spec/chef_helper.rb
+++ b/spec/chef_helper.rb
@@ -8,6 +8,7 @@
 # Load our cookbook libraries so we can stub them in our tests
 Dir[File.join(__dir__, '../files/gitlab-cookbooks/package/libraries/**/*.rb')].each { |f| require f }
 Dir[File.join(__dir__, '../files/gitlab-cookbooks/gitlab/libraries/*.rb')].each { |f| require f }
+Dir[File.join(__dir__, '../files/gitlab-cookbooks/gitaly/libraries/*.rb')].each { |f| require f }
 Dir[File.join(__dir__, '../files/gitlab-cookbooks/mattermost/libraries/*.rb')].each { |f| require f }
 Dir[File.join(__dir__, '../files/gitlab-cookbooks/gitlab-ee/libraries/*.rb')].each { |f| require f }
 
diff --git a/spec/libraries/gitaly_spec.rb b/spec/libraries/gitaly_spec.rb
--- a/spec/libraries/gitaly_spec.rb
+++ b/spec/libraries/gitaly_spec.rb
@@ -6,14 +6,14 @@
 
   describe 'by default' do
     it 'provides settings needed for gitaly to run' do
-      expect(chef_run.node['gitlab']['gitaly']['env']).to include(
+      expect(chef_run.node['gitaly']['env']).to include(
         'HOME' => '/var/opt/gitlab',
         'PATH' => '/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin'
       )
     end
 
     it 'does not include known settings in the environment' do
-      expect(chef_run.node['gitlab']['gitaly']['env']).not_to include('GITALY_ENABLE')
+      expect(chef_run.node['gitaly']['env']).not_to include('GITALY_ENABLE')
     end
   end
 end
diff --git a/spec/libraries/services_spec.rb b/spec/libraries/services_spec.rb
--- a/spec/libraries/services_spec.rb
+++ b/spec/libraries/services_spec.rb
@@ -80,7 +80,7 @@
         Services.disable('redis', 'postgresql', 'gitaly')
         expect(node['gitlab']['redis']['enable']).to be false
         expect(node['gitlab']['postgresql']['enable']).to be false
-        expect(node['gitlab']['gitaly']['enable']).to be false
+        expect(node['gitaly']['enable']).to be false
 
         Services.enable('mattermost', 'registry', 'mailroom')
         expect(node['mattermost']['enable']).to be true
@@ -99,7 +99,7 @@
         Services.disable('redis', 'postgresql', 'gitaly', except: 'postgresql')
         expect(node['gitlab']['redis']['enable']).to be false
         expect(node['gitlab']['postgresql']['enable']).to be true
-        expect(node['gitlab']['gitaly']['enable']).to be false
+        expect(node['gitaly']['enable']).to be false
       end
 
       it 'supports multiple exceptions' do
@@ -113,7 +113,7 @@
         Services.disable('redis', 'postgresql', 'gitaly', except: %w(postgresql gitaly))
         expect(node['gitlab']['redis']['enable']).to be false
         expect(node['gitlab']['postgresql']['enable']).to be true
-        expect(node['gitlab']['gitaly']['enable']).to be true
+        expect(node['gitaly']['enable']).to be true
       end
 
       it 'ignores disable on system services' do
@@ -157,7 +157,7 @@
         Services.enable(Services::ALL_SERVICES, except: %w(registry mailroom))
         expect(node['gitlab']['redis']['enable']).to be true
         expect(node['gitlab']['postgresql']['enable']).to be true
-        expect(node['gitlab']['gitaly']['enable']).to be true
+        expect(node['gitaly']['enable']).to be true
         expect(node['mattermost']['enable']).to be true
         expect(node['gitlab']['mailroom']['enable']).to be false
         expect(node['registry']['enable']).to be false
@@ -168,7 +168,7 @@
         Services.disable(Services::ALL_SERVICES, except: %w(postgresql gitaly))
         expect(node['gitlab']['redis']['enable']).to be false
         expect(node['gitlab']['postgresql']['enable']).to be true
-        expect(node['gitlab']['gitaly']['enable']).to be true
+        expect(node['gitaly']['enable']).to be true
         expect(node['mattermost']['enable']).to be false
         expect(node['gitlab']['mailroom']['enable']).to be false
         expect(node['registry']['enable']).to be false
diff --git a/spec/support/env_dir.rb b/spec/support/env_dir.rb
--- a/spec/support/env_dir.rb
+++ b/spec/support/env_dir.rb
@@ -45,3 +45,15 @@
     )
   end
 end
+
+shared_examples 'enabled gitaly env' do |env_var, content|
+  it 'created env directory' do
+    expect(chef_run).to create_directory("/opt/gitlab/etc/gitaly")
+  end
+
+  it "does create the #{env_var} file" do
+    expect(chef_run).to create_file("/opt/gitlab/etc/gitaly/#{env_var}").with_content(
+      /#{content}/
+    )
+  end
+end