diff --git a/upgrade_roundcube.sh b/upgrade_roundcube.sh index 2725203..b4dd710 100755 --- a/upgrade_roundcube.sh +++ b/upgrade_roundcube.sh @@ -95,12 +95,40 @@ trap clean_up SIGHUP SIGINT SIGTERM # - Support systemd ? # - -if [[ "X$(which systemd)" = "X" ]]; then - SYSTEMD_EXISTS=false -else - SYSTEMD_EXISTS=true +systemd_supported=false + +systemd=$(which systemd) +systemctl=$(which systemctl) + +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true fi +# - Look for systemd service file or sysv init script for apache2 webservice +# - +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 -E "(enabled|disabled)" 2> /devnull ; then + + APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \ + | grep -e "^apache" \ + | awk '{print$1}') + + fi +fi + +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 DEFAULT_DB_HOST="localhost" @@ -340,22 +368,21 @@ fi echononl " Stop Apache Webserver.." -if $SYSTEMD_EXISTS ; then - systemctl stop apache2 > $log_file 2>&1 +if [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl stop $APACHE_SERVICE_FILE > $log_file 2>&1 + else + $APACHE_INIT_SCRIPT stop > $log_file 2>&1 + fi if [[ $? -eq 0 ]]; then echo_ok else echo_failed - fatal "$(cat $log_file)" + error "$(cat $log_file)" fi else - /etc/init.d/apache2 stop > ${logdir}/main.log 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - fatal "$(cat $log_file)" - fi + echo_skipped + warn "Neither an init-script nor a service file for 'apache2' webservice found!" fi @@ -583,22 +610,21 @@ fi # - Start Apache Webserver # - echononl " Start Apache Webserver.." -if $SYSTEMD_EXISTS ; then - systemctl start apache2 > $log_file 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - fatal "$(cat $log_file)" - fi +if [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then + if [[ -n "$APACHE_SERVICE_FILE" ]] ; then + systemctl start $APACHE_SERVICE_FILE > $log_file 2>&1 + else + $APACHE_INIT_SCRIPT start > $log_file 2>&1 + fi + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "$(cat $log_file)" + fi else - /etc/init.d/apache2 start> $log_file 2>&1 - if [[ $? -eq 0 ]]; then - echo_ok - else - echo_failed - fatal "$(cat $log_file)" - fi + echo_skipped + warn "Neither an init-script nor a service file for 'apache2' webservice found!" fi