From 729a44f82ae1e21b6c8906490e46deb7591613b8 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 23 Feb 2025 15:48:32 +0100 Subject: [PATCH] Do not hide error messages when dealing with services If service start/stop/restart/enable/disable fails, it help to debug the issue, if STDERR is not hidden, hence the error message can be seen. systemctl furthermore has the `-q` option to suppress non-error output. It works as well for "is-enabled", but until a certain systemd version still throws an error, if the checked service does not exist at all. Once Debian Bullseye support is dropped by Pi-hole, also STDERR form systemctl is-enabled does not need to be suppressed anymore. Signed-off-by: MichaIng --- automated install/basic-install.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4a1df70c..8b4425bc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1355,9 +1355,9 @@ stop_service() { local str="Stopping ${1} service" printf " %b %s..." "${INFO}" "${str}" if is_command systemctl; then - systemctl stop "${1}" &>/dev/null || true + systemctl -q stop "${1}" || true else - service "${1}" stop &>/dev/null || true + service "${1}" stop >/dev/null || true fi printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}" } @@ -1370,10 +1370,10 @@ restart_service() { # If systemctl exists, if is_command systemctl; then # use that to restart the service - systemctl restart "${1}" &>/dev/null + systemctl -q restart "${1}" else # Otherwise, fall back to the service command - service "${1}" restart &>/dev/null + service "${1}" restart >/dev/null fi printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}" } @@ -1386,10 +1386,10 @@ enable_service() { # If systemctl exists, if is_command systemctl; then # use that to enable the service - systemctl enable "${1}" &>/dev/null + systemctl -q enable "${1}" else # Otherwise, use update-rc.d to accomplish this - update-rc.d "${1}" defaults &>/dev/null + update-rc.d "${1}" defaults >/dev/null fi printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}" } @@ -1402,10 +1402,10 @@ disable_service() { # If systemctl exists, if is_command systemctl; then # use that to disable the service - systemctl disable "${1}" &>/dev/null + systemctl -q disable "${1}" else # Otherwise, use update-rc.d to accomplish this - update-rc.d "${1}" disable &>/dev/null + update-rc.d "${1}" disable >/dev/null fi printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}" } @@ -1414,7 +1414,7 @@ check_service_active() { # If systemctl exists, if is_command systemctl; then # use that to check the status of the service - systemctl is-enabled "${1}" &>/dev/null + systemctl -q is-enabled "${1}" 2>/dev/null else # Otherwise, fall back to service command service "${1}" status &>/dev/null @@ -1999,7 +1999,7 @@ FTLinstall() { curl -sSL "https://ftl.pi-hole.net/macvendor.db" -o "${PI_HOLE_CONFIG_DIR}/macvendor.db" || true # Stop pihole-FTL service if available - stop_service pihole-FTL &>/dev/null + stop_service pihole-FTL >/dev/null # Install the new version with the correct permissions install -T -m 0755 "${binary}" /usr/bin/pihole-FTL