From 1eb01f7c00df8cb6f7a2dd396c3191ef677efd09 Mon Sep 17 00:00:00 2001 From: phil Date: Mon, 20 Nov 2023 11:55:43 +0100 Subject: [PATCH] Control restart via systemd --- files/grafana.monit | 8 -------- files/systemd/override.conf | 8 ++++++++ handlers/main.yml | 11 ++++------- tasks/configuration.yml | 21 +++++++++++++++++---- 4 files changed, 29 insertions(+), 19 deletions(-) delete mode 100644 files/grafana.monit create mode 100644 files/systemd/override.conf diff --git a/files/grafana.monit b/files/grafana.monit deleted file mode 100644 index 3fdb0b4..0000000 --- a/files/grafana.monit +++ /dev/null @@ -1,8 +0,0 @@ -# {{ ansible_managed }} - -check process grafana with pidfile /var/run/grafana/grafana-server.pid - group monitor - start program = "/bin/systemctl start grafana-server.service" - stop program = "/bin/systemctl stop grafana-server.service" - if failed host localhost port 3000 with timeout 15 seconds for 3 times within 4 cycles then restart - if 5 restarts with 5 cycles then timeout diff --git a/files/systemd/override.conf b/files/systemd/override.conf new file mode 100644 index 0000000..9b823fa --- /dev/null +++ b/files/systemd/override.conf @@ -0,0 +1,8 @@ +# Ansible managed + +[Unit] +StartLimitIntervalSec=6 +StartLimitBurst=10 + +[Service] +Restart=always diff --git a/handlers/main.yml b/handlers/main.yml index 7b4bc44..a3dbb04 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,10 +1,7 @@ --- -- name: restart grafana - ansible.builtin.service: +- name: Restart grafana-server + ansible.builtin.systemd: name: grafana-server state: restarted - -- name: reload monit - ansible.builtin.service: - name: monit - state: reloaded + daemon_reload: true + enabled: true diff --git a/tasks/configuration.yml b/tasks/configuration.yml index c23fbc5..599c362 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -1,19 +1,32 @@ --- -- name: "Grafana | Aktivere und starte Service" +- name: "Configuration | Aktivere und starte Service" ansible.builtin.systemd: name: grafana-server enabled: true state: started daemon_reload: true -- name: "Grafana | Erzeuge Grafana-Konfiguration" +- name: "Configuration | Erzeuge Grafana-Konfiguration" ansible.builtin.template: src: grafana.ini dest: /etc/grafana/grafana.ini mode: "0640" - notify: restart grafana + notify: Restart grafana-server -- name: "Grafana | Installiere Image Renderer Module" +- name: "Configuration | Installiere Image Renderer Module" ansible.builtin.command: cmd: grafana-cli plugins install grafana-image-renderer creates: /var/lib/grafana/plugins/grafana-image-renderer + +- name: "Configuration | Create systemd override directory" + ansible.builtin.file: + path: /etc/systemd/system/grafana-server.service.d + state: directory + mode: "0755" + +- name: "Configuration | Copy systemd override configuration" + ansible.builtin.copy: + src: systemd/override.conf + dest: /etc/systemd/system/grafana-server.service.d + mode: "0644 + notify: Restart grafana-server