Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deb & rpm packages #88

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add deb & rpm packages
  • Loading branch information
utkuozdemir committed Aug 9, 2022
commit e8dea7f929dd815663f96211e0fb40d2b4db7579
52 changes: 47 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ builds:
- amd64
- arm
- arm64
- 386
- "386"
goarm:
- 7
- "7"
ignore:
- goos: windows
goarch: arm
Expand All @@ -37,9 +37,9 @@ builds:
- goos: darwin
goarch: arm64
- goos: darwin
goarch: 386
goarch: "386"
- goos: linux
goarch: 386
goarch: "386"

archives:
- id: nvidia_gpu_exporter-archive
Expand All @@ -54,6 +54,48 @@ archives:
files:
- LICENSE

nfpms:
- id: nvidia_gpu_exporter
package_name: nvidia-gpu-exporter
bindir: /usr/bin
vendor: Utku Ozdemir
homepage: https://github.com/utkuozdemir/nvidia_gpu_exporter
license: MIT
maintainer: Utku Ozdemir <uoz@protonmail.com>
section: misc
description: |-
Nvidia GPU exporter for prometheus.
This is a simple exporter that uses `nvidia-smi(.exe)` binary to collect,
parse and export metrics.
formats:
- deb
- rpm
contents:
- src: ./systemd/nvidia_gpu_exporter.service
dst: /usr/lib/systemd/system/nvidia_gpu_exporter.service
file_info:
owner: root
group: root
mode: 0644
- src: ./LICENSE
dst: /usr/share/doc/nvidia-gpu-exporter/copyright
file_info:
owner: root
group: root
mode: 0644
scripts:
preinstall: scripts/pre-install.sh
postinstall: scripts/post-install.sh
preremove: scripts/pre-remove.sh
postremove: scripts/post-remove.sh
deb:
lintian_overrides:
- statically-linked-binary
- changelog-file-missing-in-native-package
- no-manual-page
# Probably won't be implemented: https://github.com/goreleaser/nfpm/issues/15#issuecomment-830816661
- maintainer-script-calls-systemctl

checksum:
name_template: checksums.txt
algorithm: sha256
Expand Down Expand Up @@ -93,7 +135,7 @@ dockers:
- docker.io/utkuozdemir/nvidia_gpu_exporter:{{ .Version }}-armv7
use: buildx
goarch: arm
goarm: 7
goarm: "7"
dockerfile: Dockerfile
build_flag_templates:
- --platform=linux/arm/v7
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ These steps do the following:
If your Linux distro is using systemd, you can install the exporter as a service using the unit file provided.

Follow these simple steps:
1. Download the Linux binary matching your CPU architecture and put it under `/usr/local/bin` directory.
1. Download the Linux binary matching your CPU architecture and put it under `/usr/bin` directory.
2. Drop a copy of the file **[nvidia_gpu_exporter.service](systemd/nvidia_gpu_exporter.service)** under `/etc/systemd/system` directory.
3. Run `sudo systemctl daemon-reload`
4. Start and enable the service to run on boot: `sudo systemctl enable --now nvidia_gpu_exporter`
Expand Down
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: "3"

tasks:
fmt:
desc: format all code
desc: format code
cmds:
- go mod tidy
- gci write -s standard -s default -s "prefix(github.com/utkuozdemir/nvidia_gpu_exporter)" .
- gofumpt -w -l .

lint:
desc: Lint the code with golangci-lint
desc: lint code
cmds:
- go mod tidy && git diff --no-patch --exit-code go.mod go.sum
- golangci-lint run ./...
Expand Down
18 changes: 18 additions & 0 deletions scripts/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e

PID1=$(ps --no-headers -o comm 1)

if [ "$PID1" != systemd ]; then
echo "Only systemd is supported but detected pid 1: $PID1"
exit 1
fi

echo "Detected systemd as init system, proceeding"

useradd -r nvidia_gpu_exporter -s /bin/false || true

systemctl daemon-reload

systemctl enable nvidia_gpu_exporter.service
systemctl restart nvidia_gpu_exporter.service
6 changes: 6 additions & 0 deletions scripts/post-remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e

userdel -f nvidia_gpu_exporter || true

systemctl daemon-reload
9 changes: 9 additions & 0 deletions scripts/pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

PID1=$(ps --no-headers -o comm 1)

if [ "$PID1" != systemd ]; then
echo "Only systemd is supported but detected pid 1: $PID1"
exit 1
fi
7 changes: 7 additions & 0 deletions scripts/pre-remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

systemctl stop nvidia_gpu_exporter.service || true
systemctl disable nvidia_gpu_exporter.service || true

systemctl daemon-reload
13 changes: 1 addition & 12 deletions systemd/nvidia_gpu_exporter.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ Type=simple
User=nvidia_gpu_exporter
Group=nvidia_gpu_exporter

ExecStart=/usr/local/bin/nvidia_gpu_exporter
ExecStart=/usr/bin/nvidia_gpu_exporter

SyslogIdentifier=nvidia_gpu_exporter

Restart=always
RestartSec=1

NoNewPrivileges=yes

ProtectHome=yes
ProtectSystem=strict
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes
ProtectHostname=yes
ProtectKernelLogs=yes
ProtectProc=yes

[Install]
WantedBy=multi-user.target