Skip to content

Instantly share code, notes, and snippets.

@downspot
Last active October 31, 2023 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save downspot/9a5712fedc607f1b2095efce504987e7 to your computer and use it in GitHub Desktop.
Save downspot/9a5712fedc607f1b2095efce504987e7 to your computer and use it in GitHub Desktop.
#!/bin/sh
VERSION=${VERSION:-1.6.1}
URL=https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz
FILENAME=${URL##*/}
ROOT_PATH=$PWD/opt/pkg
APP_ROOT_PATH=$ROOT_PATH/opt/node_exporter
ITERATION=${ITERATION:-1}
mkdir -p $APP_ROOT_PATH/script
curl -sLO $URL
tar -C $APP_ROOT_PATH -xvf $FILENAME --strip-components=1
rm $FILENAME
cat > $APP_ROOT_PATH/script/after-install.sh <<'EOF'
#/usr/bin/env bash
/usr/sbin/useradd node_exporter &>/dev/null
/usr/bin/systemctl enable --now node_exporter &>/dev/null || true
/usr/bin/systemctl daemon-reload
EOF
cat > $APP_ROOT_PATH/script/before-remove.sh <<'EOF'
#/usr/bin/env bash
/usr/bin/systemctl disable --now node_exporter &>/dev/null || true
EOF
cat > $APP_ROOT_PATH/script/after-remove.sh <<'EOF'
#/usr/bin/env bash
/usr/bin/systemctl daemon-reload
EOF
mkdir -p $ROOT_PATH/etc/systemd/system
cat > $ROOT_PATH/etc/systemd/system/node_exporter.service <<'EOF'
[Unit]
Description=
Requires=network.target
After=network.target
Requires=time-sync.target
After=time-sync.target
[Service]
Type=simple
ExecStart=/opt/node_exporter/node_exporter --web.listen-address=0.0.0.0:9100 --log.level=warn --collector.interrupts --collector.logind --collector.meminfo_numa --collector.processes --collector.systemd --collector.tcpstat --collector.textfile.directory=/run/node_exporter
User=node_exporter
Group=node_exporter
StandardOutput=journal
StandardError=journal
SyslogIdentifier=node_exporter
Restart=always
RestartSec=60
RuntimeDirectory=node_exporter
RuntimeDirectoryMode=0777
[Install]
WantedBy=default.target
EOF
docker run -it --rm -v $ROOT_PATH:/opt/pkg -w /opt/pkg islandsound/fpm -s dir -t rpm -n node_exporter -v $VERSION --iteration $ITERATION --rpm-user root --rpm-group root --prefix / -C /opt/pkg/ -f --after-install opt/node_exporter/script/after-install.sh --before-remove opt/node_exporter/script/before-remove.sh --after-remove opt/node_exporter/script/after-remove.sh
mv ./opt/pkg/node_exporter-$VERSION-$ITERATION.x86_64.rpm $PWD/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment