Skip to content
Snippets Groups Projects
Commit 19c89fcb authored by Balasankar "Balu" C's avatar Balasankar "Balu" C
Browse files

Merge branch 'gitlab-redis-cli' into 'master'

introduce gitlab-redis-cli

See merge request gitlab-org/omnibus-gitlab!4020
parents a5047620 da372974
No related branches found
No related tags found
No related merge requests found
---
title: Introduce gitlab-redis-cli
merge_request: 4020
author:
type: added
......@@ -112,6 +112,7 @@
dependency 'gitlab-shell'
dependency 'gitlab-ctl'
dependency 'gitlab-psql'
dependency 'gitlab-redis-cli'
dependency 'gitlab-healthcheck'
dependency 'gitlab-cookbooks'
dependency 'chef-acme'
......
#
# Copyright:: Copyright (c) 2020 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.
#
require 'digest'
name 'gitlab-redis-cli'
license 'Apache-2.0'
license_file File.expand_path('LICENSE', Omnibus::Config.project_root)
skip_transitive_dependency_licensing true
# This 'software' is self-contained in this file. Use the file contents
# to generate a version string.
default_version Digest::MD5.file(__FILE__).hexdigest
build do
block do
File.open("#{install_dir}/bin/gitlab-redis-cli", 'w') do |file|
file.print <<-EOH
#!/bin/sh
error_echo()
{
echo "$1" 2>& 1
}
gitlab_redis_cli_rc='/opt/gitlab/etc/gitlab-redis-cli-rc'
if ! [ -f ${gitlab_redis_cli_rc} ] || ! [ -r ${gitlab_redis_cli_rc} ] ; then
error_echo "$0 error: could not load ${gitlab_redis_cli_rc}"
error_echo "Either you are not allowed to read the file, or it does not exist yet."
error_echo "You can generate it with: sudo gitlab-ctl reconfigure"
exit 1
fi
. "${gitlab_redis_cli_rc}"
if [ -e "${redis_socket}" ]; then
REDIS_PARAMS="-s ${redis_socket}"
else
REDIS_PARAMS="-h ${redis_host} -p ${redis_port}"
fi
export REDISCLI_AUTH="$(grep ^requirepass ${redis_dir}/redis.conf|cut -d\\" -f2)"
exec /opt/gitlab/embedded/bin/redis-cli $REDIS_PARAMS $@
EOH
end
end
command "chmod 755 #{install_dir}/bin/gitlab-redis-cli"
end
......@@ -19,3 +19,8 @@
redis_service do
socket_group AccountHelper.new(node).gitlab_group
end
template "/opt/gitlab/etc/gitlab-redis-cli-rc" do
owner 'root'
group 'root'
end
redis_dir='<%= node['redis']['dir'] %>'
redis_host='<%= node['redis']['bind'] %>'
redis_port='<%= node['redis']['port'] %>'
redis_socket='<%= node['redis']['unixsocket'] if node['redis']['unixsocket'] %>'
......@@ -11,6 +11,7 @@
"${DEST_DIR}/embedded/bin/gitlab-pg-ctl"
"${DEST_DIR}/bin/gitlab-geo-psql"
"${DEST_DIR}/bin/gitlab-backup"
"${DEST_DIR}/bin/gitlab-redis-cli"
)
error_exit()
......
......@@ -8,6 +8,15 @@
end
context 'by default' do
let(:gitlab_redis_cli_rc) do
<<-EOF
redis_dir='/var/opt/gitlab/redis'
redis_host='127.0.0.1'
redis_port='0'
redis_socket='/var/opt/gitlab/redis/redis.socket'
EOF
end
it 'creates redis config with default values' do
expect(chef_run).to render_file('/var/opt/gitlab/redis/redis.conf')
.with_content { |content|
......@@ -35,6 +44,11 @@
it_behaves_like 'enabled runit service', 'redis', 'root', 'root', 'gitlab-redis', 'gitlab-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)
end
describe 'pending restart check' do
context 'when running version is same as installed version' do
before do
......@@ -155,6 +169,15 @@
let(:master_ip) { '10.0.0.0' }
let(:master_port) { 6371 }
let(:gitlab_redis_cli_rc) do
<<-EOF
redis_dir='/var/opt/gitlab/redis'
redis_host='1.2.3.4'
redis_port='6370'
redis_socket=''
EOF
end
before do
stub_gitlab_rb(
redis: {
......@@ -172,6 +195,11 @@
expect(chef_run).to render_file('/var/opt/gitlab/redis/redis.conf')
.with_content(/^slaveof #{master_ip} #{master_port}/)
end
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)
end
end
context 'in HA mode with Sentinels' do
......@@ -180,6 +208,15 @@
let(:master_ip) { '10.0.0.0' }
let(:master_port) { 6371 }
let(:gitlab_redis_cli_rc) do
<<-EOF
redis_dir='/var/opt/gitlab/redis'
redis_host='1.2.3.4'
redis_port='6370'
redis_socket=''
EOF
end
before do
stub_gitlab_rb(
redis: {
......@@ -198,6 +235,11 @@
expect(chef_run).not_to render_file('/var/opt/gitlab/redis/redis.conf')
.with_content(/^slaveof/)
end
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)
end
end
context 'with rename_commands disabled' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment