diff --git a/docs/README.rst b/docs/README.rst index 2fd9751..d93ee9f 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -53,6 +53,11 @@ starts the associated prometheus service. This state will install the prometheus from archive file only. +``prometheus.archive.alternatives`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will install the prometheus linux alternatives for archives only. + ``prometheus.package`` ^^^^^^^^^^^^^^^^^^^^ @@ -107,6 +112,11 @@ This state will remove the prometheus package and has a depency on This state will uninstall the prometheus archive-extracted directory only. +``prometheus.package.archive.alternatives.clean`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will uninstall the prometheus linux alternatives for archives only. + ``prometheus.package.repo.clean`` ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pillar.example b/pillar.example index 5ddde08..6c3a797 100644 --- a/pillar.example +++ b/pillar.example @@ -6,6 +6,8 @@ prometheus: - prometheus - pushgateway - node_explorer + # no memcached_exporter in upstream repo - only archive + # memcached_exporter use_upstream_repo: False use_upstream_archive: True diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index b6b17e5..67d501b 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -5,7 +5,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} {%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %} @@ -21,8 +21,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: - 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 - - require: - - sls: {{ sls_archive_install }} prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: @@ -33,8 +31,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: - order: 10 - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted - - require: - - sls: {{ sls_archive_install }} - onlyif: {{ grains.os_family not in ('Suse',) }} prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index a1bfe5e..43c70c6 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -5,10 +5,10 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} - - {%- if p.use_upstream_archive %} +{%- set sls_users_clean = tplroot ~ '.config.users.clean' %} include: + - {{ sls_users_clean }} - {{ sls_alternatives_clean }} {%- for name in p.wanted %} @@ -31,13 +31,9 @@ prometheus-archive-clean-{{ name }}-user-absent: {%- endfor %} -prometheus-archive-clean-file-directory: +prometheus-archive-clean-basedir-file-directory: file.absent: - - names: - - {{ p.dir.basedir }} - - {{ p.dir.etc }} - - {{ p.dir.var }} + - name: {{ p.dir.basedir }} - require: - sls: {{ sls_alternatives_clean }} - {%- endif %} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index d169323..507b0e7 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -6,35 +6,24 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_users_install = tplroot ~ '.config.users' %} -prometheus-archive-install-file-directory: +include: + - {{ sls_users_install }} + +prometheus-config-file-basedir-file-directory: file.directory: - - names: - - {{ p.dir.basedir }} - - {{ p.dir.etc }} - - {{ p.dir.var }} + - name: {{ p.dir.basedir }} - user: prometheus - group: prometheus - mode: 755 - makedirs: True + # require: + # sls: {{ sls_users_install }} {%- for name in p.wanted %} {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} -prometheus-archive-install-{{ name }}-user-present: - group.present: - - name: {{ name }} - - require_in: - - user: prometheus-archive-install-{{ name }}-user-present - user.present: - - name: {{ name }} - - shell: /bin/false - - createhome: false - - groups: - - {{ name }} - - require_in: - - archive: prometheus-archive-install-{{ name }}-archive-extracted - prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: - name: {{ p.dir.basedir }} @@ -47,6 +36,8 @@ prometheus-archive-install-{{ name }}-archive-extracted: - recurse: - user - group + - require: + - file: prometheus-config-file-basedir-file-directory {%- if name in p.service %} @@ -59,6 +50,7 @@ prometheus-archive-install-{{ name }}-file-directory: - makedirs: True - require: - archive: prometheus-archive-install-{{ name }}-archive-extracted + - file: prometheus-config-file-basedir-file-directory prometheus-archive-install-{{ name }}-managed-service: file.managed: @@ -82,6 +74,7 @@ prometheus-archive-install-{{ name }}-managed-service: stop: '' #not needed - require: - file: prometheus-archive-install-{{ name }}-file-directory + - file: prometheus-config-file-basedir-file-directory {%- endif %} {%- endfor %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls index e72d83c..e9da0e3 100644 --- a/prometheus/config/args/clean.sls +++ b/prometheus/config/args/clean.sls @@ -55,3 +55,7 @@ prometheus-config-args-{{ name }}-file-absent: {%- endif %} {%- endif %} {%- endfor %} + +prometheus-config-file-args-file-absent: + file.absent: + - name: {{ prometheus.dir.args }} diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls index 787aa16..0512dda 100644 --- a/prometheus/config/args/install.sls +++ b/prometheus/config/args/install.sls @@ -9,8 +9,18 @@ {%- set sls_service_install = tplroot ~ '.service' %} include: - - {{ sls_config_install }} - {{ sls_service_install }} + - {{ sls_config_install }} + +prometheus-config-file-args-file-directory: + file.directory: + - name: {{ prometheus.dir.args }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + # require: + # sls: {{ sls_config_install }}.users {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -28,6 +38,8 @@ prometheus-config-args-{{ name }}-data-dir: - makedirs: True - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if args and grains.os_family == 'FreeBSD' %} @@ -43,7 +55,7 @@ prometheus-config-args-args-web-listen-address: {%- endif %} {%- if 'collector.textfile.directory' in args.keys() %} -prometheus-config-args-{{ name }}--collector-textfile-directory: +prometheus-config-args-{{ name }}-collector-textfile-directory: sysrc.managed: - name: {{ name }}_textfile_dir - value: {{ args.pop('collector.textfile.directory') }} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 7d54d55..cf7559a 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -4,3 +4,4 @@ include: - .file.clean - .args.clean + - .users.clean diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls index a86ce29..10b6f95 100644 --- a/prometheus/config/file/clean.sls +++ b/prometheus/config/file/clean.sls @@ -19,3 +19,7 @@ prometheus-config-file-{{ name }}-file-absent: - sls: {{ sls_service_clean }} {%- endfor %} + +prometheus-config-file-etc-file-absent: + file.absent: + - name: {{ prometheus.dir.etc }} diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls index 0359979..bb48a1d 100644 --- a/prometheus/config/file/install.sls +++ b/prometheus/config/file/install.sls @@ -5,11 +5,23 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- set sls_package_install = tplroot ~ '.package.install' %} +{%- set sls_users_install = tplroot ~ '.config.users' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} +{%- set sls_package_install = tplroot ~ '.package' %} include: - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - {{ sls_users_install }} + +prometheus-config-file-etc-file-directory: + file.directory: + - name: {{ prometheus.dir.etc }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + # require: + # sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -29,7 +41,8 @@ prometheus-config-file-{{ name }}-file-managed: - context: config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} - require: - - sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - file: prometheus-config-file-etc-file-directory + # user: prometheus-config-user-install-{{ name }}-user-present {%- endif %} {%- endfor %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 8919ea2..6923174 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -2,5 +2,6 @@ # vim: ft=sls include: + - .users - .args - .file diff --git a/prometheus/config/users/clean.sls b/prometheus/config/users/clean.sls new file mode 100644 index 0000000..20c200e --- /dev/null +++ b/prometheus/config/users/clean.sls @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + + {%- for name in prometheus.wanted %} + +prometheus-config-user-clean-{{ name }}-user-absent: + user.absent: + - name: {{ name }} + group.absent: + - name: {{ name }} + - require: + - user: prometheus-config-user-clean-{{ name }}-user-absent + + {%- endfor %} diff --git a/prometheus/config/users/init.sls b/prometheus/config/users/init.sls new file mode 100644 index 0000000..051d698 --- /dev/null +++ b/prometheus/config/users/init.sls @@ -0,0 +1,5 @@ +#.-*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/users/install.sls b/prometheus/config/users/install.sls new file mode 100644 index 0000000..c63dac3 --- /dev/null +++ b/prometheus/config/users/install.sls @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + + {%- for name in prometheus.wanted %} + +prometheus-config-user-install-{{ name }}-user-present: + group.present: + - name: {{ name }} + - require_in: + - user: prometheus-config-user-install-{{ name }}-user-present + user.present: + - name: {{ name }} + - shell: /bin/false + - createhome: false + - groups: + - {{ name }} + + {%- endfor %} diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls deleted file mode 100644 index 14401e2..0000000 --- a/prometheus/exporters/node/clean.sls +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - -prometheus-exporters-node-service-dead: - service.dead: - - name: {{ prometheus.exporters.node.service }} - - enable: False - -prometheus-exporters-node-pkg-removed: - pkg.removed: - - name: {{ prometheus.exporters.node.pkg.name }} - - require: - - service: prometheus-exporters-node-service-dead - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- for parameter in ['args', 'listen_address', 'textfile_dir'] %} -prometheus-exporters-node-args-{{ parameter }}: - sysrc.absent: - - name: node_exporter_{{ parameter }} - - require: - - service: prometheus-exporters-node-service-dead -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls deleted file mode 100644 index f8f7534..0000000 --- a/prometheus/exporters/node/init.sls +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -prometheus-exporters-node-pkg-installed: - pkg.installed: - - name: {{ prometheus.exporters.node.pkg.name }} - -{%- if 'args' in prometheus.exporters.node %} -{%- set args = prometheus.exporters.node.get('args', {}) -%} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'web.listen-address' in args.keys() %} -{%- set value = args.pop('web.listen-address') %} -prometheus-exporters-node-args-web-listen-address: - sysrc.managed: - - name: node_exporter_listen_address - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -{%- if 'collector.textfile.directory' in args.keys() %} -{%- set value = args.pop('collector.textfile.directory') %} -prometheus-exporters-node-args-collector-textfile-directory: - sysrc.managed: - - name: node_exporter_textfile_dir - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -prometheus-exporters-node-args: - sysrc.managed: - - name: node_exporter_args - # service node_exporter restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-exporters-node-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-exporters-node-args: - file.managed: - - name: {{ prometheus.exporters.node.config_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} -{%- endif %} - -prometheus-exporters-node-service-running: - service.running: - - name: {{ prometheus.exporters.node.service }} - - enable: True - - watch: - - pkg: prometheus-exporters-node-pkg-installed diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index 59f0ab5..23b9ba7 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -8,6 +8,9 @@ include: - {{ sls_config_clean }} + {%- if prometheus.use_upstream_repo %} + - .repo.clean + {%- endif %} {%- for name in prometheus.wanted %} {%- if name in prometheus.pkg %} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index dc6caa6..7bdcb98 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -5,7 +5,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} - {%- if prometheus.pkg.use_upstream_repo %} + {%- if prometheus.use_upstream_repo %} include: - .repo diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 9a69790..31b0076 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -17,4 +17,9 @@ prometheus-service-clean-{{ name }}-service-dead: {%- endif %} {%- endif %} + {%- endfor %} + +prometheus-config-file-var-file-absent: + file.absent: + - name: {{ prometheus.dir.var }} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index ec5300f..2cec36c 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -3,14 +3,24 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_args = tplroot ~ '.config.args.install' %} -{%- set sls_config_file = tplroot ~ '.config.file.install' %} +{%- set sls_config_args = tplroot ~ '.config.args' %} +{%- set sls_config_file = tplroot ~ '.config.file' %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - {{ sls_config_args }} - {{ sls_config_file }} +prometheus-config-file-var-file-directory: + file.directory: + - name: {{ prometheus.dir.var }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + - require: + - file: prometheus-config-file-etc-file-directory + {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} @@ -18,8 +28,7 @@ prometheus-service-running-{{ name }}-service-unmasked: service.unmasked: - name: {{ name }} - require: - - sls: {{ sls_config_args }} - - sls: {{ sls_config_file }} + - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} - onlyif: - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 @@ -35,8 +44,7 @@ prometheus-service-running-{{ name }}-service-running: {%- endif %} - require: - service: prometheus-service-running-{{ name }}-service-unmasked - - sls: {{ sls_config_args }} - - sls: {{ sls_config_file }} + - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %}