Last active
October 31, 2023 01:22
-
-
Save downspot/9a5712fedc607f1b2095efce504987e7 to your computer and use it in GitHub Desktop.
node_exporter fpm rpm (credit to https://gist.github.com/dreampuf/5531fd5b131e73fe97d6b871fce60bb0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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