Skip to content

Instantly share code, notes, and snippets.

@alchemycs
Created August 15, 2014 00:33
Show Gist options
  • Save alchemycs/af5a03a02d7b986ee60c to your computer and use it in GitHub Desktop.
Save alchemycs/af5a03a02d7b986ee60c to your computer and use it in GitHub Desktop.
Apache Config Auto-Watch via Upstart
# apache-config-watch - checks config changes and reloads apache if the configs are ok
description "Reload apache when configs have changed."
author "Michael McHugh <developer@yrucalling.me>"
start on runlevel [2345]
stop on runlevel [016]
respawn
exec /opt/CompliSpace/bin/apache-config-watcher.sh
#!/bin/bash
# DO NOT RUN THIS MANUALY
# This script is used by upstart and run as a dameon at boot time
while inotifywait -qre close_write -e modify -e move -e delete -e create /etc/apache2/sites-enabled; do
TMP=$(mktemp)
apache2ctl configtest &>$TMP
cat $TMP | grep -q "Syntax OK"
if [ $? -eq 0 ]
then
echo "$(date): Syntax is OK, reloading"
service apache2 reload
else
echo "$(date): Syntax is BAD, fix it first!"
fi
# cat $TMP
rm $TMP
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment