Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/packaging/grafana-agent-flow/deb/control/postinst
5398 views
#!/bin/sh

set -e

# shellcheck disable=SC1091
[ -f /etc/default/grafana-agent-flow ] && . /etc/default/grafana-agent-flow

# 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.

# Initial installation: $1 == configure
# Upgrade: $1 == configure, $2 == old version
case "$1" in
    configure)
        [ -z "$GRAFANA_AGENT_USER" ] && GRAFANA_AGENT_USER="grafana-agent-flow"
        [ -z "$GRAFANA_AGENT_GROUP" ] && GRAFANA_AGENT_GROUP="grafana-agent"
        if ! getent group "$GRAFANA_AGENT_GROUP" > /dev/null 2>&1 ; then
            groupadd -r "$GRAFANA_AGENT_GROUP"
        fi
        if ! getent passwd "$GRAFANA_AGENT_USER" > /dev/null 2>&1 ; then
            useradd -m -r -g "$GRAFANA_AGENT_GROUP" -d /var/lib/grafana-agent-flow -s /sbin/nologin -c "grafana-agent-flow user" "$GRAFANA_AGENT_USER"
        fi

        # Add grafana agent user to groups used for reading logs.
        if getent group adm > /dev/null 2>&1 ; then
            usermod -a -G adm "$GRAFANA_AGENT_USER"
        fi
        if getent group systemd-journal > /dev/null 2>&1 ; then
            usermod -a -G systemd-journal "$GRAFANA_AGENT_USER"
        fi

        chown $GRAFANA_AGENT_USER:$GRAFANA_AGENT_GROUP /var/lib/grafana-agent-flow
        chmod 770 /var/lib/grafana-agent-flow

        chmod 640 /etc/grafana-agent-flow.river
        chown root:$GRAFANA_AGENT_GROUP /etc/grafana-agent-flow.river

        if [ -z ${2+x} ] && [ "$RESTART_ON_UPGRADE" = "true" ]; then
            if command -v systemctl 2>/dev/null; then
                systemctl daemon-reload
                systemctl restart grafana-agent-flow
            fi
        fi
esac