configuration-templates – Rev 171

Subversion Repositories:
Rev:
#!/bin/bash
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2023 - License: GNU GPLv3      ##
###########################################################################
# This script matches the PID reported by HAproxy via its internal stats  #
# interface to the PID of the process from the process table and iff. the #
# two match then the script returns 0.                                    #
#                                                                         #
# Requirements:                                                           #
#   * socket                                                              #
#                                                                         #
###########################################################################

###########################################################################
#                           CONFIGURATION                                 #
###########################################################################

# HAProxy needs the socket for stats to be exposed.
# These settings added to the global section should enable the socket:
#   stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
#   stats timeout 30s
SOCKET_PATH="/run/haproxy/admin.sock"
PID_FILE="/run/haproxy.pid"

###########################################################################
#                             INTERNALS                                   #
###########################################################################

PID=$(cat <<EOF | \
    socat "$SOCKET_PATH" stdio | \
    grep ^Pid | \
    awk -F': ' '{ print $2 }'
show info
EOF
)

[ "$PID" != `cat "$PID_FILE"` ] || exit 1

exit 0