Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring redis sentinel service name #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ redis_config_additional: ""
## Redis sentinel configs
# Set this to true on a host to configure it as a Sentinel
redis_sentinel: false
redis_sentinel_service_name: "sentinel_{{ redis_sentinel_port }}"
redis_sentinel_protected_mode: "yes"
redis_sentinel_dir: /var/lib/redis/sentinel_{{ redis_sentinel_port }}
redis_sentinel_bind: 0.0.0.0
redis_sentinel_port: 26379
redis_sentinel_password: false
redis_sentinel_pidfile: /var/run/redis/sentinel_{{ redis_sentinel_port }}.pid
redis_sentinel_logfile: '""'
redis_sentinel_syslog_ident: sentinel_{{ redis_sentinel_port }}
redis_sentinel_syslog_ident: "{{ redis_sentinel_service_name }}"
redis_sentinel_oom_score_adjust: 0
redis_sentinel_monitors:
- name: master01
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

- name: "restart sentinel"
service:
name: sentinel_{{ redis_sentinel_port }}
name: "{{ redis_sentinel_service_name }}"
state: restarted
when: redis_as_service
14 changes: 7 additions & 7 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- name: create sentinel init script
template:
src: "{{ item }}"
dest: /etc/init.d/sentinel_{{ redis_sentinel_port }}
dest: /etc/init.d/{{ redis_sentinel_service_name }}
mode: 0755
# Choose the distro-specific template. We must specify the templates
# path here because with_first_found tries to find files in files/
Expand All @@ -24,7 +24,7 @@
- name: create sentinel systemd service
template:
src: "{{ item }}"
dest: /etc/systemd/system/sentinel_{{ redis_sentinel_port }}.service
dest: /etc/systemd/system/{{ redis_sentinel_service_name }}.service
mode: 0644
with_first_found:
- files:
Expand Down Expand Up @@ -55,7 +55,7 @@

- name: set sentinel to start at boot
service:
name: sentinel_{{ redis_sentinel_port }}
name: "{{ redis_sentinel_service_name }}"
enabled: yes
when: redis_as_service

Expand Down Expand Up @@ -105,21 +105,21 @@
- name: create sentinel config file
template:
src: redis_sentinel.conf.j2
dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
dest: /etc/redis/{{ redis_sentinel_service_name }}.conf
owner: "{{ redis_user }}"
mode: 0640
notify: "restart sentinel"

- name: add sentinel init config file
template:
dest: /etc/sysconfig/sentinel_{{ redis_sentinel_port }}
dest: /etc/sysconfig/{{ redis_sentinel_service_name }}
src: redis.init.conf.j2
when: ansible_os_family == "RedHat"
notify: "restart sentinel"

- name: add sentinel init config file
template:
dest: /etc/default/sentinel_{{ redis_sentinel_port }}
dest: /etc/default/{{ redis_sentinel_service_name }}
src: redis.init.conf.j2
when: ansible_os_family == "Debian"
notify: "restart sentinel"
Expand All @@ -131,6 +131,6 @@

- name: ensure sentinel is running
service:
name: sentinel_{{ redis_sentinel_port }}
name: "{{ redis_sentinel_service_name }}"
state: started
when: redis_as_service
4 changes: 2 additions & 2 deletions templates/Debian/redis_sentinel.init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#
#
### BEGIN INIT INFO
# Provides: sentinel_{{ redis_sentinel_port }}
# Provides: {{ redis_sentinel_service_name }}
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: Start and stop sentinel_{{ redis_sentinel_port }}
# Short-Description: Start and stop {{ redis_sentinel_service_name }}
# Description: Redis Sentinel monitor
### END INIT INFO

Expand Down
4 changes: 2 additions & 2 deletions templates/default/redis_sentinel.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Documentation=http://redis.io/documentation, man:redis-sentinel(1)

[Service]
Type={{ 'forking' if redis_daemonize == 'yes' else 'simple' }}
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/sentinel_{{ redis_sentinel_port }}.conf --sentinel
EnvironmentFile=-/etc/default/sentinel_{{ redis_sentinel_port }}
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/{{ redis_sentinel_service_name }}.conf --sentinel
EnvironmentFile=-/etc/default/{{ redis_sentinel_service_name }}
PIDFile={{ redis_sentinel_pidfile }}
TimeoutStopSec=0
Restart=always
Expand Down
2 changes: 1 addition & 1 deletion templates/redis_sentinel.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# redis-sentinel {{ redis_version }} configuration file
# sentinel_{{ redis_sentinel_port }}.conf
# {{ redis_sentinel_service_name }}.conf

daemonize {{ redis_daemonize }}
protected-mode {{ redis_sentinel_protected_mode }}
Expand Down