From 65a0d4046e0541e361261038dd9a45c6e62a72b6 Mon Sep 17 00:00:00 2001 From: phil Date: Wed, 1 Nov 2023 08:23:48 +0100 Subject: [PATCH] "Monitor" service via systemd --- files/systemd/override.conf | 4 ++++ handlers/main.yaml | 9 ++++----- tasks/configure.yml | 15 +++++++++++++++ tasks/monitoring.yml | 8 -------- templates/monit.j2 | 8 -------- 5 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 files/systemd/override.conf delete mode 100644 templates/monit.j2 diff --git a/files/systemd/override.conf b/files/systemd/override.conf new file mode 100644 index 0000000..bf45b90 --- /dev/null +++ b/files/systemd/override.conf @@ -0,0 +1,4 @@ +# Ansible managed + +[Service] +Restart=always diff --git a/handlers/main.yaml b/handlers/main.yaml index d44eb01..b2fce98 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -8,12 +8,11 @@ name: nginx state: reloaded -- name: reload monit - ansible.builtin.service: - name: monit - state: reloaded - - name: reload fail2ban ansible.builtin.service: name: fail2ban state: reloaded + +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true diff --git a/tasks/configure.yml b/tasks/configure.yml index 29d3ba5..c444316 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -46,3 +46,18 @@ mode: "0644" notify: reload nginx when: nginx_type == 'gateway' or nginx_type == 'standalone' + +- name: "Configuration | Create systemd override directory" + ansible.builtin.file: + path: /etc/systemd/system/nginx.service.d + state: directory + mode: "0755" + +- name: "Configuration | Copy systemd override configuration" + ansible.builtin.copy: + src: systemd/override.conf + dest: /etc/systemd/system/nginx.service.d/override.conf + mode: "0644" + notify: + - Reload systemd + - reload nginx diff --git a/tasks/monitoring.yml b/tasks/monitoring.yml index fd1f547..e03349c 100644 --- a/tasks/monitoring.yml +++ b/tasks/monitoring.yml @@ -23,11 +23,3 @@ dest: /etc/nginx/sites-enabled/local-statistics state: link notify: reload nginx - -- name: "Monitoring | Copy Monit configuration" - ansible.builtin.template: - src: monit.j2 - dest: /etc/monit/conf-enabled/nginx - mode: 0644 - notify: reload monit - when: "'monit' in ansible_facts.packages" diff --git a/templates/monit.j2 b/templates/monit.j2 deleted file mode 100644 index 0215ec7..0000000 --- a/templates/monit.j2 +++ /dev/null @@ -1,8 +0,0 @@ -# {{ ansible_managed }} - -check process nginx with pidfile /var/run/nginx.pid - group webserver - start program = "/usr/sbin/service nginx start" - stop program = "/usr/sbin/service nginx stop" - if failed host 127.0.0.1 port {{ nginx_port | default(80) }} for 3 cycles then restart - if 5 restarts with 5 cycles then timeout