Created
June 12, 2019 03:17
-
-
Save vladkras/4e6bf0cb53eb9c623b19426da0892ebb to your computer and use it in GitHub Desktop.
Test config and reload Apache in one command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reload () { | |
STATUS=$(sudo apache2ctl configtest 2>&1) | |
OK=$(echo $STATUS | grep "OK" | wc -l) | |
if [[ $OK -eq 1 ]]; then | |
echo "reloading Apache..." | |
sudo service apache2 reload | |
else | |
echo "$STATUS" | |
LINEOF=$(echo "$STATUS" | grep -Eo "line ([0-9]+) of [^:]+") | |
if [ ! -z "$LINEOF" ]; then | |
POS=$(echo "$LINEOF" | cut -d' ' -f2) | |
FILE=$(echo "$LINEOF" | cut -d' ' -f4) | |
echo "Open $FILE:$POS to edit [y/n]?" | |
read y | |
if [[ "$y" == "y" ]]; then | |
sudo vim +$POS $FILE | |
fi | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function tests Apache config for errors and immediately reloads If none found, or requests if you want to edit specific line in your config file where problem was found.
Add this function to your
~/.bashrc
file, relogin and typereload
(I use vim and apache2)