Skip to content

Commit

Permalink
Create piddirs with tmpfiles.d on systemd
Browse files Browse the repository at this point in the history
Fixes #132
  • Loading branch information
DavidWittman committed Dec 10, 2016
1 parent e32159c commit 3a597b8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.kitchen/
.bundle
.vagrant
*.retry
10 changes: 10 additions & 0 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
- ../templates
when: redis_as_service and ansible_service_mgr|default() == 'systemd'

- name: create systemd tmpfiles configuration
template:
src: etc/tmpfiles.d/redis.conf.j2
dest: /etc/tmpfiles.d/redis.conf
mode: 0644
when:
- redis_as_service
- ansible_service_mgr|default() == 'systemd'
- (redis_sentinel_pidfile|dirname).startswith('/var/run') or (redis_sentinel_pidfile|dirname).startswith('/run')

- name: set sentinel to start at boot
service:
name: sentinel_{{ redis_sentinel_port }}
Expand Down
16 changes: 13 additions & 3 deletions tasks/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- default/redis.init.j2
paths:
- ../templates
when: redis_as_service and ansible_service_mgr | default != 'systemd'
when: redis_as_service and ansible_service_mgr|default() != 'systemd'

- name: create redis systemd service
template:
Expand All @@ -32,13 +32,23 @@
- default/redis.service.j2
paths:
- ../templates
when: redis_as_service and ansible_service_mgr | default == 'systemd'
when: redis_as_service and ansible_service_mgr|default() == 'systemd'

- name: create systemd tmpfiles configuration
template:
src: etc/tmpfiles.d/redis.conf.j2
dest: /etc/tmpfiles.d/redis.conf
mode: 0644
when:
- redis_as_service
- ansible_service_mgr|default() == 'systemd'
- (redis_pidfile|dirname).startswith('/var/run') or (redis_pidfile|dirname).startswith('/run')

- name: set redis to start at boot
service:
name: "{{ redis_service_name }}"
enabled: yes
daemon_reload: "{{ True if ansible_service_mgr | default == 'systemd' else omit }}"
daemon_reload: "{{ True if ansible_service_mgr|default() == 'systemd' else omit }}"
when: redis_as_service

# Check then create log dir to prevent aggressively overwriting permissions
Expand Down
2 changes: 0 additions & 2 deletions templates/default/redis.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Documentation=http://redis.io/documentation, man:redis-server(1)

[Service]
Type={{ 'forking' if redis_daemonize == 'yes' else 'simple' }}
ExecStartPre=-/bin/mkdir {{ redis_pidfile|dirname }}
ExecStartPre=/bin/chown -R {{ redis_user }}:{{ redis_group }} {{ redis_pidfile|dirname }}
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/{{ redis_port }}.conf
EnvironmentFile=-/etc/default/redis_{{ redis_port }}
PIDFile={{ redis_pidfile }}
Expand Down
2 changes: 0 additions & 2 deletions templates/default/redis_sentinel.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Documentation=http://redis.io/documentation, man:redis-sentinel(1)

[Service]
Type={{ 'forking' if redis_daemonize == 'yes' else 'simple' }}
ExecStartPre=-/bin/mkdir {{ redis_sentinel_pidfile|dirname }}
ExecStartPre=/bin/chown -R {{ redis_user }}:{{ redis_group }} {{ redis_sentinel_pidfile|dirname }}
ExecStart={{ redis_install_dir }}/bin/redis-server /etc/redis/sentinel_{{ redis_sentinel_port }}.conf --sentinel
EnvironmentFile=-/etc/default/sentinel_{{ redis_sentinel_port }}
PIDFile={{ redis_sentinel_pidfile }}
Expand Down
4 changes: 4 additions & 0 deletions templates/etc/tmpfiles.d/redis.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
d {{ redis_pidfile|dirname }} 0755 {{ redis_user }} {{ redis_group }}
{% if redis_pidfile|dirname != redis_sentinel_pidfile|dirname -%}
d {{ redis_sentinel_pidfile|dirname }} 0755 {{ redis_user }} {{ redis_group }}
{% endif -%}

0 comments on commit 3a597b8

Please sign in to comment.