Skip to content

Commit 14a660e

Browse files
committed
Connect to Redis via a UNIX socket rather than TCP
We are already assuming that Redis is local. A UNIX socket is faster, more secure, and avoids the IPv6 headache. We now have to create the git user earlier so that the redisio cookbook does not create it with different properties and because usermod will fail if Redis is already running.
1 parent 745e254 commit 14a660e

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

attributes/default.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@
7272
nodejs::install
7373
)
7474

75-
# Redisio instance name
76-
default['gitlab']['redis_instance'] = 'redis-server'
75+
# redisio instance
76+
default['gitlab']['redis_instance'] = 'redisgitlab'
77+
default['redisio']['servers'] = [
78+
{
79+
'name' => 'gitlab',
80+
'user' => node['gitlab']['user'],
81+
'group' => node['gitlab']['group'],
82+
'unixsocket' => '/var/run/redis/gitlab/redis.sock',
83+
'unixsocketperm' => '660',
84+
'port' => 0
85+
}
86+
]
7787

7888
# Required packages for Gitlab
7989
default['gitlab']['packages'] = %w(

recipes/default.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@
4242
extend SELinuxPolicy::Helpers
4343
include_recipe 'selinux_policy::install' if use_selinux
4444

45-
# Install the required packages via cookbook
46-
node['gitlab']['cookbook_dependencies'].each do |requirement|
47-
include_recipe requirement
48-
end
49-
50-
# Install required packages for Gitlab
51-
package node['gitlab']['packages']
52-
5345
# Add a git user for Gitlab
5446
user node['gitlab']['user'] do
5547
comment 'Gitlab User'
@@ -58,6 +50,14 @@
5850
supports manage_home: true
5951
end
6052

53+
# Install the required packages via cookbook
54+
node['gitlab']['cookbook_dependencies'].each do |requirement|
55+
include_recipe requirement
56+
end
57+
58+
# Install required packages for Gitlab
59+
package node['gitlab']['packages']
60+
6161
# Fix home permissions for nginx
6262
directory node['gitlab']['home'] do
6363
owner node['gitlab']['user']
@@ -178,6 +178,9 @@ class file open;
178178
api_fqdn = \
179179
node['gitlab']['shell']['gitlab_host'] || node['gitlab']['web_fqdn']
180180

181+
redis_socket = \
182+
node['redisio']['servers'].find { |s| s['name'] == 'gitlab' }['unixsocket']
183+
181184
# render gitlab-shell config
182185
template node['gitlab']['shell']['home'] + '/config.yml' do
183186
owner node['gitlab']['user']
@@ -186,7 +189,8 @@ class file open;
186189
source 'shell_config.yml.erb'
187190
variables(
188191
fqdn: api_fqdn,
189-
listen_port: listen_port
192+
listen_port: listen_port,
193+
redis_socket: redis_socket
190194
)
191195
end
192196

@@ -233,6 +237,15 @@ class file open;
233237
)
234238
end
235239

240+
file "#{node['gitlab']['app_home']}/config/resque.yml" do
241+
owner 'root'
242+
group node['gitlab']['group']
243+
mode '0640'
244+
content lazy {
245+
{ 'production' => { 'url' => "unix:#{redis_socket}" } }.to_yaml
246+
}
247+
end
248+
236249
# Render gitlab config file
237250
template "#{node['gitlab']['app_home']}/config/gitlab.yml" do
238251
owner node['gitlab']['user']
@@ -463,4 +476,5 @@ class unix_stream_socket connectto;
463476
pattern "unicorn_rails master -D -c #{node['gitlab']['app_home']}/config/unicorn.rb"
464477
action [:enable, :start]
465478
subscribes :restart, "template[#{node['gitlab']['app_home']}/config/gitlab.yml]", :delayed
479+
subscribes :restart, "file[#{node['gitlab']['app_home']}/config/resque.yml]", :delayed
466480
end

templates/default/shell_config.yml.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ auth_file: <%= node['gitlab']['home'] + "/.ssh/authorized_keys"%>
2121
# Redis settings used for pushing commit notices to gitlab
2222
redis:
2323
bin: <%= node['redisio']['bin_path'] %>/redis-cli
24-
host: 127.0.0.1
25-
port: 6379
26-
# socket: /tmp/redis.socket # Only define this if you want to use sockets
24+
socket: <%= @redis_socket %>
2725
namespace: resque:gitlab
2826

2927
# Log file.

0 commit comments

Comments
 (0)