From 4bfd9b87f60e10f14b4d006657c40afb85e059f8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 12 Jan 2018 04:42:51 +0100 Subject: [PATCH] Support of Debian 9 (stretch) samba installation. --- check_samba4_service.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/check_samba4_service.sh b/check_samba4_service.sh index f91d328..16c6439 100755 --- a/check_samba4_service.sh +++ b/check_samba4_service.sh @@ -3,6 +3,9 @@ working_dir="$(dirname $(realpath $0))" +service_name="samba" +check_string_ps="(sbin/smbd| sbin/samba )" + # ------------- # - Some Variables # ------------- @@ -148,22 +151,20 @@ if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then systemd_supported=true fi -check_string_ps="(sbin/smbd | sbin/samba )" - # - Check How to start/stop service # - SYSTEMD_UNIT_FILE="" SYSY_INIT_SCRIPT="" if $systemd_supported ; then - SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "samba[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" + SYSTEMD_UNIT_FILE="$(systemctl list-unit-files | grep -E "${service_name}[^@]*\.service" | grep "enabled" | cut -d' ' -f1)" fi if [[ -z "$SYSTEMD_UNIT_FILE" ]]; then - SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep samba | head -1)" + SYSY_INIT_SCRIPT="$(service --status-all | awk '{print$4}' | grep ${service_name} | head -1)" fi if [[ -z "$SYSTEMD_UNIT_FILE" ]] && [[ -z "$SYSY_INIT_SCRIPT" ]] ; then - fatal 'Neither an init-script nor a service file for samba service found!' + fatal "Neither an init-script nor a service file for ${service_name} service found!" fi @@ -172,17 +173,17 @@ fi # ------------- if $terminal ; then - echo -e "\n Check if Samba Service is running.." - echo -e " ===================================" + echo -e "\n Check if Service '${service_name}' is running.." + echo -e " =====================================" fi PIDS="$(ps ax | grep -E "$check_string_ps" | grep -v grep | awk '{print$1}')" if [[ -z "$PIDS" ]];then - error "Samba Service seems to be down. Try to (re)start .." + error "$service_name service seems to be down. Try to (re)start .." - echononl " Stop Samba Service first .." + echononl " Stop Service '${service_name}' first .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl stop $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then @@ -201,7 +202,7 @@ if [[ -z "$PIDS" ]];then sleep 2 - echononl " Start Samba Service .." + echononl " Start Service '${service_name}' .." if [[ -n "$SYSTEMD_UNIT_FILE" ]] ; then systemctl start $SYSTEMD_UNIT_FILE > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then @@ -228,11 +229,11 @@ if [[ -z "$PIDS" ]];then done if [[ -z "${PIDS}" ]] ; then - error "Restarting Samba Service failed" + error "Restarting Service '${service_name}' failed" else NEW_PIDS="" - count=0 + count=1 for _pid in $PIDS ; do if [[ $count -eq 1 ]] ; then NEW_PIDS="$_pid" @@ -242,17 +243,20 @@ if [[ -z "$PIDS" ]];then ((count++)) done - info "the new PIDs are $NEW_PIDS" + info "Service '${service_name}' was restarted and is now up and running. + The new PID is $NEW_PIDS" - echo "" - echo "[ Success ]: Samba Service was restarted and is now up and running." - echo " The new PIDs are $NEW_PIDS" - echo "" + if ! $terminal ; then + echo "" + echo "[ Success ]: Service '${service_name}' was restarted and is now up and running." + echo " The new PIDs are $NEW_PIDS" + echo "" + fi fi else - info "Samba Service is up and running." + info "Service '${service_name}' is up and running." fi clean_up 0