From d60c4d99b90cf125a413429c81ed949154b827cb Mon Sep 17 00:00:00 2001 From: phil Date: Wed, 1 Nov 2023 08:13:57 +0100 Subject: [PATCH] Use systemd to "monitor" and restart the service --- files/systemd/override.conf | 4 ++++ tasks/main.yml | 4 ---- tasks/monitoring.yml | 8 -------- tasks/php.yml | 9 +++++++++ templates/monit.j2 | 13 ------------- 5 files changed, 13 insertions(+), 25 deletions(-) create mode 100644 files/systemd/override.conf delete mode 100644 tasks/monitoring.yml delete mode 100644 templates/monit.j2 diff --git a/files/systemd/override.conf b/files/systemd/override.conf new file mode 100644 index 0000000..f079d62 --- /dev/null +++ b/files/systemd/override.conf @@ -0,0 +1,4 @@ +## Managed by Ansible + +[Service] +Restart=always diff --git a/tasks/main.yml b/tasks/main.yml index 460aa66..a1bcca7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,7 +18,3 @@ - name: User tasks ansible.builtin.import_tasks: user.yml tags: never, user - -- name: Monitoring tasks - ansible.builtin.import_tasks: monitoring.yml - tags: monitoring diff --git a/tasks/monitoring.yml b/tasks/monitoring.yml deleted file mode 100644 index 741e6e6..0000000 --- a/tasks/monitoring.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: "Monitoring | Enable Monit monitoring" - ansible.builtin.template: - src: monit.j2 - dest: /etc/monit/conf-enabled/phpfpm - mode: "0644" - when: '"monit" in ansible_facts.packages' - notify: reload monit diff --git a/tasks/php.yml b/tasks/php.yml index 6a18230..4c7d381 100644 --- a/tasks/php.yml +++ b/tasks/php.yml @@ -37,3 +37,12 @@ path: /etc/systemd/system/php-fpm@.service.d state: directory mode: "0755" + +- name: "PHP | Copy systemd override configuration" + ansible.builtin.copy: + src: systemd/override.conf + dest: /etc/systemd/system/php-fpm@.service.d/override.conf + mode: "0644" + notify: + - stop php-fpm-service + - start php-fpm-socket diff --git a/templates/monit.j2 b/templates/monit.j2 deleted file mode 100644 index 8f715d5..0000000 --- a/templates/monit.j2 +++ /dev/null @@ -1,13 +0,0 @@ -# {{ ansible_managed }} - -check process php-fpm with pidfile /run/php/php{{ php_version.stdout }}-fpm.pid - group webserver - start program = "/usr/sbin/service php{{ php_version.stdout }}-fpm start" - stop program = "/usr/sbin/service php{{ php_version.stdout }}-fpm stop" - if failed unixsocket /run/php/php{{ php_version.stdout }}-fpm.sock for 3 cycles then restart - if 3 restarts within 5 cycles then timeout - -{% if "apache2" in ansible_facts.packages %} -check file basedir with path /var/log/apache2/error.log - if match "open_basedir restriction in effect" then alert -{% endif %}