From 83484ff4a5177ddf0ffd39f89e06a2a48d76b6c5 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sun, 5 Feb 2023 20:40:26 +0900 Subject: [PATCH] Deploy `snmp_exporter` service and enable it. --- .../files/etc/supervisor/conf.d/snmp_exporter.conf | 8 -------- .../files/etc/systemd/system/snmp_exporter.service | 10 ++++++++++ cookbooks/prometheus/snmp_exporter_setup.rb | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 cookbooks/prometheus/files/etc/supervisor/conf.d/snmp_exporter.conf create mode 100644 cookbooks/prometheus/files/etc/systemd/system/snmp_exporter.service diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/snmp_exporter.conf b/cookbooks/prometheus/files/etc/supervisor/conf.d/snmp_exporter.conf deleted file mode 100644 index 38e00ac..0000000 --- a/cookbooks/prometheus/files/etc/supervisor/conf.d/snmp_exporter.conf +++ /dev/null @@ -1,8 +0,0 @@ -[program:snmp_exporter] -command=/usr/local/bin/snmp_exporter --config.file /etc/prometheus_exporters.d/snmp.yml -stdout_logfile=/var/log/supervisor/snmp_exporter.log -redirect_stderr=true -stdout_logfile_maxbytes=1MB -stdout_logfile_backups=5 -autorestart=true -stopsignal=HUP diff --git a/cookbooks/prometheus/files/etc/systemd/system/snmp_exporter.service b/cookbooks/prometheus/files/etc/systemd/system/snmp_exporter.service new file mode 100644 index 0000000..7e64c7d --- /dev/null +++ b/cookbooks/prometheus/files/etc/systemd/system/snmp_exporter.service @@ -0,0 +1,10 @@ +[Unit] +Description=SNMP Exporter + +[Service] +User=root +Group=root +ExecStart=/usr/local/bin/snmp_exporter --config.file /etc/prometheus_exporters.d/snmp.yml + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/prometheus/snmp_exporter_setup.rb b/cookbooks/prometheus/snmp_exporter_setup.rb index 5b11a89..e3f99ba 100644 --- a/cookbooks/prometheus/snmp_exporter_setup.rb +++ b/cookbooks/prometheus/snmp_exporter_setup.rb @@ -3,13 +3,15 @@ link '/etc/prometheus_exporters.d/snmp.yml' do to "#{node['snmp_exporter']['storage']}snmp.yml" end -# Deploy `supervisord` config: -remote_file '/etc/supervisor/conf.d/snmp_exporter.conf' do +# Deploy `systemd` config: +remote_file '/etc/systemd/system/snmp_exporter.service' do owner 'root' group 'root' mode '644' +end - notifies :restart, 'service[supervisor]' +service 'snmp_exporter' do + action [:enable, :start] end # Deploy `consul` config: