From 63649bf0ddc3a7735e18490166f3ac6bdfc47201 Mon Sep 17 00:00:00 2001 From: Lorenzo Affetti Date: Tue, 16 Apr 2019 01:07:47 +0200 Subject: [PATCH] Set log directory attributes in rpm spec (#5716) --- scripts/build.py | 4 ++++ scripts/post-install.sh | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/build.py b/scripts/build.py index 5869bf1edacf2..85e1724a5da76 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -18,6 +18,8 @@ # Packaging variables PACKAGE_NAME = "telegraf" +USER = "telegraf" +GROUP = "telegraf" INSTALL_ROOT_DIR = "/usr/bin" LOG_DIR = "/var/log/telegraf" SCRIPT_DIR = "/usr/lib/telegraf/scripts" @@ -66,6 +68,7 @@ --before-install {} \ --after-remove {} \ --before-remove {} \ + --rpm-attr 755,{},{}:{} \ --description \"{}\"".format( VENDOR, PACKAGE_URL, @@ -77,6 +80,7 @@ PREINST_SCRIPT, POSTREMOVE_SCRIPT, PREREMOVE_SCRIPT, + USER, GROUP, LOG_DIR, DESCRIPTION) targets = { diff --git a/scripts/post-install.sh b/scripts/post-install.sh index 822a4e4de5028..9972364bc6e7d 100644 --- a/scripts/post-install.sh +++ b/scripts/post-install.sh @@ -32,10 +32,6 @@ if ! id telegraf &>/dev/null; then useradd -r -M telegraf -s /bin/false -d /etc/telegraf -g telegraf fi -test -d $LOG_DIR || mkdir -p $LOG_DIR -chown -R -L telegraf:telegraf $LOG_DIR -chmod 755 $LOG_DIR - # Remove legacy symlink, if it exists if [[ -L /etc/init.d/telegraf ]]; then rm -f /etc/init.d/telegraf @@ -72,6 +68,14 @@ if [[ -f /etc/redhat-release ]] || [[ -f /etc/SuSE-release ]]; then fi elif [[ -f /etc/debian_version ]]; then # Debian/Ubuntu logic + + # Ownership for RH-based platforms is set in build.py via the `rmp-attr` option. + # We perform ownership change only for Debian-based systems. + # Moving these lines out of this if statement would make `rmp -V` fail after installation. + test -d $LOG_DIR || mkdir -p $LOG_DIR + chown -R -L telegraf:telegraf $LOG_DIR + chmod 755 $LOG_DIR + if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then install_systemd /lib/systemd/system/telegraf.service deb-systemd-invoke restart telegraf.service || echo "WARNING: systemd not running."