fix: Postint check if api.server.enable is false (#3802)

This commit is contained in:
Laurence Jones
2025-08-25 15:45:33 +02:00
committed by GitHub
parent 8bb8532520
commit 2e3789b98c
2 changed files with 25 additions and 10 deletions
+11 -2
View File
@@ -64,13 +64,22 @@ if [ "$1" = configure ]; then
systemctl --quiet is-enabled crowdsec || systemctl unmask crowdsec && systemctl enable crowdsec
LAPI=true
API=$(cscli config show --key "Config.API.Server")
if [ "$API" = "nil" ] ; then
LAPI=false
else
PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
# If API server is explicitly disabled, don't attempt port checks
ENABLED=$(cscli config show --key "Config.API.Server.Enable" 2>/dev/null || true)
if [ "$ENABLED" = "false" ]; then
LAPI=false
fi
# Extract port from ListenURI robustly (handles IPv6 like ::8080)
URI=$(cscli config show --key "Config.API.Server.ListenURI" 2>/dev/null || true)
PORT=${URI##*:}
fi
if [ "$LAPI" = false ] || [ -z "$(ss -nlt "sport = ${PORT}" | grep -v ^State)" ] ; then
# Start if lapi disabled, or if port is unspecified, or if port is free.
if [ "$LAPI" = false ] || [ -z "$PORT" ] || [ -z "$(ss -nlt "sport = ${PORT}" 2>/dev/null | grep -v ^State || true)" ] ; then
systemctl start crowdsec
else
echo "Not attempting to start crowdsec, port ${PORT} is already used or lapi was disabled"
+14 -8
View File
@@ -189,14 +189,20 @@ echo "You can always run the configuration again interactively by using 'cscli s
%systemd_post %{name}.service
if [ $1 == 1 ]; then
API=$(cscli config show --key "Config.API.Server")
if [ "$API" = "nil" ] ; then
LAPI=false
else
PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
fi
if [ "$LAPI" = false ] || [ -z "$(ss -nlt "sport = ${PORT}" | grep -v ^State)" ] ; then
if [ $1 == 1 ]; then
LAPI=true
API=$(cscli config show --key "Config.API.Server")
if [ "$API" = "nil" ] ; then
LAPI=false
else
ENABLED=$(cscli config show --key "Config.API.Server.Enable" 2>/dev/null || true)
if [ "$ENABLED" = "false" ]; then
LAPI=false
fi
URI=$(cscli config show --key "Config.API.Server.ListenURI" 2>/dev/null || true)
PORT=${URI##*:}
fi
if [ "$LAPI" = false ] || [ -z "$PORT" ] || [ -z "$(ss -nlt "sport = ${PORT}" 2>/dev/null | grep -v ^State || true)" ] ; then
%if 0%{?fc35} || 0%{?fc36}
systemctl enable crowdsec
%endif