mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2026-10-12 02:12:31 +00:00
fix: Postint check if api.server.enable is false (#3802)
This commit is contained in:
Vendored
+11
-2
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user