Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
pulp_redis: Allow to configure Unix Domain Socket
Browse files Browse the repository at this point in the history
This commit ensures one can configure redis so it listens to unix domain
socket (if wanted) rather than forcing it to listen on TCP socket.

Benefits of this commit has been higlighted in previous PR[1].

Also, this commit introduces `pulp_redis_bind` to offer an expected
experience for people using `pulp/pulp_installer` when it comes to
configure network services (ie. `pulp_api_bind`, `pulp_content_bind`).

fixes #6931

[1] #322
  • Loading branch information
Spredzy committed Jun 9, 2020
1 parent c0d1314 commit 6575e08
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/6931.feature
@@ -0,0 +1 @@
Allow a user to use Unix Domain Socket (UDS) for the redis server.
5 changes: 5 additions & 0 deletions roles/pulp_redis/README.md
Expand Up @@ -3,6 +3,11 @@ pulp_redis

Install and start Redis, and install RQ in the Pulp virtualenv.

Role Variables
--------------

* `pulp_redis_bind`: Interface and Port where Redis service will listen. One can specify a unix path (ie. 'unix:/var/run/redis/redis.sock'). Defaults to `127.0.0.1:6379`

Shared Variables
----------------

Expand Down
1 change: 1 addition & 0 deletions roles/pulp_redis/defaults/main.yml
@@ -1,3 +1,4 @@
---
pulp_install_dir: '/usr/local/lib/pulp'
pulp_user: pulp
pulp_redis_bind: '127.0.0.1:6379'
5 changes: 5 additions & 0 deletions roles/pulp_redis/handlers/main.yml
@@ -0,0 +1,5 @@
---
- name: restart redis
systemd:
name: "{{ pulp_redis_server_name }}"
state: restarted
17 changes: 17 additions & 0 deletions roles/pulp_redis/tasks/configure_tcp.yml
@@ -0,0 +1,17 @@
---
- name: Set pulp_redis_host and pulp_redis_port fact
set_fact:
pulp_redis_host: '{{ pulp_redis_bind.split(":")[0] }}'
pulp_redis_port: '{{ pulp_redis_bind.split(":")[1] }}'

- name: Ensure Redis will listen on the specified TCP socket
lineinfile:
path: '{{ pulp_redis_conf_file }}'
regexp: '{{ item.regexp }}'
line: '{{ item.line }}'
loop:
- regexp: '^port '
line: 'port {{ pulp_redis_port }}'
- regexp: '^bind '
line: 'bind {{ pulp_redis_host }}'
notify: restart redis
24 changes: 24 additions & 0 deletions roles/pulp_redis/tasks/configure_uds.yml
@@ -0,0 +1,24 @@
---
- name: Configure pulp_redis_socket_file fact
set_fact:
pulp_redis_socket_file: '{{ pulp_redis_bind | replace("unix:", "") }}'

- name: Ensure pulp is part of group redis
user:
name: '{{ pulp_user }}'
groups: redis
append: true

- name: Ensure Redis will not listen on a TCP socket
lineinfile:
path: '{{ pulp_redis_conf_file }}'
regexp: '{{ item.regexp }}'
line: '{{ item.line }}'
loop:
- regexp: '^port '
line: 'port 0'
- regexp: '^unixsocket '
line: 'unixsocket {{ pulp_redis_socket_file }}'
- regexp: '^unixsocketperm '
line: 'unixsocketperm 775'
notify: restart redis
8 changes: 8 additions & 0 deletions roles/pulp_redis/tasks/main.yml
Expand Up @@ -32,6 +32,14 @@
name: redis
state: present

- name: Configure Redis to listen on Unix Domain Socket
include_tasks: configure_uds.yml
when: "pulp_redis_bind.startswith('unix:')"

- name: Configure Redis to listen on TCP socket
include_tasks: configure_tcp.yml
when: "not pulp_redis_bind.startswith('unix:')"

- name: Start Redis
systemd:
name: "{{ pulp_redis_server_name }}"
Expand Down
1 change: 1 addition & 0 deletions roles/pulp_redis/vars/CentOS.yml
Expand Up @@ -3,3 +3,4 @@ pulp_preq_packages:
- python36
- python36-devel
pulp_redis_server_name: redis
pulp_redis_conf_file: '/etc/redis.conf'
1 change: 1 addition & 0 deletions roles/pulp_redis/vars/Debian.yml
Expand Up @@ -3,4 +3,5 @@ pulp_preq_packages:
- python3
- python3-dev
pulp_redis_server_name: redis-server
pulp_redis_conf_file: '/etc/redis/redis.conf'
...
1 change: 1 addition & 0 deletions roles/pulp_redis/vars/Fedora.yml
Expand Up @@ -4,3 +4,4 @@ pulp_preq_packages:
- python3-devel

pulp_redis_server_name: redis
pulp_redis_conf_file: '/etc/redis.conf'
1 change: 1 addition & 0 deletions roles/pulp_redis/vars/Ubuntu.yml
Expand Up @@ -3,3 +3,4 @@ pulp_preq_packages:
- python3
- python3-dev
pulp_redis_server_name: redis-server
pulp_redis_conf_file: '/etc/redis/redis.conf'

0 comments on commit 6575e08

Please sign in to comment.