From 04be7724372c98496b1e237f9ba39e341c007e04 Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 10 Jun 2023 18:30:09 +0200 Subject: [PATCH] Add monit monitoring --- handlers/main.yml | 15 ++++++++++----- tasks/main.yml | 5 +++++ tasks/monitoring.yml | 8 ++++++++ templates/monit.j2 | 8 ++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tasks/monitoring.yml create mode 100644 templates/monit.j2 diff --git a/handlers/main.yml b/handlers/main.yml index 8e027d3..8459573 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,19 +1,24 @@ --- - name: reload apache2 - service: + ansible.builtin.service: name: apache2 state: reloaded - name: reload php-fpm - service: + ansible.builtin.service: name: "php{{ php_version.stdout }}-fpm" state: reloaded - name: stop php-fpm-socket - command: systemctl stop php-fpm@*.socket + ansible.builtin.command: systemctl stop php-fpm@*.socket - name: stop php-fpm-service - command: systemctl stop php-fpm@*.service + ansible.builtin.command: systemctl stop php-fpm@*.service - name: start php-fpm-socket - command: systemctl start php-fpm@*.socket --all + ansible.builtin.command: systemctl start php-fpm@*.socket --all + +- name: reload monit + ansible.builtin.service: + name: monit + state: reloaded diff --git a/tasks/main.yml b/tasks/main.yml index a1bcca7..2f57280 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,3 +18,8 @@ - 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 new file mode 100644 index 0000000..741e6e6 --- /dev/null +++ b/tasks/monitoring.yml @@ -0,0 +1,8 @@ +--- +- 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/templates/monit.j2 b/templates/monit.j2 new file mode 100644 index 0000000..5c322a6 --- /dev/null +++ b/templates/monit.j2 @@ -0,0 +1,8 @@ +# {{ ansible_managed }} + +check process php-fpm with pidfile /run/php/php{{ php_version.stdout }}.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_version.stdout }}-fpm.sock for 3 cycles then restart + if 3 restarts within 5 cycles then timeout