From 6aee7dbe350924175b21afe367ca37ddbc23c2f2 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 11 Jun 2023 17:29:27 -0400 Subject: [PATCH] simplify node-exporter --- prom-node-exporter | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/prom-node-exporter b/prom-node-exporter index 61fe700..c75b496 100755 --- a/prom-node-exporter +++ b/prom-node-exporter @@ -142,40 +142,24 @@ if [[ -d /etc/systemd/system ]]; then # we are using systemd fi - #why have - # this logic to handle both cases: The only differences of the + # I used to have logic to handle having the distro package installed, which would then just override it's service file in some ways. The only differences of the # packaged version in t11 is that it creates /var/log/prometheus and a # logrotate, but nothing is logged there. And it depends on - # prometheus-node-exporter-collectors, which is useful, but that - # package itself depends on prometheus-node-exporter. We have no + # prometheus-node-exporter-collectors, which is useful, but + # depends on prometheus-node-exporter. We would have no # reason to install prometheus-node-exporter except that - # dependency. We could fix that, but this is easier. So, we keep - # handling both cases in case we fix that or maybe run a different - # distro that doesn't have it. - if [[ -e /lib/systemd/system/prometheus-node-exporter.service ]]; then - - if [[ -e /etc/systemd/system/prometheus.service ]]; then - rm -f /etc/systemd/system/prometheus.service - sysd_reload=true - fi - - - i /etc/systemd/system/prometheus-node-exporter.service.d/override.conf <<'EOF' -[Unit] -# needed to continually restart -StartLimitIntervalSec=0 + # dependency. But since the collectors package is just a few + # small scripts we don't even currently use, and of course are not + # there on old versions, lets not try to use that package, and + # just manually install the files we want from upstream. + # https://github.com/prometheus-community/node-exporter-textfile-collector-scripts -[Service] -Restart=always -# time to sleep before restarting a service -RestartSec=600 + if [[ -e /lib/systemd/system/prometheus-node-exporter.service ]]; then + apt -y remove --purge prometheus-node-exporter + rm -fv /lib/systemd/system/prometheus-node-exporter.service + fi -# empty signifies to replace the existing value -ExecStart= -ExecStart=/usr/local/bin/prometheus-node-exporter $ARGS -EOF - else # we dont have the distro package installed - i /etc/systemd/system/prometheus-node-exporter.service <<'EOF' + i /etc/systemd/system/prometheus-node-exporter.service <<'EOF' [Unit] Description=Prometheus exporter for machine metrics Documentation=https://github.com/prometheus/node_exporter @@ -201,7 +185,6 @@ RestartSec=600 [Install] WantedBy=multi-user.target EOF - fi if $sysd_reload; then systemctl daemon-reload fi -- 2.30.2