mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-11-11 05:42:52 +00:00
Improve service stopping logic in stop_all_services
Refactored stop_all_services to handle empty service lists and avoid pipeline failures. Now checks for found services before attempting to stop and disable them, improving robustness and error handling.
This commit is contained in:
@@ -72,15 +72,23 @@ stop_all_services() {
|
|||||||
local service_patterns=("$@")
|
local service_patterns=("$@")
|
||||||
|
|
||||||
for pattern in "${service_patterns[@]}"; do
|
for pattern in "${service_patterns[@]}"; do
|
||||||
# Find all matching services
|
# Find all matching services (use || true to avoid pipeline failures)
|
||||||
systemctl list-units --type=service --all 2>/dev/null |
|
local services
|
||||||
grep -oE "${pattern}[^ ]*\.service" |
|
services=$(systemctl list-units --type=service --all 2>/dev/null |
|
||||||
sort -u |
|
grep -oE "${pattern}[^ ]*\.service" 2>/dev/null |
|
||||||
while read -r service; do
|
sort -u 2>/dev/null || true)
|
||||||
|
|
||||||
|
# Only process if we found any services
|
||||||
|
if [[ -n "$services" ]]; then
|
||||||
|
while IFS= read -r service; do
|
||||||
|
[[ -z "$service" ]] && continue
|
||||||
$STD systemctl stop "$service" 2>/dev/null || true
|
$STD systemctl stop "$service" 2>/dev/null || true
|
||||||
$STD systemctl disable "$service" 2>/dev/null || true
|
$STD systemctl disable "$service" 2>/dev/null || true
|
||||||
|
done <<<"$services"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
done
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user