58 lines
1.3 KiB
Diff
58 lines
1.3 KiB
Diff
|
|
From fc0657b936f6a58f741e33f851b22f82bc68bffa Mon Sep 17 00:00:00 2001
|
||
|
|
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
||
|
|
Date: Tue, 6 Feb 2024 13:28:12 +0100
|
||
|
|
Subject: [PATCH 1/3] ocf-shellfuncs: add curl_retry()
|
||
|
|
|
||
|
|
---
|
||
|
|
heartbeat/ocf-shellfuncs.in | 34 ++++++++++++++++++++++++++++++++++
|
||
|
|
1 file changed, 34 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
|
||
|
|
index c5edb6f5..a69a9743 100644
|
||
|
|
--- a/heartbeat/ocf-shellfuncs.in
|
||
|
|
+++ b/heartbeat/ocf-shellfuncs.in
|
||
|
|
@@ -672,6 +672,40 @@ EOF
|
||
|
|
systemctl daemon-reload
|
||
|
|
}
|
||
|
|
|
||
|
|
+# usage: curl_retry RETRIES SLEEP ARGS URL
|
||
|
|
+#
|
||
|
|
+# Use --show-error in ARGS to log HTTP error code
|
||
|
|
+#
|
||
|
|
+# returns:
|
||
|
|
+# 0 success
|
||
|
|
+# exit:
|
||
|
|
+# 1 fail
|
||
|
|
+curl_retry()
|
||
|
|
+{
|
||
|
|
+ local retries=$1 sleep=$2 opts=$3 url=$4
|
||
|
|
+ local tries=$(($retries + 1))
|
||
|
|
+ local args="--fail $opts $url"
|
||
|
|
+ local result rc
|
||
|
|
+
|
||
|
|
+ for try in $(seq $tries); do
|
||
|
|
+ ocf_log debug "curl $args try $try of $tries"
|
||
|
|
+ result=$(echo "$args" | xargs curl 2>&1)
|
||
|
|
+ rc=$?
|
||
|
|
+
|
||
|
|
+ ocf_log debug "result: $result"
|
||
|
|
+ [ $rc -eq 0 ] && break
|
||
|
|
+ sleep $sleep
|
||
|
|
+ done
|
||
|
|
+
|
||
|
|
+ if [ $rc -ne 0 ]; then
|
||
|
|
+ ocf_exit_reason "curl $args failed $tries tries"
|
||
|
|
+ exit $OCF_ERR_GENERIC
|
||
|
|
+ fi
|
||
|
|
+
|
||
|
|
+ echo "$result"
|
||
|
|
+ return $rc
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
# move process to root cgroup if realtime scheduling is enabled
|
||
|
|
ocf_move_to_root_cgroup_if_rt_enabled()
|
||
|
|
{
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|