From: lavado Date: Fri, 6 Dec 2019 23:11:36 +0000 (-0500) Subject: Node-exporter idempotent installation X-Git-Tag: v7.0.0rc1~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F8346%2F1;p=osm%2Fdevops.git Node-exporter idempotent installation Change-Id: I99f38c28f38e1982859a38ea2d35cada0c09d74a Signed-off-by: lavado --- diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index c1dd2cc7..e759c566 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -195,7 +195,6 @@ function uninstall_lightweight() { remove_stack $OSM_STACK_NAME remove_stack osm_elk - uninstall_prometheus_nodeexporter fi echo "Now osm docker images and volumes will be deleted" newgrp docker << EONG @@ -604,16 +603,28 @@ function install_osmclient(){ } function install_prometheus_nodeexporter(){ - sudo useradd --no-create-home --shell /bin/false node_exporter - sudo wget -q https://github.com/prometheus/node_exporter/releases/download/v$PROMETHEUS_NODE_EXPORTER_TAG/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz -P /tmp/ - sudo tar -C /tmp -xf /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz - sudo cp /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64/node_exporter /usr/local/bin - sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter - sudo rm -rf node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64* - sudo cp ${OSM_DEVOPS}/installers/docker/files/node_exporter.service /etc/systemd/system/node_exporter.service - sudo systemctl daemon-reload - sudo systemctl restart node_exporter - sudo systemctl enable node_exporter + if (systemctl -q is-active node_exporter) + then + echo "Node Exporter is already running." + else + echo "Node Exporter is not active, installing..." + if getent passwd node_exporter > /dev/null 2>&1; then + echo "node_exporter user exists" + else + echo "Creating user node_exporter" + sudo useradd --no-create-home --shell /bin/false node_exporter + fi + sudo wget -q https://github.com/prometheus/node_exporter/releases/download/v$PROMETHEUS_NODE_EXPORTER_TAG/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz -P /tmp/ + sudo tar -C /tmp -xf /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64.tar.gz + sudo cp /tmp/node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64/node_exporter /usr/local/bin + sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter + sudo rm -rf node_exporter-$PROMETHEUS_NODE_EXPORTER_TAG.linux-amd64* + sudo cp ${OSM_DEVOPS}/installers/docker/files/node_exporter.service /etc/systemd/system/node_exporter.service + sudo systemctl daemon-reload + sudo systemctl restart node_exporter + sudo systemctl enable node_exporter + echo "Node Exporter has been activated in this host." + fi return 0 }