From c735a6deead13db2bac18e48cb4715643c6478f8 Mon Sep 17 00:00:00 2001 From: N Date: Sun, 23 Jun 2019 14:04:48 +0100 Subject: [PATCH] fix(service): ensure service file is removed on clean --- docs/README.rst | 2 +- prometheus/archive/alternatives/install.sls | 8 +++++--- prometheus/archive/clean.sls | 3 ++- prometheus/archive/install.sls | 3 +++ prometheus/config/users/clean.sls | 3 +++ prometheus/config/users/install.sls | 3 +++ prometheus/service/clean.sls | 10 +++++++++- prometheus/service/running.sls | 4 ++-- 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/README.rst b/docs/README.rst index d93ee9f..4c5a574 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -13,7 +13,7 @@ prometheus-formula :alt: Semantic Release :scale: 100% :target: https://github.com/semantic-release/semantic-release -Manage Prometheus. +Manage Prometheus on MacOS, GNU/Linux and FreeBSD. .. contents:: **Table of Contents** diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index 67d501b..c3553b1 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -14,14 +14,16 @@ include: {%- for name in p.wanted %} {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + {%- if grains.os_family == 'Suse' %} prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: cmd.run: - - onlyif: {{ grains.os_family in ('Suse',) }} - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted + {%- else %} + prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: - name: prometheus-{{ name }}-home @@ -40,9 +42,9 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: - require: - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - - onlyif: {{ grains.os_family not in ('Suse',) }} - {% for b in p.pkg[name]['binaries'] %} + {%- endif %} + {% for b in p.pkg[name]['binaries'] %} prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: cmd.run: diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index c3cf5f1..cb487d3 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -6,9 +6,11 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} {%- set sls_users_clean = tplroot ~ '.config.users.clean' %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} include: - {{ sls_users_clean }} + - {{ sls_service_clean }} - {{ sls_alternatives_clean }} {%- for name in p.wanted %} @@ -31,4 +33,3 @@ prometheus-archive-clean-{{ name }}-user-absent: prometheus-archive-clean-basedir-file-directory: file.absent: - name: {{ p.dir.basedir }} - diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 8548b6d..93c1c83 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -53,6 +53,8 @@ prometheus-archive-install-{{ name }}-file-directory: - archive: prometheus-archive-install-{{ name }}-archive-extracted - file: prometheus-config-file-basedir-file-directory + {%- if grains.os_family not in ('MacOS', 'FreeBSD', 'Windows') %} + prometheus-archive-install-{{ name }}-managed-service: file.managed: - name: {{ p.dir.service }}/{{ name }}.service @@ -81,6 +83,7 @@ prometheus-archive-install-{{ name }}-managed-service: - require: - file: prometheus-archive-install-{{ name }}-managed-service + {%- endif %} {%- endif %} {%- endif %} {%- endfor %} diff --git a/prometheus/config/users/clean.sls b/prometheus/config/users/clean.sls index 20c200e..7917073 100644 --- a/prometheus/config/users/clean.sls +++ b/prometheus/config/users/clean.sls @@ -10,6 +10,9 @@ prometheus-config-user-clean-{{ name }}-user-absent: user.absent: - name: {{ name }} + {%- if grains.os_family == 'MacOS' %} + - onlyif: /usr/bin/dscl . list /Users | grep {{ name }} >/dev/null 2>&1 + {%- endif %} group.absent: - name: {{ name }} - require: diff --git a/prometheus/config/users/install.sls b/prometheus/config/users/install.sls index c63dac3..059009c 100644 --- a/prometheus/config/users/install.sls +++ b/prometheus/config/users/install.sls @@ -18,5 +18,8 @@ prometheus-config-user-install-{{ name }}-user-present: - createhome: false - groups: - {{ name }} + {%- if grains.os_family == 'MacOS' %} + - unless: /usr/bin/dscl . list /Users | grep {{ name }} >/dev/null 2>&1 + {%- endif %} {%- endfor %} diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 31b0076..6ac6364 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -15,9 +15,17 @@ prometheus-service-clean-{{ name }}-service-dead: {%- if grains.kernel|lower == 'linux' %} - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} + file.absent: + - name: {{ prometheus.dir.service }}/{{ name }}.service + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + cmd.run: + - onlyif: {{ grains.kernel|lower == 'linux' }} + - name: systemctl daemon-reload + - require: + - file: prometheus-service-clean-{{ name }}-service-dead {%- endif %} - {%- endfor %} prometheus-config-file-var-file-absent: diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index ec7a808..f174e37 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -23,13 +23,13 @@ prometheus-config-file-var-file-directory: {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} + {%- if grains.kernel|lower == 'linux' %} prometheus-service-running-{{ name }}-service-unmasked: service.unmasked: - name: {{ name }} - require: - file: prometheus-config-file-var-file-directory - {%- if grains.kernel|lower == 'linux' %} - onlyif: - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} @@ -43,9 +43,9 @@ prometheus-service-running-{{ name }}-service-running: - file: prometheus-config-file-{{ name }}-file-managed {%- endif %} - require: - - service: prometheus-service-running-{{ name }}-service-unmasked - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} + - service: prometheus-service-running-{{ name }}-service-unmasked - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %}