-
Notifications
You must be signed in to change notification settings - Fork 2
/
healthcheck.sh
118 lines (108 loc) · 3.58 KB
/
healthcheck.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
## No healthcheck if healthcheck-disable is set ##
if [[ -f "/config/healthcheck-disable" ]]
then
touch /config/healthcheck-disable
else
# Block concurrent runs #
touch /config/healthcheck-disable
# Autoheal #
crashed=0
pidlist=$(pidof influxd)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-influxd-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Run influxdb as service on port $INFLUXDB_HTTP_PORT"
service influxdb start
fi
pidlist=$(pidof loki)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-loki-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Run loki as daemon on port $LOKI_PORT"
start-stop-daemon --start -b --exec /usr/sbin/loki -- -config.file=/config/loki/loki-local-config.yaml
fi
if [[ $USE_HDDTEMP =~ "yes" ]]
then
pidlist=$(pidof hddtemp)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-hddtemp-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Running hddtemp as daemon due to USE_HDDTEMP set to $USE_HDDTEMP"
hddtemp --quiet --daemon --file=/config/hddtemp/hddtemp.db --listen='127.0.0.1' --port=7634 /rootfs/dev/disk/by-id/ata*
fi
fi
pidlist=$(pidof telegraf)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-telegraf-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Run telegraf as service"
service telegraf start
fi
pidlist=$(pidof promtail)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-promtail-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Run promtail as daemon on port $PROMTAIL_PORT"
start-stop-daemon --start -b --exec /usr/sbin/promtail -- -config.file=/config/promtail/promtail.yml
fi
pidlist=$(pidof grafana-server)
if [ -z "$pidlist" ]
then
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
crashed=$(( $crashed + 1 ))
touch "/config/healthcheck-failure-grafana-at-$(date "+%d.%m.%Y_%T")"
fi
echo "[info] Run grafana as service on port $GRAFANA_PORT"
service grafana-server start
fi
# Remove blockage #
rm -f /config/healthcheck-disable
# No error if healthcheck-no-error is set #
if [[ -f "/config/healthcheck-no-error" ]]
then
touch /config/healthcheck-no-error
else
# Return exit code for healthcheck #
if (( $crashed > 0 ))
then
#touch "/config/debug-healthcheck-failure-at-$(date "+%d.%m.%Y_%T")"
exit 1
else
exit 0
fi
fi
fi