diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template index 01e594b1a72c3af8a9bc6267e62237507e6ae743_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU=..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU= 100644 --- a/files/gitlab-config-template/gitlab.rb.template +++ b/files/gitlab-config-template/gitlab.rb.template @@ -1372,6 +1372,8 @@ # redis['enable'] = true # redis['ha'] = false +# redis['start_down'] = false +# redis['set_replicaof'] = false # redis['hz'] = 10 # redis['dir'] = "/var/opt/gitlab/redis" # redis['log_directory'] = "/var/log/gitlab/redis" diff --git a/files/gitlab-cookbooks/redis/attributes/attributes.rb b/files/gitlab-cookbooks/redis/attributes/attributes.rb index 01e594b1a72c3af8a9bc6267e62237507e6ae743_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy9hdHRyaWJ1dGVzL2F0dHJpYnV0ZXMucmI=..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy9hdHRyaWJ1dGVzL2F0dHJpYnV0ZXMucmI= 100644 --- a/files/gitlab-cookbooks/redis/attributes/attributes.rb +++ b/files/gitlab-cookbooks/redis/attributes/attributes.rb @@ -3,6 +3,8 @@ #### default['redis']['enable'] = false default['redis']['ha'] = false +default['redis']['start_down'] = false +default['redis']['set_replicaof'] = false default['redis']['hz'] = 10 default['redis']['dir'] = "/var/opt/gitlab/redis" default['redis']['log_directory'] = "/var/log/gitlab/redis" diff --git a/files/gitlab-cookbooks/redis/resources/service.rb b/files/gitlab-cookbooks/redis/resources/service.rb index 01e594b1a72c3af8a9bc6267e62237507e6ae743_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy9yZXNvdXJjZXMvc2VydmljZS5yYg==..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy9yZXNvdXJjZXMvc2VydmljZS5yYg== 100644 --- a/files/gitlab-cookbooks/redis/resources/service.rb +++ b/files/gitlab-cookbooks/redis/resources/service.rb @@ -36,11 +36,18 @@ end redis_config = ::File.join(new_resource.dir, 'redis.conf') - is_replica = node['redis']['master_ip'] && - node['redis']['master_port'] && - !node['redis']['master'] + + if node['redis'].key?('ha') + if node['redis']['ha'] + node.default['redis']['start_down'] = true + node.default['redis']['set_replicaof'] = false + else + node.default['redis']['start_down'] = false + node.default['redis']['set_replicaof'] = true unless node['redis']['master'] + end + end template redis_config do source "redis.conf.erb" owner new_resource.account_helper.redis_user mode "0644" @@ -42,11 +49,11 @@ template redis_config do source "redis.conf.erb" owner new_resource.account_helper.redis_user mode "0644" - variables(node['redis'].to_hash.merge({ is_replica: is_replica })) + variables(node['redis'].to_hash) notifies :restart, 'runit_service[redis]', :immediately if new_resource.omnibus_helper.should_notify?('redis') sensitive true end runit_service 'redis' do @@ -48,9 +55,9 @@ notifies :restart, 'runit_service[redis]', :immediately if new_resource.omnibus_helper.should_notify?('redis') sensitive true end runit_service 'redis' do - start_down node['redis']['ha'] + start_down node['redis']['start_down'] template_name 'redis' options({ service: 'redis', diff --git a/files/gitlab-cookbooks/redis/templates/default/redis.conf.erb b/files/gitlab-cookbooks/redis/templates/default/redis.conf.erb index 01e594b1a72c3af8a9bc6267e62237507e6ae743_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy90ZW1wbGF0ZXMvZGVmYXVsdC9yZWRpcy5jb25mLmVyYg==..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9yZWRpcy90ZW1wbGF0ZXMvZGVmYXVsdC9yZWRpcy5jb25mLmVyYg== 100644 --- a/files/gitlab-cookbooks/redis/templates/default/redis.conf.erb +++ b/files/gitlab-cookbooks/redis/templates/default/redis.conf.erb @@ -151,7 +151,7 @@ # server to connected clients, masters or cluster peers. These files should be # PEM formatted. # -# tls-cert-file redis.crt +# tls-cert-file redis.crt <% unless @tls_cert_file.nil? %> tls-cert-file <%= @tls_cert_file %> <% end %> @@ -447,7 +447,7 @@ # and resynchronize with them. # # replicaof <masterip> <masterport> -<%= "replicaof #{@master_ip} #{@master_port}" if @is_replica && !@ha %> +<%= "replicaof #{@master_ip} #{@master_port}" if @set_replicaof %> # If the master is password protected (using the "requirepass" configuration # directive below) it is possible to tell the replica to authenticate before @@ -829,8 +829,8 @@ # ACL LOG # # The ACL Log tracks failed commands and authentication events associated -# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked -# by ACLs. The ACL Log is stored in memory. You can reclaim memory with +# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked +# by ACLs. The ACL Log is stored in memory. You can reclaim memory with # ACL LOG RESET. Define the maximum entry length of the ACL Log below. acllog-max-len 128 @@ -1405,5 +1405,5 @@ # cluster-replica-no-failover no # This option, when set to yes, allows nodes to serve read traffic while the -# the cluster is in a down state, as long as it believes it owns the slots. +# the cluster is in a down state, as long as it believes it owns the slots. # @@ -1409,4 +1409,4 @@ # -# This is useful for two cases. The first case is for when an application +# This is useful for two cases. The first case is for when an application # doesn't require consistency of data during node failures or network partitions. # One example of this is a cache, where as long as the node has the data it @@ -1411,4 +1411,4 @@ # doesn't require consistency of data during node failures or network partitions. # One example of this is a cache, where as long as the node has the data it -# should be able to serve it. +# should be able to serve it. # @@ -1414,5 +1414,5 @@ # -# The second use case is for configurations that don't meet the recommended -# three shards but want to enable cluster mode and scale later. A +# The second use case is for configurations that don't meet the recommended +# three shards but want to enable cluster mode and scale later. A # master outage in a 1 or 2 shard configuration causes a read/write outage to the # entire cluster without this option set, with it set there is only a write outage. @@ -1417,6 +1417,6 @@ # master outage in a 1 or 2 shard configuration causes a read/write outage to the # entire cluster without this option set, with it set there is only a write outage. -# Without a quorum of masters, slot ownership will not change automatically. +# Without a quorum of masters, slot ownership will not change automatically. # # cluster-allow-reads-when-down no diff --git a/spec/chef/cookbooks/redis/recipes/redis_spec.rb b/spec/chef/cookbooks/redis/recipes/redis_spec.rb index 01e594b1a72c3af8a9bc6267e62237507e6ae743_c3BlYy9jaGVmL2Nvb2tib29rcy9yZWRpcy9yZWNpcGVzL3JlZGlzX3NwZWMucmI=..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_c3BlYy9jaGVmL2Nvb2tib29rcy9yZWRpcy9yZWNpcGVzL3JlZGlzX3NwZWMucmI= 100644 --- a/spec/chef/cookbooks/redis/recipes/redis_spec.rb +++ b/spec/chef/cookbooks/redis/recipes/redis_spec.rb @@ -245,6 +245,8 @@ .with_content(/^replicaof/) end + it_behaves_like 'started down runit service', 'redis' + it 'creates gitlab-redis-cli-rc' do expect(chef_run).to render_file('/opt/gitlab/etc/gitlab-redis-cli-rc') .with_content(gitlab_redis_cli_rc) diff --git a/spec/chef/support/shared_examples/runit_service.rb b/spec/chef/support/shared_examples/runit_service.rb index 01e594b1a72c3af8a9bc6267e62237507e6ae743_c3BlYy9jaGVmL3N1cHBvcnQvc2hhcmVkX2V4YW1wbGVzL3J1bml0X3NlcnZpY2UucmI=..ef9f3bf61dcdc376bc3a5175784becf776e57a2b_c3BlYy9jaGVmL3N1cHBvcnQvc2hhcmVkX2V4YW1wbGVzL3J1bml0X3NlcnZpY2UucmI= 100644 --- a/spec/chef/support/shared_examples/runit_service.rb +++ b/spec/chef/support/shared_examples/runit_service.rb @@ -118,3 +118,9 @@ expect(chef_run).to run_ruby_block("disable #{svc_name}") end end + +RSpec.shared_examples 'started down runit service' do |svc_name| + it 'creates a service down file' do + expect(chef_run).to render_file("/opt/gitlab/sv/#{svc_name}/down") + end +end