Add handler when systemd is used

The service handler will restart a sysV or upstart init script when
present instead of a systemd service unit. In Xenial both upstart and
systemd service files can be present at the same time which can create
an unintended consequence by restarting the wrong service. This change
creates a guard so that if systemd is used we restart using a systemctl
command otherwise we use the service module.

> NOTE a systemctl command is used because the systemd module is not
  available until ansible 2.2

Change-Id: I71cd03ac0f10e88e83c085b7a87b7b2f710d0c3e
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-03-14 10:58:26 -05:00 committed by Andy McCrae
parent 4be8f4d031
commit b04b48bc7f
2 changed files with 16 additions and 5 deletions

View File

@ -18,8 +18,15 @@
when:
- ansible_service_mgr == 'systemd'
- name: Restart memcached
- name: Restart memcached (upstart)
service:
name: "memcached"
state: "restarted"
pattern: "memcached"
when:
- ansible_service_mgr != 'systemd'
- name: Restart memcached (systemd)
command: "systemctl restart memcached"
when:
- ansible_service_mgr == 'systemd'

View File

@ -38,7 +38,9 @@
owner: "root"
group: "root"
mode: "0644"
notify: Restart memcached
notify:
- Restart memcached (upstart)
- Restart memcached (systemd)
- name: Create memcached systemd service config dir
file:
@ -61,7 +63,8 @@
- ansible_pkg_mgr == 'apt'
- ansible_service_mgr != 'systemd'
- memcached_connections > 1024
notify: Restart memcached
notify:
- Restart memcached (upstart)
- name: Add automatic restart on failure
template:
@ -69,7 +72,8 @@
dest: "/etc/systemd/system/memcached.service.d/systemd-restart-on-failure.conf"
when:
- ansible_service_mgr == 'systemd'
notify: Restart memcached
notify:
- Restart memcached (systemd)
- name: Apply resource limits (systemd)
template:
@ -83,7 +87,7 @@
- memcached_connections > 1024
notify:
- Reload the systemd daemon
- Restart memcached
- Restart memcached (systemd)
- name: Configure soft file limits
lineinfile: