From 11aad9b6760b249e8ea490948854a03125b3cf53 Mon Sep 17 00:00:00 2001 From: studersi Date: Wed, 18 Apr 2018 11:37:25 +0200 Subject: [PATCH 01/15] Use inotifywait to watch for changes instead of reloading manually. --- bin/apachex | 92 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/bin/apachex b/bin/apachex index d599588..b410308 100755 --- a/bin/apachex +++ b/bin/apachex @@ -69,6 +69,36 @@ function wait_process_disappears() { fi } +function start_apache() { + echo + if [ -f $AP_PID_FILE ]; then + + ps ax | grep -v " grep " | grep -q $(cat $AP_PID_FILE) + + if [ $? -eq 0 ]; then + + echo -n "Stopping active apache process ... " + + sudo kill -TERM $(cat $AP_PID_FILE) + + wait_process_disappears + else + sudo rm $AP_PID_FILE + fi + fi + + # clean up semaphores + sudo ipcs -s | grep $AP_USER | awk '{ print $2 }' | xargs -n 1 sudo ipcrm sem 2>/dev/null >/dev/null + + echo -n "Launching apache on config file $AP_CONF_FILE ... " + + sudo $AP_BIN -X -f $AP_CONF_FILE & + + wait_pid_exists + + echo +} + # ----------------------------------------------------------------------- # INIT @@ -157,55 +187,25 @@ fi # ----------------------------------------------------------------------- # MAIN LOOP # ----------------------------------------------------------------------- - -while [ 1 ]; do - echo - if [ -f $AP_PID_FILE ]; then - - ps ax | grep -v " grep " | grep -q $(cat $AP_PID_FILE) - - if [ $? -eq 0 ]; then - - echo -n "Stopping active apache process ... " - - sudo kill -TERM $(cat $AP_PID_FILE) - - wait_process_disappears - else - sudo rm $AP_PID_FILE - fi - fi - - # clean up semaphores - sudo ipcs -s | grep $AP_USER | awk '{ print $2 }' | xargs -n 1 sudo ipcrm sem 2>/dev/null >/dev/null - - echo -n "Launching apache on config file $AP_CONF_FILE ... " - - sudo $AP_BIN -X -f $AP_CONF_FILE & - - wait_pid_exists - - echo - read -r -p 'Press [enter] to restart apache, enter [q] to stop apache and exit: ' var - - if [ "$var" == "q" ]; then - break - - fi +start_apache +inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) | +while read -r file; do + if [ "$file" = $AP_CONF_FILE ]; then + start_apache + echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " + fi done - # ----------------------------------------------------------------------- # SHUT-DOWN # ----------------------------------------------------------------------- -echo -echo -n "Bailing out ... " - -if [ -f $AP_PID_FILE ]; then - sudo kill -TERM $(cat $AP_PID_FILE) - wait_process_disappears -fi - -echo - +#echo +#echo -n "Bailing out ... " +# +#if [ -f $AP_PID_FILE ]; then +# sudo kill -TERM $(cat $AP_PID_FILE) +# wait_process_disappears +#fi +# +#echo From 0c3356402d8ceca9e5c0ecc0be45047c87f33fb4 Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 07:55:49 +0200 Subject: [PATCH 02/15] Check if inotifywait command available. --- bin/apachex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/apachex b/bin/apachex index b410308..0eab0f1 100755 --- a/bin/apachex +++ b/bin/apachex @@ -106,6 +106,14 @@ function start_apache() { VERBOSE=0 +# check if inotifywait command available +which inotifywait > /dev/null 2> /dev/null +rc=$? +if [ ${rc} != 0 ]; then + echo "The command inotifywait is not available. This is fatal. Aborting." + exit 1 +fi + AP_CONFS_PATTERN="/etc/apache2/apache2.conf /apache/conf/httpd.conf_* /opt/apache*/conf/httpd.conf_*" AP_CONF_FILE=$(ls -tr $AP_CONFS_PATTERN 2>/dev/null | tail -1) From 944d65deafbd454af017b084fdaf4d5a1342ccaf Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 08:09:38 +0200 Subject: [PATCH 03/15] Formatting. --- bin/apachex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index fe9ec1b..9b7e5b6 100755 --- a/bin/apachex +++ b/bin/apachex @@ -110,7 +110,7 @@ VERBOSE=0 which inotifywait > /dev/null 2> /dev/null rc=$? if [ ${rc} != 0 ]; then - echo "The command inotifywait is not available. This is fatal. Aborting." + echo "The command 'inotifywait' is not available. This is fatal. Aborting." exit 1 fi From 9d0950768a585bad8234207d4992cffb01da3afd Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 08:18:31 +0200 Subject: [PATCH 04/15] Print instructions immediately after startup and after every restart. --- bin/apachex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index 9b7e5b6..cd47208 100755 --- a/bin/apachex +++ b/bin/apachex @@ -99,6 +99,9 @@ function start_apache() { echo } +function print_instructions() { + echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " +} # ----------------------------------------------------------------------- # INIT @@ -196,11 +199,12 @@ fi # MAIN LOOP # ----------------------------------------------------------------------- start_apache +print_instructions inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) | while read -r file; do if [ "$file" = $AP_CONF_FILE ]; then start_apache - echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " + print_instructions fi done From 8a9cb627031e2c562cba41a0dad59b9b9e75c6ea Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 08:19:55 +0200 Subject: [PATCH 05/15] Redirect unnecessary output to '/dev/null'. --- bin/apachex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index cd47208..bcb9ea6 100755 --- a/bin/apachex +++ b/bin/apachex @@ -200,7 +200,7 @@ fi # ----------------------------------------------------------------------- start_apache print_instructions -inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) | +inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) 2> /dev/null | while read -r file; do if [ "$file" = $AP_CONF_FILE ]; then start_apache From 0b184b9dc4190043a8242944b94cba892afb70fe Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 08:27:40 +0200 Subject: [PATCH 06/15] Clean exit on Ctrl+c. --- bin/apachex | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bin/apachex b/bin/apachex index bcb9ea6..2285f2c 100755 --- a/bin/apachex +++ b/bin/apachex @@ -103,12 +103,27 @@ function print_instructions() { echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " } +function clean_exit() { + echo + echo -n "Bailing out ... " + + if [ -f $AP_PID_FILE ]; then + sudo kill -TERM $(cat $AP_PID_FILE) + wait_process_disappears + fi + + echo +} + # ----------------------------------------------------------------------- # INIT # ----------------------------------------------------------------------- VERBOSE=0 +# trap Ctrl+c +trap clean_exit INT + # check if inotifywait command available which inotifywait > /dev/null 2> /dev/null rc=$? @@ -207,17 +222,3 @@ while read -r file; do print_instructions fi done - -# ----------------------------------------------------------------------- -# SHUT-DOWN -# ----------------------------------------------------------------------- - -#echo -#echo -n "Bailing out ... " -# -#if [ -f $AP_PID_FILE ]; then -# sudo kill -TERM $(cat $AP_PID_FILE) -# wait_process_disappears -#fi -# -#echo From ca1cf179546148b025fceb66b6b108dae73746c1 Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 08:57:53 +0200 Subject: [PATCH 07/15] Add manual mode. --- bin/apachex | 90 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/bin/apachex b/bin/apachex index 2285f2c..0bd1f46 100755 --- a/bin/apachex +++ b/bin/apachex @@ -100,7 +100,11 @@ function start_apache() { } function print_instructions() { - echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " + if [ "$MANUAL_MODE" -eq 1 ]; then + echo "Press [Enter] to restart apache, press [Ctrl+C] to exit: " + else + echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " + fi } function clean_exit() { @@ -113,6 +117,7 @@ function clean_exit() { fi echo + exit 0 } # ----------------------------------------------------------------------- @@ -120,16 +125,43 @@ function clean_exit() { # ----------------------------------------------------------------------- VERBOSE=0 +MANUAL_MODE=0 + +# param checking loop +while [ 1 ] +do + if [ -n "$1" ]; then + ARG="$1" + export FC="`echo $ARG | sed -e 's/^\(.\).*/\1/'`" # first char of $ARG + if [ "-" = $FC ]; then + case $1 in + -h) usage; exit;; + --help) usage; exit;; + -v) export VERBOSE=1;; + --verbose) export VERBOSE=1;; + -m) export MANUAL_MODE=1;; + --manual-mode) export MANUAL_MODE=1;; + esac + shift + else + break + fi + else + break + fi +done # trap Ctrl+c trap clean_exit INT -# check if inotifywait command available -which inotifywait > /dev/null 2> /dev/null -rc=$? -if [ ${rc} != 0 ]; then - echo "The command 'inotifywait' is not available. This is fatal. Aborting." - exit 1 +# check if inotifywait command available (not in manual mode) +if [ "$MANUAL_MODE" -eq 0 ]; then + which inotifywait > /dev/null 2> /dev/null + rc=$? + if [ ${rc} != 0 ]; then + echo "The command 'inotifywait' is not available. Install it or use manual mode (-m). This is fatal. Aborting." + exit 1 + fi fi AP_CONFS_PATTERN="/etc/apache2/apache2.conf /apache/conf/httpd.conf_* /opt/apache*/conf/httpd.conf_*" @@ -179,28 +211,6 @@ if [ -z "AP_USER" -o "$AP_USER" == "${APACHE_RUN_USER}" ]; then AP_USER="www-data" fi -# param checking loop -while [ 1 ] -do - if [ -n "$1" ]; then - ARG="$1" - export FC="`echo $ARG | sed -e 's/^\(.\).*/\1/'`" # first char of $ARG - if [ "-" = $FC ]; then - case $1 in - -h) usage; exit;; - --help) usage; exit;; - -v) export VERBOSE=1;; - --verbose) export VERBOSE=1;; - esac - shift - else - break - fi - else - break - fi -done - if [ "$VERBOSE" -eq 1 ]; then echo "Apache Root: $AP_ROOT" echo "Apache Binary: $AP_BIN" @@ -213,12 +223,20 @@ fi # ----------------------------------------------------------------------- # MAIN LOOP # ----------------------------------------------------------------------- -start_apache -print_instructions -inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) 2> /dev/null | -while read -r file; do - if [ "$file" = $AP_CONF_FILE ]; then +if [ "$MANUAL_MODE" -eq 1 ]; then + while [ 1 ]; do + start_apache + print_instructions + read -r + done +else start_apache print_instructions - fi -done + inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) 2> /dev/null | + while read -r file; do + if [ "$file" = $AP_CONF_FILE ]; then + start_apache + print_instructions + fi + done +fi \ No newline at end of file From b0bf81fc1f0a973eb52e1de25f34a8543ea4aaca Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 09:34:47 +0200 Subject: [PATCH 08/15] Check config file before restarting apache. --- bin/apachex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bin/apachex b/bin/apachex index 0bd1f46..4e45478 100755 --- a/bin/apachex +++ b/bin/apachex @@ -70,7 +70,25 @@ function wait_process_disappears() { } function start_apache() { + # check config files echo + echo -n "Checking config file ... " + sudo $AP_BIN -t -f $AP_CONF_FILE 2> /dev/null + rc=$? + if [ ${rc} != 0 ]; then + echo "fail" + echo + echo "Errors in config file detected" + echo "-------------------------------------------------------------" + sudo $AP_BIN -t -f $AP_CONF_FILE + echo "-------------------------------------------------------------" + echo + echo "Not restarting apache because of syntax errors in config file" + echo + return ${rc} + fi + echo "ok" + if [ -f $AP_PID_FILE ]; then ps ax | grep -v " grep " | grep -q $(cat $AP_PID_FILE) From ad6bb86ae41493e62b68599c6f2aaf6c977551e2 Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 10:21:24 +0200 Subject: [PATCH 09/15] Add additional output and second verbosity level. --- bin/apachex | 55 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/bin/apachex b/bin/apachex index 4e45478..fed4b12 100755 --- a/bin/apachex +++ b/bin/apachex @@ -72,22 +72,23 @@ function wait_process_disappears() { function start_apache() { # check config files echo - echo -n "Checking config file ... " + if [ "$VERBOSITY" -ge 1 ]; then echo -n "`timestamp`Checking config file ... "; fi + sudo $AP_BIN -t -f $AP_CONF_FILE 2> /dev/null rc=$? if [ ${rc} != 0 ]; then echo "fail" echo - echo "Errors in config file detected" - echo "-------------------------------------------------------------" + echo "`timestamp`Errors in config file detected" + echo "`timestamp`----------------------------------------------------------------------" sudo $AP_BIN -t -f $AP_CONF_FILE - echo "-------------------------------------------------------------" + echo "`timestamp`----------------------------------------------------------------------" echo - echo "Not restarting apache because of syntax errors in config file" + echo "`timestamp`Not restarting apache because of syntax errors in config file" echo return ${rc} fi - echo "ok" + if [ "$VERBOSITY" -ge 1 ]; then echo "ok"; fi if [ -f $AP_PID_FILE ]; then @@ -95,7 +96,7 @@ function start_apache() { if [ $? -eq 0 ]; then - echo -n "Stopping active apache process ... " + echo -n "`timestamp`Stopping active apache process ... " sudo kill -TERM $(cat $AP_PID_FILE) @@ -108,7 +109,7 @@ function start_apache() { # clean up semaphores sudo ipcs -s | grep $AP_USER | awk '{ print $2 }' | xargs -n 1 sudo ipcrm sem 2>/dev/null >/dev/null - echo -n "Launching apache on config file $AP_CONF_FILE ... " + echo -n "`timestamp`Launching apache on config file $AP_CONF_FILE ... " sudo $AP_BIN -X -f $AP_CONF_FILE & @@ -119,15 +120,15 @@ function start_apache() { function print_instructions() { if [ "$MANUAL_MODE" -eq 1 ]; then - echo "Press [Enter] to restart apache, press [Ctrl+C] to exit: " + echo "`timestamp`Press [Enter] to restart apache, press [Ctrl+C] to exit: " else - echo "Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " + echo "`timestamp`Edit and save '$AP_CONF_FILE' to restart apache, press [Ctrl+C] to exit: " fi } function clean_exit() { echo - echo -n "Bailing out ... " + echo -n "`timestamp`Bailing out ... " if [ -f $AP_PID_FILE ]; then sudo kill -TERM $(cat $AP_PID_FILE) @@ -138,11 +139,15 @@ function clean_exit() { exit 0 } +function timestamp() { + if [ "$VERBOSITY" -ge 2 ]; then echo -n "$(date +"%T") "; fi +} + # ----------------------------------------------------------------------- # INIT # ----------------------------------------------------------------------- -VERBOSE=0 +VERBOSITY=0 MANUAL_MODE=0 # param checking loop @@ -155,8 +160,8 @@ do case $1 in -h) usage; exit;; --help) usage; exit;; - -v) export VERBOSE=1;; - --verbose) export VERBOSE=1;; + -v) export VERBOSITY=$((VERBOSITY+1));; + --verbose) export VERBOSITY=$((VERBOSITY+1));; -m) export MANUAL_MODE=1;; --manual-mode) export MANUAL_MODE=1;; esac @@ -177,7 +182,7 @@ if [ "$MANUAL_MODE" -eq 0 ]; then which inotifywait > /dev/null 2> /dev/null rc=$? if [ ${rc} != 0 ]; then - echo "The command 'inotifywait' is not available. Install it or use manual mode (-m). This is fatal. Aborting." + echo "`timestamp`The command 'inotifywait' is not available. Install it or use manual mode (-m). This is fatal. Aborting." exit 1 fi fi @@ -186,7 +191,7 @@ AP_CONFS_PATTERN="/etc/apache2/apache2.conf /apache/conf/httpd.conf_* /opt/apach AP_CONF_FILE=$(ls -tr $AP_CONFS_PATTERN 2>/dev/null | tail -1) if [ ! -f $AP_CONF_FILE ]; then - echo "Apache config file can not be determined. This is fatal. Aborting." + echo "`timestamp`Apache config file can not be determined. This is fatal. Aborting." exit 1 fi @@ -195,7 +200,7 @@ if [ ! -d $AP_ROOT ]; then if [ -d "/usr/local/apache" ]; then AP_ROOT="/usr/local/apache" else - echo "Apache server root can not be determined. This is fatal. Aborting." + echo "`timestamp`Apache server root can not be determined. This is fatal. Aborting." exit 1 fi fi @@ -206,7 +211,7 @@ if [ ! -f $AP_BIN ]; then if [ -f "/usr/sbin/apache2" ]; then AP_BIN="/usr/sbin/apache2" else - echo "Apache binary can not be determined. This is fatal. Aborting." + echo "`timestamp`Apache binary can not be determined. This is fatal. Aborting." exit 1 fi fi @@ -229,12 +234,12 @@ if [ -z "AP_USER" -o "$AP_USER" == "${APACHE_RUN_USER}" ]; then AP_USER="www-data" fi -if [ "$VERBOSE" -eq 1 ]; then - echo "Apache Root: $AP_ROOT" - echo "Apache Binary: $AP_BIN" - echo "Apache Config: $AP_CONF_FILE" - echo "Apache PidFile: $AP_PID_FILE" - echo "Apache User: $AP_USER" +if [ "$VERBOSITY" -ge 1 ]; then + echo "`timestamp`Apache Root: $AP_ROOT" + echo "`timestamp`Apache Binary: $AP_BIN" + echo "`timestamp`Apache Config: $AP_CONF_FILE" + echo "`timestamp`Apache PidFile: $AP_PID_FILE" + echo "`timestamp`Apache User: $AP_USER" fi @@ -249,10 +254,12 @@ if [ "$MANUAL_MODE" -eq 1 ]; then done else start_apache + if [ "$VERBOSITY" -ge 1 ]; then echo "`timestamp`Starting to watch inode for changes"; echo; fi print_instructions inotifywait -m -e close_write,moved_to --format %w%f $(dirname $AP_CONF_FILE) 2> /dev/null | while read -r file; do if [ "$file" = $AP_CONF_FILE ]; then + if [ "$VERBOSITY" -ge 1 ]; then echo; echo "`timestamp`Config file changed"; fi start_apache print_instructions fi From 1e03267ae569f47c3cc4942e5b78bd047679a34c Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 10:26:03 +0200 Subject: [PATCH 10/15] Fix bug in output. --- bin/apachex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index fed4b12..0f710cc 100755 --- a/bin/apachex +++ b/bin/apachex @@ -77,7 +77,7 @@ function start_apache() { sudo $AP_BIN -t -f $AP_CONF_FILE 2> /dev/null rc=$? if [ ${rc} != 0 ]; then - echo "fail" + if [ "$VERBOSITY" -ge 1 ]; then echo "fail"; fi echo echo "`timestamp`Errors in config file detected" echo "`timestamp`----------------------------------------------------------------------" From ece4553db98578088bf9124a460305697292749d Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 12:28:20 +0200 Subject: [PATCH 11/15] Refactor argument parsing and add config argument. --- bin/apachex | 65 +++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/bin/apachex b/bin/apachex index 0f710cc..308a1c8 100755 --- a/bin/apachex +++ b/bin/apachex @@ -13,10 +13,6 @@ # ----------------------------------------------------------------------- function usage() { - -echo -echo "$0" - cat <<'EOF' Script to launch apache repeatedly via httpd -X. @@ -25,9 +21,18 @@ The script guesses the desired apache config and handles - sudo - pidfile - semaphore cleanup - + EOF +echo "Usage: $0 [-h] [-v] [-m] [-c ]" +cat <<'EOF' +Options: + -h | --help : print this help text + -v | --verbose : increase verbosity level + -m | --manual-mode : manually restart apache by pressing enter + (does not require inotify-tools) + -c | --config-file : use specific config file +EOF } function wait_pid_exists() { @@ -149,29 +154,19 @@ function timestamp() { VERBOSITY=0 MANUAL_MODE=0 - -# param checking loop -while [ 1 ] -do - if [ -n "$1" ]; then - ARG="$1" - export FC="`echo $ARG | sed -e 's/^\(.\).*/\1/'`" # first char of $ARG - if [ "-" = $FC ]; then - case $1 in - -h) usage; exit;; - --help) usage; exit;; - -v) export VERBOSITY=$((VERBOSITY+1));; - --verbose) export VERBOSITY=$((VERBOSITY+1));; - -m) export MANUAL_MODE=1;; - --manual-mode) export MANUAL_MODE=1;; - esac - shift - else - break - fi - else - break - fi +AP_CONF_FILE="" + +# parse command line arguments +while test $# -gt 0; do + case "$1" in + -h|--help) usage; exit 0 ;; + -v*) VERBOSITY=$(( $(echo -n $1 | wc -m)-1 )) ;; + --verbose) VERBOSITY=$((VERBOSITY+1)) ;; + -m|--manual-mode) MANUAL_MODE=1 ;; + -c|--config-file) shift; AP_CONF_FILE=$1 ;; + *) usage; exit 1 ;; + esac + shift done # trap Ctrl+c @@ -187,12 +182,14 @@ if [ "$MANUAL_MODE" -eq 0 ]; then fi fi -AP_CONFS_PATTERN="/etc/apache2/apache2.conf /apache/conf/httpd.conf_* /opt/apache*/conf/httpd.conf_*" -AP_CONF_FILE=$(ls -tr $AP_CONFS_PATTERN 2>/dev/null | tail -1) - -if [ ! -f $AP_CONF_FILE ]; then - echo "`timestamp`Apache config file can not be determined. This is fatal. Aborting." - exit 1 +if [ "$AP_CONF_FILE" == "" ]; then + AP_CONFS_PATTERN="/etc/apache2/apache2.conf /apache/conf/httpd.conf* /opt/apache*/conf/httpd.conf*" + AP_CONF_FILE=$(ls -tr $AP_CONFS_PATTERN 2>/dev/null | tail -1) + + if [ ! -f $AP_CONF_FILE ]; then + echo "`timestamp`Apache config file can not be determined. This is fatal. Aborting." + exit 1 + fi fi AP_ROOT=$(grep ServerRoot $AP_CONF_FILE | sed -e "s/.*ServerRoot\s*//" | tr -d "'" | tr -d '"') From 3c85e4a3b9f0fb89c59bb87c0852c4ad2bdf7224 Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 12:33:24 +0200 Subject: [PATCH 12/15] Fix usage text. --- bin/apachex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index 308a1c8..977cdac 100755 --- a/bin/apachex +++ b/bin/apachex @@ -24,7 +24,7 @@ The script guesses the desired apache config and handles EOF -echo "Usage: $0 [-h] [-v] [-m] [-c ]" +echo "Usage: $0 [-h] [-v[v]] [-m] [-c ]" cat <<'EOF' Options: -h | --help : print this help text From ede06da9ef0ebb6594bd0bcd88b84ae5f2570eb9 Mon Sep 17 00:00:00 2001 From: studersi Date: Tue, 8 May 2018 14:45:40 +0200 Subject: [PATCH 13/15] Switch to manual mode if inotifywait not available instead of exiting. --- bin/apachex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/apachex b/bin/apachex index 977cdac..6fe9db3 100755 --- a/bin/apachex +++ b/bin/apachex @@ -177,8 +177,8 @@ if [ "$MANUAL_MODE" -eq 0 ]; then which inotifywait > /dev/null 2> /dev/null rc=$? if [ ${rc} != 0 ]; then - echo "`timestamp`The command 'inotifywait' is not available. Install it or use manual mode (-m). This is fatal. Aborting." - exit 1 + echo "`timestamp`The command 'inotifywait' is not available, switching to manual mode." + MANUAL_MODE=1 fi fi From 7cf857554bd444a4b56f8a2a7e425ca69019eed5 Mon Sep 17 00:00:00 2001 From: studersi Date: Wed, 16 May 2018 15:43:15 +0200 Subject: [PATCH 14/15] Fix bug where PID file is not defined in config file. --- bin/apachex | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/apachex b/bin/apachex index 6fe9db3..0bd06e9 100755 --- a/bin/apachex +++ b/bin/apachex @@ -107,6 +107,7 @@ function start_apache() { wait_process_disappears else + echo "`timestamp`Could not determine process pid" sudo rm $AP_PID_FILE fi fi @@ -213,17 +214,20 @@ if [ ! -f $AP_BIN ]; then fi fi +# fetch pid file from config AP_PID_FILE=$(grep PidFile $AP_CONF_FILE | sed -e "s/.*PidFile\s*//" | tr -d "'" | tr -d '"') +# if pid file not configured +if [ -z "AP_PID_FILE" -o "$AP_PID_FILE" == "" ]; then + AP_PID_FILE="$AP_ROOT/logs/httpd.pid" +fi + +# if not absolute path to pid file echo "$AP_PID_FILE" | egrep -q "^\/" if [ $? -eq 1 ]; then AP_PID_FILE="$AP_ROOT/$AP_PID_FILE" fi -if [ -z "AP_PID_FILE" -o "$AP_PID_FILE" == "" ]; then - AP_PID_FILE="$AP_ROOT/logs/httpd.pid" -fi - AP_USER=$(egrep "\bUser\s+" $AP_CONF_FILE | sed -e "s/.*User\s*//" | tr -d "'" | tr -d '"') From ec8c977f471caaa59008749668c6716ceaad3b6f Mon Sep 17 00:00:00 2001 From: studersi Date: Wed, 16 May 2018 16:17:52 +0200 Subject: [PATCH 15/15] Fix comment. --- bin/apachex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/apachex b/bin/apachex index 0bd06e9..5dcc6c7 100755 --- a/bin/apachex +++ b/bin/apachex @@ -107,7 +107,7 @@ function start_apache() { wait_process_disappears else - echo "`timestamp`Could not determine process pid" + echo "`timestamp`No running process found" sudo rm $AP_PID_FILE fi fi