From 00fcb8de66db0d6632781beb38e8fdcef4e46252 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 10 Jan 2018 04:40:39 +0100 Subject: [PATCH] Improve detection of apache systemd service file if exists. --- check_webservice_load.sh | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/check_webservice_load.sh b/check_webservice_load.sh index abd3bcf..d67c81e 100755 --- a/check_webservice_load.sh +++ b/check_webservice_load.sh @@ -214,21 +214,45 @@ if $check_apache ; then fi fi - APACHE_SYSTEMD_SERVICE_EXISTS=false if $systemd_supported ; then - if $(locate apache2.service > /dev/null 2>&1) ; then - APACHE_SYSTEMD_SERVICE_EXISTS=true + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | grep -q enabled 2> /devnull ; then + + MYSQLD_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^mysql" \ + | awk '{print$1}') + fi + + fi + + APACHE_SERVICE_FILE="" + APACHE_INIT_SCRIPT="" + if $systemd_supported ; then + # - Is Service exclusive controlled by systemd + # - + if systemctl -t service list-unit-files \ + | grep -e "^apache" \ + | grep -q enabled 2> /devnull ; then + + APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^apache" \ + | awk '{print$1}') + fi fi - APACHE_INIT_SCRIPT="" - if [ -x "/etc/init.d/apache2" ]; then - APACHE_INIT_SCRIPT="/etc/init.d/apache2" - elif [ -x "/etc/init.d/apachectl" ]; then - APACHE_INIT_SCRIPT="/etc/init.d/apachectl" + if [[ -z "$APACHE_SERVICE_FILE" ]] ; then + if [ -x "/etc/init.d/apache2" ]; then + APACHE_INIT_SCRIPT="/etc/init.d/apache2" + elif [ -x "/etc/init.d/apachectl" ]; then + APACHE_INIT_SCRIPT="/etc/init.d/apachectl" + fi fi - if [[ -z "$APACHE_INIT_SCRIPT" ]] && ! $APACHE_SYSTEMD_SERVICE_EXISTS ; then + if [[ -z "$APACHE_INIT_SCRIPT" ]] && [[ -z "$APACHE_SERVICE_FILE" ; then fatal 'Neither an init-script nor a service file for apache2 found!' fi fi @@ -402,8 +426,8 @@ stop_apache() { ## - Stop Apache Webservice ## - - if $APACHE_SYSTEMD_SERVICE_EXISTS ; then - systemctl stop apache2 > /dev/null 2>&1 + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl stop "$APACHE_SERVICE_FILE" > /dev/null 2>&1 else $APACHE_INIT_SCRIPT stop > /dev/null 2>&1 fi @@ -705,8 +729,8 @@ start_apache() { ## - Start Apache Webservice ## - - if $APACHE_SYSTEMD_SERVICE_EXISTS ; then - systemctl start apache2 > /dev/null 2>&1 + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl start "$APACHE_SERVICE_FILE" > /dev/null 2>&1 else $APACHE_INIT_SCRIPT start > /dev/null 2>&1 fi