#!/bin/sh
set -e
echo "Running initial build..."
make -C /var/www
TRIGGER="/tmp/rebuild_trigger"
echo "Starting file watcher..."
inotifywait -m -r \
-e close_write,moved_to,create \
--exclude '(dirindex|varindex)\.xml$' \
--format '%w%f' \
/var/www/xml /var/www/xsls \
| while read file; do
touch "$TRIGGER"
done &
(
while true; do
if [ -f "$TRIGGER" ]; then
sleep 1.0
rm -f "$TRIGGER"
echo "Changes detected. Rebuilding..."
make -C /var/www || echo "Build failed. Fix the errors to trigger a rebuild."
else
sleep 1.0
fi
done
) &
echo "NOTICE: nginx.org development site is running at http://localhost:8001/"
exec nginx -g 'daemon off;'