Improve detection of apache systemd service file if exists.

This commit is contained in:
Christoph 2018-01-10 04:40:39 +01:00
parent 569cde854e
commit 00fcb8de66

View File

@ -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