Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit ed4cc52

Browse files
authored
add ssh connection check (#31472)
1 parent f833dac commit ed4cc52

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

metrics/influx-enterprise/status.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,32 @@ check_service() {
2222

2323
# Loop through the servers
2424
for server in "${servers[@]}"; do
25-
# Check if the service is running
26-
if ssh -o StrictHostKeyChecking=no sol@"$server" sudo systemctl is-active "$service" >/dev/null; then
25+
ssh_success=false
26+
ssh_attempts=0
27+
while ! $ssh_success && [ $ssh_attempts -lt 3 ]; do
28+
# Check if the service is running
29+
if ssh -o StrictHostKeyChecking=no sol@"$server" sudo systemctl is-active "$service" >/dev/null 2>&1; then
30+
ssh_success=true
31+
else
32+
ssh_attempts=$((ssh_attempts + 1))
33+
sleep 5
34+
fi
35+
done
36+
37+
if $ssh_success; then
2738
# Service is running
2839
message="The $service service is running on $server."
2940
echo "$message"
3041
else
31-
# Service is not running, try to restart it
42+
# SSH connection failed after retries
43+
message="ERROR: Unable to establish SSH connection to $server after 3 retries."
44+
echo "$message"
45+
curl -H "Content-Type: application/json" -d '{"content":"'"$message"', manual intervention is required."}' "$DISCORD_WEBHOOK"
46+
continue
47+
fi
48+
49+
# Service is not running, try to restart it
50+
if ! $ssh_success; then
3251
message="The $service service is not running on $server. Restarting..."
3352
echo "$message"
3453
curl -H "Content-Type: application/json" -d '{"content":"'"$message"'"}' "$DISCORD_WEBHOOK"

0 commit comments

Comments
 (0)