File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # NGINX WATCH DAEMON
4+ #
5+ # Author: Devonte
6+ #
7+ # Place file in root of nginx folder: /etc/nginx
8+ # This will test your nginx config on any change and
9+ # if there are no problems it will reload your configuration
10+ # USAGE: sh nginx-watch.sh
11+
12+ # Set NGINX directory
13+ dir=' /etc/nginx'
14+
15+ # Get initial checksum values
16+ checksum_initial=` tar -cf - $dir | md5sum | awk ' {print $1}' `
17+ checksum_now=$checksum_initial
18+
19+ # Start nginx
20+ nginx
21+
22+ # Daemon that checks the md5 sum of the directory
23+ # ff the sums are different ( a file changed / added / deleted)
24+ # the nginx configuration is tested and reloaded on success
25+ while true
26+ do
27+ checksum_now=` tar -cf - $dir | md5sum | awk ' {print $1}' `
28+
29+ if [ $checksum_initial != $checksum_now ]; then
30+ echo ' [ NGINX ] A configuration file changed. Reloading...'
31+ nginx -t && nginx -s reload;
32+ fi
33+
34+ checksum_initial=$checksum_now
35+
36+ sleep 2
37+ done
You can’t perform that action at this time.
0 commit comments