Skip to content

Commit

Permalink
Prefer the Redis unix socket if available
Browse files Browse the repository at this point in the history
Unix sockets typically have lower overhead and also allows setting
stricter permissions. While iptables can be used to limit access using
users, file permissions are much easier to manage.
  • Loading branch information
ekohl committed Jul 13, 2021
1 parent 99381ed commit d7dfdb7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
ensure_newline => true,
}

if $redis::unixsocket != '' {
$redis_url = "redis+unix://${redis::unixsocket}?db=${pulpcore::redis_db}"
} elsif $redis::port != 0 {
# TODO: this assumes $redis::bind at least has localhost in it
$redis_url = "redis://localhost:${redis::port}/${pulpcore::redis_db}"
} else {
fail('Unable to determine Redis URL')
}

concat::fragment { 'base':
target => 'pulpcore settings',
content => template('pulpcore/settings.py.erb'),
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/pulpcore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.with_content(%r{ALLOWED_IMPORT_PATHS = \["/var/lib/pulp/sync_imports"\]})
.with_content(%r{ALLOWED_CONTENT_CHECKSUMS = \["sha224", "sha256", "sha384", "sha512"\]})
.with_content(%r{\s'level': 'INFO',})
.with_content(%r{REDIS_URL = "redis://localhost:6379/8"})
.with_content(%r{REDIS_URL = "redis\+unix:///var/run/redis/redis\.sock\?db=8"})
.with_content(%r{CACHE_ENABLED = False})
.without_content(%r{sslmode})
is_expected.to contain_file('/etc/pulp')
Expand Down
2 changes: 1 addition & 1 deletion templates/settings.py.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DATABASES = {
<% end -%>
},
}
REDIS_URL = "redis://localhost:<%= scope['redis::port'] %>/<%= scope['pulpcore::redis_db'] %>"
REDIS_URL = "<%= @redis_url %>"

USE_NEW_WORKER_TYPE = <%= scope['pulpcore::use_rq_tasking_system'] ? "False" : "True" %>

Expand Down

0 comments on commit d7dfdb7

Please sign in to comment.