forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostinst
41 lines (34 loc) · 1.49 KB
/
postinst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
set -e
# shellcheck disable=SC1091
[ -f /etc/default/grafana-agent ] && . /etc/default/grafana-agent
# Initial installation: $1 == configure
# Upgrade: $1 == configure, $2 == old version
case "$1" in
configure)
[ -z "$GRAFANA_AGENT_USER" ] && GRAFANA_AGENT_USER="grafana-agent"
[ -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 -s /sbin/nologin -c "grafana-agent 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
chmod 770 /var/lib/grafana-agent
chmod 640 /etc/grafana-agent.yaml
chown root:$GRAFANA_AGENT_GROUP /etc/grafana-agent.yaml
if [ -z ${2+x} ] && [ "$RESTART_ON_UPGRADE" = "true" ]; then
if command -v systemctl 2>/dev/null; then
systemctl daemon-reload
systemctl restart grafana-agent
fi
fi
esac