]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: admin: haproxy-reload conversion to POSIX sh
authorWilliam Lallemand <wlallemand@irq6.net>
Sun, 8 Mar 2026 00:10:45 +0000 (01:10 +0100)
committerWilliam Lallemand <wlallemand@irq6.net>
Sun, 8 Mar 2026 00:37:52 +0000 (01:37 +0100)
The script relied on a bash-specific process substitution (< <(...)) to
feed socat's output into the read loop. This is replaced with a standard
POSIX pipe into a command group.

The response parsing is also simplified: instead of iterating over each
line with a while loop and echoing them individually, the status line is
read first, the "--" separator consumed, and the remaining output is
streamed to stderr or discarded as a whole depending on the verbosity
level.

Could be backported to 3.3 as it makes it more portable, but introduce a
slight change in the error format.

admin/cli/haproxy-reload

index b592d98e9ef86d9a28079c98cce9a68f44f08db8..a3f07ef456a17fc1e5497eeedddae4daf75afcc8 100755 (executable)
@@ -1,11 +1,10 @@
-#!/bin/bash
+#!/bin/sh
 
 set -e
 
 export VERBOSE=1
 export TIMEOUT=90
 export MASTER_SOCKET="${MASTER_SOCKET:-/var/run/haproxy-master.sock}"
-export RET=
 
 alert() {
        if [ "$VERBOSE" -ge "1" ]; then
@@ -28,32 +27,25 @@ reload() {
                                ;;
                esac
        fi
-       while read -r line; do
 
-               if [ "$line" = "Success=0" ]; then
-                       RET=1
-               elif [ "$line" = "Success=1" ]; then
-                       RET=0
-               elif [ "$line" = "Another reload is still in progress." ]; then
-                       alert "$line"
-               elif [ "$line" = "--" ]; then
-                       continue;
-               else
-                       if [ "$RET" = 1 ] && [ "$VERBOSE" = "2" ]; then
-                               echo "$line" >&2
-                       elif [ "$VERBOSE" = "3" ]; then
-                               echo "$line" >&2
-                       fi
-               fi
+       echo "reload" | socat -t"${TIMEOUT}" "$socat_addr" - | {
+               read -r status || { alert "No status received (connection error or timeout after ${TIMEOUT}s)."; exit 1; }
+               case "$status" in
+                       "Success=1") ret=0 ;;
+                       "Success=0") ret=1 ;;
+                       *)           alert "Unexpected response: '$status'"; exit 1 ;;
+               esac
 
-       done < <(echo "reload" | socat -t"${TIMEOUT}" "$socat_addr" -)
+               read -r _  # consume "--"
 
-       if [ -z "$RET" ]; then
-               alert "Couldn't finish the reload before the timeout (${TIMEOUT})."
-               return 1
-       fi
+               if [ "$VERBOSE" -ge 3 ] || { [ "$ret" = 1 ] && [ "$VERBOSE" -ge 2 ]; }; then
+                       cat >&2
+               else
+                       cat >/dev/null
+               fi
 
-       return "$RET"
+               exit "$ret"
+       }
 }
 
 usage() {