Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loki/tools/packaging/promtail-postinstall.sh

63 lines
1.8 KiB

#!/bin/sh
# Based on https://nfpm.goreleaser.com/tips/
if ! command -V systemctl >/dev/null 2>&1; then
echo "Could not find systemd. Skipping system installation." && exit 0
else
packaging: fix postinst on debian oses (#9706) Previously the systemd version extract pulled in debian string breaking the detection on debian variants **What this PR does / why we need it**: Fixes postinst error on Debian variants **Which issue(s) this PR fixes**: Fixes #9701 #9302 **Special notes for your reviewer**: Tests on various OS variants: Debian/12 ``` $ systemctl --version systemd 252 (252.6-1) +PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT +QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified $ systemctl --version | head -1 | sed 's/systemd \([0-9]\+\).*/\1/' 252 ``` CentOS/7 ``` $ systemctl --version systemd 219 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN $ systemctl --version | head -1 | sed 's/systemd \([0-9]\+\).*/\1/' 219 ``` Debian/11 ``` $ systemctl --version systemd 247 (247.3-7+deb11u2) +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=unified $ systemctl --version | head -1 | sed 's/systemd \([0-9]\+\).*/\1/' 247 ``` Ubuntu/20.04 ``` $ systemctl --version systemd 245 (245.4-4ubuntu3.20) +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid $ systemctl --version | head -1 | sed 's/systemd \([0-9]\+\).*/\1/' 245 ``` **Checklist** - [x] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [ ] Tests updated - [ ] `CHANGELOG.md` updated - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](https://github.com/grafana/loki/commit/d10549e3ece02120974929894ee333d07755d213) Co-authored-by: Michel Hollands <42814411+MichelHollands@users.noreply.github.com>
3 years ago
systemd_version=$(systemctl --version | head -1 | sed 's/systemd \([0-9]\+\).*/\1/')
fi
cleanInstall() {
printf "\033[32m Post Install of a clean install\033[0m\n"
# Create the user
if ! id promtail > /dev/null 2>&1 ; then
adduser --no-create-home --system --shell /bin/false "promtail"
fi
# rhel/centos7 cannot use ExecStartPre=+ to specify the pre start should be run as root
# even if you want your service to run as non root.
if [ "${systemd_version}" -lt 231 ]; then
printf "\033[31m systemd version %s is less then 231, fixing the service file \033[0m\n" "${systemd_version}"
sed -i "s/=+/=/g" /etc/systemd/system/promtail.service
fi
printf "\033[32m Reload the service unit from disk\033[0m\n"
systemctl daemon-reload ||:
printf "\033[32m Unmask the service\033[0m\n"
systemctl unmask promtail ||:
printf "\033[32m Set the preset flag for the service unit\033[0m\n"
systemctl preset promtail ||:
printf "\033[32m Set the enabled flag for the service unit\033[0m\n"
systemctl enable promtail ||:
systemctl restart promtail ||:
}
upgrade() {
:
# printf "\033[32m Post Install of an upgrade\033[0m\n"
}
action="$1"
if [ "$1" = "configure" ] && [ -z "$2" ]; then
# Alpine linux does not pass args, and deb passes $1=configure
action="install"
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
# deb passes $1=configure $2=<current version>
action="upgrade"
fi
case "${action}" in
"1" | "install")
cleanInstall
;;
"2" | "upgrade")
upgrade
;;
*)
# $1 == version being installed
printf "\033[32m Alpine\033[0m"
cleanInstall
;;
esac