search by tags

for the user

adventures into the land of the command line

making a debian package

below are some manual steps to create a debian package using dpkg-deb. the package will work with systemd and can be put into a repo and installed with apt-get.

note that deb packages cannot have _ in their names, so the actual package name is node-exporter, but everything else is node_exporter.

make a working directory

$ mkdir node_exporter

download the binary you wanna make into a package

$ curl -LO https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
$ tar -xzvf node_exporter-0.18.1.linux-amd64.tar.gz

make a directory where the file should be installed and move it there

$ mkdir -p node_exporter/usr/bin
$ cp node_exporter-0.18.1.linux-amd64/node_exporter node_exporter/usr/bin/node_exporter

make a directory where a systemd config should go and put your systemd config in said directory

$ mkdir -p node_exporter/lib/systemd/system/
$ vim node_exporter/lib/systemd/system/node_exporter.service

[Unit]
Description=Prometheus node exporter
Documentation=https://github.com/prometheus/node_exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node-exporter
Group=node-exporter
Type=simple
ExecStart=/usr/bin/node_exporter --web.listen-address=:9100 --web.telemetry-path="/metrics"
Restart=always
User=root
Group=root

[Install]
WantedBy=multi-user.target

make a control file

$ mkdir -p node_exporter/DEBIAN
$ vim node_exporter/DEBIAN/control

Package: node-exporter
Version: 0.18.1
Section: utils
Priority: optional
Architecture: amd64
Maintainer: sebastianfromearth <my.groovy.email>
Description: Prometheus node exporter
Build-Depends: debhelper, dh-systemd (>= 1.5)

add a postinst script to add stuff on install

$ vim node_exporter/DEBIAN/postinst


systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter


$ chmod 755 node_exporter/DEBIAN/postinst

add a prerm script to remove stuff on uninstall

$ vim node_exporter/DEBIAN/prerm


systemctl stop node_exporter
systemctl disable node_exporter
systemctl daemon-reload
systemctl reset-failed


$ chmod 755 node_exporter/DEBIAN/prerm

add a rules file for the systemd dependency

$ vim node_exporter/DEBIAN/rules

#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1

%:
    dh $@ --with=systemd

build the package

$ dpkg-deb --build node_exporter

you will see

dpkg-deb: building package 'node-exporter' in 'node_exporter.deb'.

what do we have:

$ tree
.
├── node_exporter
   ├── DEBIAN
      ├── control
      ├── postinst
      ├── prerm
      └── rules
   ├── lib
      └── systemd
          └── system
              └── node_exporter.service
   └── usr
       └── bin
           └── node_exporter
├── node_exporter-0.18.1.linux-amd64
   ├── LICENSE
   ├── NOTICE
   └── node_exporter
├── node_exporter-0.18.1.linux-amd64.tar.gz
└── node_exporter.deb

test installation of the package with dpkg

$ sudo dpkg -i node_exporter.deb

check available packages

$ dpkg -l | grep node
ii  node-exporter                    0.18.1                                     amd64        Prometheus node exporter

and remove it

$ sudo dpkg -r node-exporter

or if you've added it to a repo:

$ sudo apt-cache madison node-exporter

node-exporter |   0.18.1  | http://my.groovy.repo xenial/main amd64 Packages
$ apt-get update
$ apt-get install node-exporter=0.18.1

Cookies

We use third-party cookies to analyse web traffic.

Read more.