Merge pull request #54 from lagooj/feat/manage_env_vars_systemd

Manage env vars
This commit is contained in:
Daniel 2021-02-10 18:25:23 +00:00 committed by GitHub
commit f51bee4da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 0 deletions

View File

@ -197,6 +197,10 @@ prometheus:
source: https://github.com/wrouesnel/postgres_exporter/releases/download/v0.8.0/postgres_exporter_v0.8.0_linux-amd64.tar.gz
skip_verify: true
mysqld_exporter:
service:
env:
- 'DATA_SOURCE_NAME=foo:bar@/'
linux:
# 'Alternatives system' priority: zero disables (default)
# yamllint disable-line rule:braces

View File

@ -126,6 +126,7 @@ prometheus-archive-install-{{ name }}-managed-service:
name: {{ name }}
user: {{ name }}
group: {{ name }}
env: {{ p.pkg.component[name]['service'].get('env', [])|tojson }}
workdir: {{ p.dir.var }}/{{ name }}
stop: ''
{%- if name in ('node_exporter', 'consul_exporter') or 'config_file' not in p.pkg.component[name] %}

View File

@ -8,6 +8,9 @@ After=
Documentation=https://github.com/saltstack-formulas/prometheus-formula
[Service]
{% for var in env %}
Environment={{ var }}
{% endfor %}
User={{ user }}
Group={{ group }}
WorkingDirectory={{ workdir }}

View File

@ -10,12 +10,14 @@ control 'prometheus components' do
node_exporter_service = 'prometheus-node-exporter'
php_fpm_exporter_service = 'php-fpm_exporter'
postgres_exporter_service = 'prometheus-postgres-exporter'
mysqld_exporter_service = 'prometheus-mysqld-exporter'
else
service_dir = '/usr/lib/systemd/system'
alert_manager_service = 'alertmanager'
node_exporter_service = 'node_exporter'
php_fpm_exporter_service = 'php-fpm_exporter'
postgres_exporter_service = 'postgres_exporter'
mysqld_exporter_service = 'mysqld_exporter'
end
# describe package('cron') do
@ -45,6 +47,12 @@ control 'prometheus components' do
describe user('postgres_exporter') do
it { should exist }
end
describe group('mysqld_exporter') do
it { should exist }
end
describe user('mysqld_exporter') do
it { should exist }
end
describe directory('/var/lib/prometheus') do
it { should exist }
end
@ -131,6 +139,25 @@ control 'prometheus components' do
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
end
describe directory('/opt/prometheus/mysqld_exporter-v0.12.1') do
it { should exist }
its('group') { should eq 'root' }
end
describe file('/opt/prometheus/mysqld_exporter-v0.12.1/mysqld_exporter') do
it { should exist }
its('group') { should eq 'root' }
end
describe directory('/var/lib/prometheus/mysqld_exporter') do
it { should exist }
its('group') { should eq 'mysqld_exporter' }
end
describe file("#{service_dir}/#{mysqld_exporter_service}.service") do
it { should exist }
its('content') { should match 'Environment=DATA_SOURCE_NAME=foo:bar@/' }
its('group') { should eq 'root' }
its('mode') { should cmp '0644' }
end
describe file('/usr/local/sbin/alertmanager') do
it { should exist }
its('group') { should eq 'root' }

View File

@ -17,6 +17,7 @@ prometheus:
- consul_exporter
- php-fpm_exporter
- postgres_exporter
- mysqld_exporter
# - memcached_exporter # not in upstream repo, only archive
exporters:
@ -100,6 +101,13 @@ prometheus:
# This is to test that any fancy name we use, will work in archive mode
name: my-fancy-consul-exporter-service
mysqld_exporter:
service:
args:
web.listen-address: 0.0.0.0:9192
env:
- 'DATA_SOURCE_NAME=foo:bar@/'
prometheus:
service:
args: