Path: blob/main/packaging/grafana-agent-flow/rpm/control/postinst
5439 views
#!/bin/sh
set -e
# NOTE: the grafana-agent group is shared with the grafana-agent package to
# make it easier to migrate between the two. A unique user is still used to
# give them different home directories.
# shellcheck disable=SC1091
[ -f /etc/sysconfig/grafana-agent-flow ] && . /etc/sysconfig/grafana-agent-flow
[ -z "$AGENT_USER" ] && AGENT_USER="grafana-agent-flow"
[ -z "$AGENT_GROUP" ] && AGENT_GROUP="grafana-agent"
add_to_logging_groups() {
# Add grafana agent user to groups used for reading logs.
if getent group adm > /dev/null 2>&1 ; then
usermod -a -G adm "$AGENT_USER"
fi
if getent group systemd-journal > /dev/null 2>&1 ; then
usermod -a -G systemd-journal "$AGENT_USER"
fi
}
# Initial installation: $1 == 1
# Upgrade: $1 == 2, and configured to restart on upgrade
if [ "$1" -eq 1 ] ; then
if ! getent group "$AGENT_GROUP" > /dev/null 2>&1 ; then
groupadd -r "$AGENT_GROUP"
fi
if ! getent passwd "$AGENT_USER" > /dev/null 2>&1 ; then
useradd -r -m -g "$AGENT_GROUP" -d /var/lib/grafana-agent-flow -s /sbin/nologin -c "grafana-agent-flow user" "$AGENT_USER"
fi
add_to_logging_groups
chown $AGENT_USER:$AGENT_GROUP /var/lib/grafana-agent-flow
chmod 770 /var/lib/grafana-agent-flow
chmod 640 /etc/grafana-agent-flow.river
chown root:$AGENT_GROUP /etc/grafana-agent-flow.river
elif [ "$1" -ge 2 ] ; then
add_to_logging_groups
if [ "$RESTART_ON_UPGRADE" = "true" ]; then
systemctl daemon-reload
systemctl restart grafana-agent-flow
fi
fi