From f5b5e06629293375ec99fbedd04aa2528b886429 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 19 Apr 2018 19:48:50 +0200 Subject: [PATCH] systemd unit for the prometheus server. Also, do not overwrite the configuration file. --- prometheus/defaults/main.yml | 2 +- prometheus/files/prometheus.systemd | 16 ++++++++++++++++ prometheus/tasks/main.yml | 14 ++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 prometheus/files/prometheus.systemd diff --git a/prometheus/defaults/main.yml b/prometheus/defaults/main.yml index db9985ee..83753e50 100644 --- a/prometheus/defaults/main.yml +++ b/prometheus/defaults/main.yml @@ -1,6 +1,6 @@ --- prometheus_install: True -prometheus_version: 2.1.0 +prometheus_version: 2.2.1 prometheus_dir: 'prometheus-{{ prometheus_version }}.linux-amd64' prometheus_file: '{{ prometheus_dir }}.tar.gz' prometheus_download_url: 'https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/{{ prometheus_file }}' diff --git a/prometheus/files/prometheus.systemd b/prometheus/files/prometheus.systemd new file mode 100644 index 00000000..52a1ca8c --- /dev/null +++ b/prometheus/files/prometheus.systemd @@ -0,0 +1,16 @@ +[Unit] +Description=Prometheus - Prometheus metrics collector. +Documentation=https://prometheus.io/docs/introduction/overview/ +After=network.target + +[Service] +Type=simple +User={{ prometheus_user }} +Group={{ prometheus_user }} +EnvironmentFile=/etc/default/prometheus +ExecStart=${PROMETHEUS_CMD} --config.file=${PROMETHEUS_CONF} --storage.tsdb.path=${PROMETHEUS_DATADIR} --log.level=${PROMETHEUS_LOGLEVEL} ${PROMETHEUS_OPTS} +Restart=on-failure + +[Install] +WantedBy=multi-user.target + diff --git a/prometheus/tasks/main.yml b/prometheus/tasks/main.yml index 78e40e84..9dc7bfa6 100644 --- a/prometheus/tasks/main.yml +++ b/prometheus/tasks/main.yml @@ -26,15 +26,21 @@ notify: Restart prometheus - name: Install the prometheus configuration - template: src=prometheus.yml.j2 dest={{ prometheus_confdir }}/prometheus.yml + template: src=prometheus.yml.j2 dest={{ prometheus_confdir }}/prometheus.yml force=no notify: Reload prometheus - - name: Install the prometheus upstart script - copy: src=prometheus.upstart dest=/etc/init/prometheus.conf mode=0644 owner=root group=root - - name: Install the prometheus defaults template: src=prometheus.default.j2 dest=/etc/default/prometheus mode=0644 owner=root group=root + - name: Install the prometheus upstart script + copy: src=prometheus.upstart dest=/etc/init/prometheus.conf mode=0644 owner=root group=root + when: ansible_service_mgr != 'systemd' + + - name: Install the prometheus server systemd unit + copy: src=prometheus.systemd dest=/etc/systemd/system/prometheus.service mode=0644 owner=root group=root + when: ansible_service_mgr == 'systemd' + notify: systemd reload + - name: Ensure that prometheus is started and enabled service: name=prometheus state=started enabled=yes