Skip to content

Commit 3a597b8

Browse files
committed
Create piddirs with tmpfiles.d on systemd
Fixes DavidWittman#132
1 parent e32159c commit 3a597b8

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.kitchen/
33
.bundle
44
.vagrant
5+
*.retry

tasks/sentinel.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
- ../templates
3535
when: redis_as_service and ansible_service_mgr|default() == 'systemd'
3636

37+
- name: create systemd tmpfiles configuration
38+
template:
39+
src: etc/tmpfiles.d/redis.conf.j2
40+
dest: /etc/tmpfiles.d/redis.conf
41+
mode: 0644
42+
when:
43+
- redis_as_service
44+
- ansible_service_mgr|default() == 'systemd'
45+
- (redis_sentinel_pidfile|dirname).startswith('/var/run') or (redis_sentinel_pidfile|dirname).startswith('/run')
46+
3747
- name: set sentinel to start at boot
3848
service:
3949
name: sentinel_{{ redis_sentinel_port }}

tasks/server.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- default/redis.init.j2
2020
paths:
2121
- ../templates
22-
when: redis_as_service and ansible_service_mgr | default != 'systemd'
22+
when: redis_as_service and ansible_service_mgr|default() != 'systemd'
2323

2424
- name: create redis systemd service
2525
template:
@@ -32,13 +32,23 @@
3232
- default/redis.service.j2
3333
paths:
3434
- ../templates
35-
when: redis_as_service and ansible_service_mgr | default == 'systemd'
35+
when: redis_as_service and ansible_service_mgr|default() == 'systemd'
36+
37+
- name: create systemd tmpfiles configuration
38+
template:
39+
src: etc/tmpfiles.d/redis.conf.j2
40+
dest: /etc/tmpfiles.d/redis.conf
41+
mode: 0644
42+
when:
43+
- redis_as_service
44+
- ansible_service_mgr|default() == 'systemd'
45+
- (redis_pidfile|dirname).startswith('/var/run') or (redis_pidfile|dirname).startswith('/run')
3646

3747
- name: set redis to start at boot
3848
service:
3949
name: "{{ redis_service_name }}"
4050
enabled: yes
41-
daemon_reload: "{{ True if ansible_service_mgr | default == 'systemd' else omit }}"
51+
daemon_reload: "{{ True if ansible_service_mgr|default() == 'systemd' else omit }}"
4252
when: redis_as_service
4353

4454
# Check then create log dir to prevent aggressively overwriting permissions

templates/default/redis.service.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Documentation=http://redis.io/documentation, man:redis-server(1)
55

66
[Service]
77
Type={{ 'forking' if redis_daemonize == 'yes' else 'simple' }}
8-
ExecStartPre=-/bin/mkdir {{ redis_pidfile|dirname }}
9-
ExecStartPre=/bin/chown -R {{ redis_user }}:{{ redis_group }} {{ redis_pidfile|dirname }}
108
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/{{ redis_port }}.conf
119
EnvironmentFile=-/etc/default/redis_{{ redis_port }}
1210
PIDFile={{ redis_pidfile }}

templates/default/redis_sentinel.service.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Documentation=http://redis.io/documentation, man:redis-sentinel(1)
55

66
[Service]
77
Type={{ 'forking' if redis_daemonize == 'yes' else 'simple' }}
8-
ExecStartPre=-/bin/mkdir {{ redis_sentinel_pidfile|dirname }}
9-
ExecStartPre=/bin/chown -R {{ redis_user }}:{{ redis_group }} {{ redis_sentinel_pidfile|dirname }}
108
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/sentinel_{{ redis_sentinel_port }}.conf --sentinel
119
EnvironmentFile=-/etc/default/sentinel_{{ redis_sentinel_port }}
1210
PIDFile={{ redis_sentinel_pidfile }}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
d {{ redis_pidfile|dirname }} 0755 {{ redis_user }} {{ redis_group }}
2+
{% if redis_pidfile|dirname != redis_sentinel_pidfile|dirname -%}
3+
d {{ redis_sentinel_pidfile|dirname }} 0755 {{ redis_user }} {{ redis_group }}
4+
{% endif -%}

0 commit comments

Comments
 (0)