--- /usr/sbin/apache2ctl 2019-09-03 14:46:22.490177200 -0600 +++ /tmp/apachectl_patched.sh 2019-09-03 14:45:53.431480800 -0600 @@ -37,6 +37,7 @@ # When multiple arguments are given, only the error from the _last_ # one is reported. Run "apachectl help" for usage info # + ARGV="$@" # # |||||||||||||||||||| START CONFIGURATION SECTION |||||||||||||||||||| @@ -44,13 +45,24 @@ # # main configuration directory if test -z "$APACHE_CONFDIR" ; then - if test "${0##*apache2ctl-}" != "$0" ; then - APACHE_CONFDIR="/etc/apache2-${0##*apache2ctl-}" - else - APACHE_CONFDIR=/etc/apache2 - fi + if test "${0##*apache2ctl-}" != "$0" ; then + APACHE_CONFDIR="/etc/apache2-${0##*apache2ctl-}" + else + APACHE_CONFDIR=/etc/apache2 + fi fi +SUFFIX="${APACHE_CONFDIR##/etc/apache2-}" +case "$SUFFIX" in + /etc/apache2) + SUFFIX="" + ;; + *) + SUFFIX="@$SUFFIX" + ;; +esac +APACHE_SYSTEMD_SERVICE="apache2$SUFFIX" + # the path to the environment variable file test -z "$APACHE_ENVVARS" && APACHE_ENVVARS="$APACHE_CONFDIR/envvars" # pick up any necessary environment variables @@ -59,7 +71,7 @@ fi if test "$APACHE_CONFDIR" != /etc/apache2 ; then - APACHE_ARGUMENTS="-d $APACHE_CONFDIR $APACHE_ARGUMENTS" + APACHE_ARGUMENTS="-d $APACHE_CONFDIR $APACHE_ARGUMENTS" fi # the following APACHE_* variables should be set in /etc/apache2/envvars # @@ -68,7 +80,7 @@ # # a command that outputs a formatted text version of the HTML at the # url given on the command line. Designed for lynx, however other -# programs may work. +# programs may work. LYNX="${APACHE_LYNX:-www-browser -dump}" # # the URL to your server's mod_status status page. If you do not @@ -91,7 +103,7 @@ fi ERROR=0 -if [ "x$ARGV" = "x" ] || [ "x$ARGV" = "xusage" ] || [ "x$ARGV" = "xhelp" ] || [ "x$ARGV" = "x--help" ]; then +if [ "x$ARGV" = "x" ] || [ "x$ARGV" = "xusage" ] || [ "x$ARGV" = "xhelp" ] || [ "x$ARGV" = "x--help" ]; then echo "Usage: $0 start|stop|restart|graceful|graceful-stop|configtest|status|fullstatus|help" >&2 echo " $0 " >&2 echo " $0 -h (for help on )" >&2 @@ -136,21 +148,61 @@ [ ! -d ${APACHE_RUN_DIR:-/var/run/apache2} ] && mkdir -p ${APACHE_RUN_DIR:-/var/run/apache2} [ ! -d ${APACHE_LOCK_DIR:-/var/lock/apache2} ] && mkdir_chown ${APACHE_RUN_USER:-www-data} ${APACHE_LOCK_DIR:-/var/lock/apache2} -case $ARGV in +case "$ARGV" in start) # ssl_scache shouldn't be here if we're just starting up. # (this is bad if there are several apache2 instances running) rm -f ${APACHE_RUN_DIR:-/var/run/apache2}/*ssl_scache* - $HTTPD ${APACHE_ARGUMENTS} -k $ARGV + + need_systemd=false + if [ -z "$APACHE_STARTED_BY_SYSTEMD" ] ; then + case "$(readlink -f /proc/1/exe)" in + *systemd*) + need_systemd=true + ;; + *) + ;; + esac + fi + if $need_systemd ; then + # If running on systemd we should not start httpd without systemd + # or systemd will get confused about the status of httpd. + echo "Invoking 'systemctl start $APACHE_SYSTEMD_SERVICE'." + echo "Use 'systemctl status $APACHE_SYSTEMD_SERVICE' for more info." + systemctl start "$APACHE_SYSTEMD_SERVICE" + else + unset APACHE_STARTED_BY_SYSTEMD + $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV" + fi + ERROR=$? ;; stop|graceful-stop) - $HTTPD ${APACHE_ARGUMENTS} -k $ARGV + $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV" ERROR=$? ;; restart|graceful) if $HTTPD ${APACHE_ARGUMENTS} -t 2> /dev/null ; then - $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV" + need_systemd=false + if [ -z "$APACHE_STARTED_BY_SYSTEMD" ] ; then + case "$(readlink -f /proc/1/exe)" in + *systemd*) + need_systemd=true + ;; + *) + ;; + esac + fi + if $need_systemd ; then + # If running on systemd we should not start httpd without systemd + # or systemd will get confused about the status of httpd. + echo "Invoking 'systemctl start $APACHE_SYSTEMD_SERVICE'." + echo "Use 'systemctl status $APACHE_SYSTEMD_SERVICE' for more info." + systemctl start "$APACHE_SYSTEMD_SERVICE" + else + unset APACHE_STARTED_BY_SYSTEMD + $HTTPD ${APACHE_ARGUMENTS} -k "$ARGV" + fi else $HTTPD ${APACHE_ARGUMENTS} -t fi @@ -173,12 +225,12 @@ get_status ;; *) - $HTTPD ${APACHE_ARGUMENTS} $ARGV + $HTTPD ${APACHE_ARGUMENTS} "$@" ERROR=$? esac if [ "$ERROR" != 0 ] ; then - echo Action \'"$@"\' failed. - echo The Apache error log may have more information. + echo Action \'"$@"\' failed. + echo The Apache error log may have more information. fi exit $ERROR