Skip to content

Commit

Permalink
Set log directory attributes in rpm spec (influxdata#5716)
Browse files Browse the repository at this point in the history
  • Loading branch information
affo authored and idohalevi committed Sep 23, 2020
1 parent 5bf793b commit 63649bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,6 +68,7 @@
--before-install {} \
--after-remove {} \
--before-remove {} \
--rpm-attr 755,{},{}:{} \
--description \"{}\"".format(
VENDOR,
PACKAGE_URL,
Expand All @@ -77,6 +80,7 @@
PREINST_SCRIPT,
POSTREMOVE_SCRIPT,
PREREMOVE_SCRIPT,
USER, GROUP, LOG_DIR,
DESCRIPTION)

targets = {
Expand Down
12 changes: 8 additions & 4 deletions scripts/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 63649bf

Please sign in to comment.