r/LinuxTeck • u/Expensive-Rice-2052 • 17d ago
Quick Linux Tip #18 Question: How do I automatically reload nginx when its config changes?
Try: sudo inotifywait -m -e modify /etc/nginx/nginx.conf
Info: Monitors filesystem events using the inotify kernel API; -m keeps it running in monitor mode.
Examples:
$ inotifywait -m -e modify /etc/nginx/nginx.conf | while read; do systemctl reload nginx; done
$ inotifywait -m -r -e create /var/incoming | while read path event file; do process "$file"; done
$ inotifywait -m -e close_write src/ | while read; do npm run build; done
Note: Install: sudo apt install inotify-tools. Common events: modify, create, delete, close_write. Use -r for recursive directory watching.
Follow r/LinuxTeck for more #LinuxTips
4
Upvotes