Skip to content

Commit 5928872

Browse files
committed
Create nginx-watch.sh
1 parent 8015f71 commit 5928872

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

nginx-watch.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

0 commit comments

Comments
 (0)