From: Michael Howe Date: Fri, 10 Mar 2023 10:20:52 +0000 (+0000) Subject: Initial packaging of promtail X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=f30c2607132da9cebab36c17e4df5481a40aa1d7;p=packages%2Fp%2Fpromtail.git Initial packaging of promtail --- f30c2607132da9cebab36c17e4df5481a40aa1d7 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fc87836 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ + +prefix = /usr + +# do some juggling to account for arm/armhf differences in names +BUILDARCH_amd64 = amd64 +BUILDARCH_armhf = arm +BUILDARCH = ${BUILDARCH_${DEB_BUILD_ARCH}} + +build: + # no-op +clean: + # no-op + +install: + install --mode 0644 -D conf/config.yml $(DESTDIR)/etc/promtail/config.yml + install -D extract/promtail-linux-$(BUILDARCH) $(DESTDIR)$(prefix)/bin/promtail + +.PHONY: install diff --git a/conf/config.yml b/conf/config.yml new file mode 100644 index 0000000..354a3e2 --- /dev/null +++ b/conf/config.yml @@ -0,0 +1,19 @@ +# +server: + http_listen_port: 9080 + grpc_listen_port: 0 + +positions: + filename: /var/lib/promtail/positions.yaml + +clients: + - url: http://localhost:3100/loki/api/v1/push + +scrape_configs: +- job_name: system + static_configs: + - targets: + - localhost + labels: + job: varlogs + __path__: /var/log/*log diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..14a7416 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,7 @@ +promtail for Debian +------------------ + +Hack of a package based on downloading binaries from github rather than +building them ourselves. Not to be published. + + -- Michael Howe Tue, 28 Feb 2023 21:09:36 +0000 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..9271e24 --- /dev/null +++ b/debian/README.source @@ -0,0 +1,17 @@ +promtail for Debian +------------------ + +Use update-version to download the new version, then bump the +changelog as appropriate and build for relevant architectures (probably amd64 +and armhf). + +Build for each architecture, then (where $ARMDIR contains the armhf build +files, and $AMD64DIR the amd64 build): +cp $ARMDIR/*armhf* $AMD64DIR +cd $AMD64DIR +# merge changes with something like: +mergechanges promtail_2.7.4+internal.0_source.changes promtail_2.7.4+internal.0_armhf.changes promtail_2.7.4+internal.0_amd64.changes > promtail_2.7.4+internal.0_combined.changes +debsign promtail_2.7.4+internal.0_combined.changes + + -- Michael Howe Tue, 28 Feb 2023 21:09:36 +0000 + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..50dfe8f --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +promtail (2.7.4+internal.0) unstable; urgency=medium + + * Initial Release. + + -- Michael Howe Tue, 28 Feb 2023 21:09:36 +0000 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..43bd984 --- /dev/null +++ b/debian/control @@ -0,0 +1,20 @@ +Source: promtail +Section: admin +Priority: optional +Maintainer: Michael Howe +Build-Depends: debhelper-compat (= 13) +Standards-Version: 4.5.1 +Homepage: https://grafana.com/docs/loki/latest/clients/promtail/ +#Vcs-Browser: https://salsa.debian.org/debian/promtail +#Vcs-Git: https://salsa.debian.org/debian/promtail.git +Rules-Requires-Root: no + +Package: promtail +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, adduser +Description: Agent which ships the contents of local logs to a Loki instance + Promtail is an agent which ships the contents of local logs to a private + Grafana Loki instance or Grafana Cloud. + . + It is usually deployed to every machine that has applications needed to be + monitored. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c9e5972 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,12 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: promtail +Upstream-Contact: https://github.com/grafana/loki +Source: https://github.com/grafana/loki + +Files: * +Copyright: 2020-2023 Grafana Labs +License: AGPL-3.0+ + +Files: debian/* +Copyright: 2023 Michael Howe +License: GPL-3.0+ diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000..67cab6d --- /dev/null +++ b/debian/postinst @@ -0,0 +1,39 @@ +#!/bin/sh +# postinst script for promtail +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..8d7f8ea --- /dev/null +++ b/debian/postrm @@ -0,0 +1,51 @@ +#!/bin/sh +# postrm script for promtail +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + purge) + SERVER_HOME=/var/lib/promtail + SERVER_GROUP=promtail + SERVER_USER=promtail + if getent passwd | grep -q "^$SERVER_USER:"; then + deluser --system promtail + fi + if getent group | grep -q "^$SERVER_GROU:"; then + delgroup --system "$SERVER_GROUP" + fi + if [ -d "$SERVER_HOME" ]; then + rm -rf "$SERVER_HOME" + fi + ;; + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/preinst b/debian/preinst new file mode 100644 index 0000000..87557c6 --- /dev/null +++ b/debian/preinst @@ -0,0 +1,77 @@ +#!/bin/sh +# preinst script for promtail +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + ADDGROUP="adm" + [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/lib/promtail + [ -z "$SERVER_USER" ] && SERVER_USER=promtail + [ -z "$SERVER_NAME" ] && SERVER_NAME="Promtail User" + [ -z "$SERVER_GROUP" ] && SERVER_GROUP=promtail + # 1. create group if it doesn't exist + if ! getent group | grep -q "^$SERVER_GROUP:"; then + echo -n "Adding group $SERVER_GROUP.." + addgroup --quiet --system "$SERVER_GROUP" 2>/dev/null || true + echo "..done" + fi + # 2. create homedir if it doesn't exist + test -d "$SERVER_HOME" || mkdir -p "$SERVER_HOME" + # 3. create user if it doesn't exist + if ! getent passwd | grep -q "^$SERVER_USER:"; then + echo -n "Adding system user $SERVER_USER.." + adduser --quiet \ + --system \ + --ingroup "$SERVER_GROUP" \ + --home "$SERVER_HOME" \ + --no-create-home \ + --disabled-password \ + "$SERVER_USER" 2>/dev/null || true + echo "..done" + fi + # 4. adjust passwd entry + usermod -c "$SERVER_NAME" \ + -d "$SERVER_HOME" \ + -g "$SERVER_GROUP" \ + "$SERVER_USER" + # 5. adjust file and directory permissions + if ! dpkg-statoverride --list "$SERVER_HOME" >/dev/null; then + chown "$SERVER_USER":"$SERVER_GROUP" "$SERVER_HOME" + chmod 0750 "$SERVER_HOME" + fi + # 6. add user to ADDGROUP group + if test -n "$ADDGROUP"; then + if ! groups "$SERVER_USER" | cut -d: -f2 | \ + grep -qw "^$ADDGROUP"; then + adduser "$SERVER_USER" "$ADDGROUP" + fi + fi + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/promtail-docs.docs b/debian/promtail-docs.docs new file mode 100644 index 0000000..efea0a6 --- /dev/null +++ b/debian/promtail-docs.docs @@ -0,0 +1,2 @@ +README.Debian +README.source diff --git a/debian/promtail.service b/debian/promtail.service new file mode 100644 index 0000000..7f971b5 --- /dev/null +++ b/debian/promtail.service @@ -0,0 +1,15 @@ +[Unit] +Description=Promtail service +After=network.target + +[Service] +Type=simple +User=promtail +ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml +# Give a reasonable amount of time for promtail to start up/shut down +TimeoutSec=60 +Restart=on-failure +RestartSec=2 + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..95db21a --- /dev/null +++ b/debian/rules @@ -0,0 +1,8 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/download/promtail-linux-amd64-v2.7.4.zip b/download/promtail-linux-amd64-v2.7.4.zip new file mode 100644 index 0000000..e036ee7 Binary files /dev/null and b/download/promtail-linux-amd64-v2.7.4.zip differ diff --git a/download/promtail-linux-arm-v2.7.4.zip b/download/promtail-linux-arm-v2.7.4.zip new file mode 100644 index 0000000..a1e696e Binary files /dev/null and b/download/promtail-linux-arm-v2.7.4.zip differ diff --git a/extract/promtail-linux-amd64 b/extract/promtail-linux-amd64 new file mode 100755 index 0000000..842dfc8 Binary files /dev/null and b/extract/promtail-linux-amd64 differ diff --git a/extract/promtail-linux-arm b/extract/promtail-linux-arm new file mode 100755 index 0000000..78aecc8 Binary files /dev/null and b/extract/promtail-linux-arm differ diff --git a/update-version b/update-version new file mode 100755 index 0000000..f33d391 --- /dev/null +++ b/update-version @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +set -u + +# eg v2.7.4 +VER=$1 + +ARCHES=('amd64' 'arm') + +mkdir -p extract/ +mkdir -p download/ + +for arch in "${ARCHES[@]}"; do + DOWNLOAD_URL="https://github.com/grafana/loki/releases/download/${VER}/promtail-linux-${arch}.zip" + ZIPFILE="download/promtail-linux-${arch}-${VER}.zip" + wget -O "${ZIPFILE}" "${DOWNLOAD_URL}" + unzip "${ZIPFILE}" -d extract/ +done