From b9f2e3edbb55c4af6b62d94afc0842d0275be159 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 24 Jul 2019 14:00:29 +0200 Subject: [PATCH] check_service.sh: remove unusually code. --- check_service.sh | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/check_service.sh b/check_service.sh index e9d1995..1830e3c 100755 --- a/check_service.sh +++ b/check_service.sh @@ -91,27 +91,15 @@ else LOGGING=false fi + +# Is service name given? +# if [[ -n "$1" ]] ; then service_name=$1 else fatal "$(basename $0): No Service given" fi -# - Is Service installed ? -# - -_check_binary="$(which ${service_name,,}d)" -if [[ -z "$_check_binary" ]] ; then - _check_binary="$(which ${service_name,,})" -fi - - -if [[ -z "$_check_binary" ]]; then - fatal "$(basename $0): $service_name Service seems NOT to be installed" -else - check_binary="$_check_binary" - check_string_ps="$check_binary" -fi - # - Systemd supported ? # - @@ -152,6 +140,23 @@ if [[ -z "$SYSTEMD_SERVICE" ]] && [[ -z "$SYSV_INIT_SCRIPT" ]] ; then fatal "Neither an init-script nor a service file for $service_name found!" fi +# - Determin check_string_ps .. +# - +if [[ -n "$SYSTEMD_SERVICE" ]] ; then + _systemd_service_file="" + if [[ -f "/etc/systemd/system/$SYSTEMD_SERVICE" ]] ; then + _systemd_service_file="/etc/systemd/system/$SYSTEMD_SERVICE" + elif [[ -f "/lib/systemd/system/$SYSTEMD_SERVICE" ]] ; then + _systemd_service_file="/etc/systemd/system/$SYSTEMD_SERVICE" + fi + if [[ -n "$_systemd_service_file" ]]; then + check_string_ps="$(trim $(cat "$_systemd_service_file" | grep ExecStart | grep -o -E "ExecStart\s*=\s*[^[:space:]]+" | cut -d "=" -f2))" + fi +else + check_string_ps="$(trim $(cat "$SYSV_INIT_SCRIPT" | grep DAEMON | grep -o -E "DAEMON\s*=\s*[^[:space:]]+" | cut -d "=" -f2))" +fi + + #--------------------------------------- #----------------------------- @@ -161,7 +166,7 @@ fi if $LOGGING ; then echo -e "\n Check if $service_name service is running.." - echo -e " =================================" + echo -e " =====================================" fi if ! ps -e f | grep -E "[[:digit:]]\ ${check_string_ps}" | grep -v grep > /dev/null ; then error "$service_name service seems to be down! Trying to restart service now.."