forked from percona/pmm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·84 lines (73 loc) · 2.91 KB
/
entrypoint.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -o errexit
# Add logging
if [ -n "${ENABLE_DEBUG}" ]; then
set -o xtrace
exec > >(tee -a /var/log/$(basename $0).log) 2>&1
fi
# Prometheus
if [[ ! "${METRICS_RESOLUTION:-1s}" =~ ^[1-5]s$ ]]; then
echo "METRICS_RESOLUTION takes only values from 1s to 5s."
exit 1
fi
sed -i "s/1s/${METRICS_RESOLUTION:-1s}/" /etc/prometheus.yml
sed -i "s/ENV_METRICS_RETENTION/${METRICS_RETENTION:-720h}/" /etc/supervisord.d/pmm.ini
if [ -n "$METRICS_MEMORY" ]; then
# Preserve compatibility with existing METRICS_MEMORY variable.
# https://jira.percona.com/browse/PMM-969
METRICS_MEMORY_MULTIPLIED=$(( ${METRICS_MEMORY} * 1024 ))
else
MEMORY_LIMIT=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes || :)
TOTAL_MEMORY=$(( $(grep MemTotal /proc/meminfo | awk '{print$2}') * 1024 ))
MEMORY_AVAIABLE=$(printf "%i\n%i\n" "$MEMORY_LIMIT" "$TOTAL_MEMORY" | sort -n | grep -v "^0$" | head -1)
METRICS_MEMORY_MULTIPLIED=$(( (${MEMORY_AVAIABLE} - 256*1024*1024) / 100 * 40 ))
if [[ $METRICS_MEMORY_MULTIPLIED < $((128*1024*1024)) ]]; then
METRICS_MEMORY_MULTIPLIED=$((128*1024*1024))
fi
fi
sed -i "s/ENV_METRICS_MEMORY_MULTIPLIED/${METRICS_MEMORY_MULTIPLIED}/" /etc/supervisord.d/pmm.ini
# Orchestrator
if [[ "${ORCHESTRATOR_ENABLED}" = "true" ]]; then
sed -i "s/orc_client_user/${ORCHESTRATOR_USER:-orc_client_user}/" /etc/orchestrator.conf.json
sed -i "s/orc_client_password/${ORCHESTRATOR_PASSWORD:-orc_client_password}/" /etc/orchestrator.conf.json
sed -i "s/autostart = false/autostart = true/" /etc/supervisord.d/pmm.ini
fi
# Cron
sed -i "s/^INTERVAL=.*/INTERVAL=${QUERIES_RETENTION:-8}/" /etc/cron.daily/purge-qan-data
# HTTP basic auth
if [ -n "${SERVER_PASSWORD}" -a -z "${UPDATE_MODE}" ]; then
SERVER_USER=${SERVER_USER:-pmm}
cat > /srv/update/pmm-manage.yml <<-EOF
users:
- username: "${SERVER_USER//\"/\"}"
password: "${SERVER_PASSWORD//\"/\"}"
EOF
pmm-configure -skip-prometheus-reload true -grafana-db-path /var/lib/grafana/grafana.db || :
fi
# Hide update button
if [[ $DISABLE_UPDATES =~ ^(1|t|T|TRUE|true|True)$ ]] && [[ -f /usr/share/pmm-server/landing-page/index.html ]]; then
sed -i "s/fa-refresh/fa-refresh hidden/" /usr/share/pmm-server/landing-page/index.html
fi
# Upgrade
if [ -f /var/lib/grafana/grafana.db ]; then
chown -R pmm:pmm /opt/consul-data
chown -R pmm:pmm /opt/prometheus/data
chown -R mysql:mysql /var/lib/mysql
chown -R grafana:grafana /var/lib/grafana
fi
# copy SSL, follow links
pushd /etc/nginx >/dev/null
if [ -s ssl/server.crt ]; then
cat ssl/server.crt > /srv/nginx/certificate.crt
fi
if [ -s ssl/server.key ]; then
cat ssl/server.key > /srv/nginx/certificate.key
fi
if [ -s ssl/dhparam.pem ]; then
cat ssl/dhparam.pem > /srv/nginx/dhparam.pem
fi
popd >/dev/null
# Start supervisor in foreground
if [ -z "${UPDATE_MODE}" ]; then
exec supervisord -n -c /etc/supervisord.conf
fi