-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhealthcheck.sh
More file actions
78 lines (62 loc) · 2.22 KB
/
healthcheck.sh
File metadata and controls
78 lines (62 loc) · 2.22 KB
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
#!/bin/sh
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
# healthcheck.sh
# - Validates HAProxy config syntax.
# - Checks if Python SPOE HTTP Control API is listening on 127.0.0.1:8200.
# - Checks if SPOE Agent is running on HP_SPOA_ADDRESS (default 127.0.0.1:9600).
# - Checks FRP port at HP_FRP_ADDRESS.
# - Checks EXAPPS HTTP frontend, and also the EXAPPS HTTPS frontend if the /certs/cert.pem file exists.
#
# This script returns 0 if all checks pass, 1 otherwise.
# Determine config directory (same logic as start.sh)
if [ -f "/run/harp/haproxy.cfg" ]; then
CFG_DIR="/run/harp"
else
CFG_DIR=""
fi
# 1) Validate HAProxy config
haproxy -c -f "${CFG_DIR}/haproxy.cfg" || exit 1
if ! command -v nc >/dev/null 2>&1; then
echo "ERROR: 'nc' command not found. Install netcat."
exit 1
fi
# 2) Check SPOE Agent Control API (Python HTTP) on 127.0.0.1:8200
if ! nc -z 127.0.0.1 8200; then
echo "ERROR: Data Plane API not responding on 127.0.0.1:8200"
exit 1
fi
# Helper: netcat a given "host:port"
check_port () {
local fulladdr="$1"
# If "host" is 0.0.0.0, netcat to 127.0.0.1. Otherwise, use the given host.
local host_part="$(echo "$fulladdr" | cut -d':' -f1)"
local port_part="$(echo "$fulladdr" | cut -d':' -f2)"
if [ -z "$host_part" ] || [ -z "$port_part" ]; then
echo "WARN: Cannot parse $fulladdr"
return 0
fi
# If host_part is 0.0.0.0, override with 127.0.0.1
[ "$host_part" = "0.0.0.0" ] && host_part="127.0.0.1"
if ! nc -z -w 2 "$host_part" "$port_part"; then
echo "ERROR: Service not listening on $fulladdr"
exit 1
fi
}
# 3) Check SPOE Agent port
check_port "${HP_SPOA_ADDRESS:-127.0.0.1:9600}"
# 4) Check FRP port
check_port "${HP_FRP_ADDRESS:-0.0.0.0:8782}"
# 5) Decide which frontends to check in HAProxy
CERT_PRESENT=0
if [ -f "/certs/cert.pem" ]; then
CERT_PRESENT=1
fi
# We always check the EXAPPS HTTP frontend
check_port "${HP_EXAPPS_ADDRESS:-0.0.0.0:8780}"
# If there's a cert, we also check the EXAPPS HTTPS frontend
if [ "$CERT_PRESENT" -eq 1 ]; then
check_port "${HP_EXAPPS_HTTPS_ADDRESS:-0.0.0.0:8781}"
fi
echo "OK: All checks passed. FRP, HAProxy agent and HAProxy itself appear to be working."
exit 0