Skip to content

Commit 98fd764

Browse files
committed
automatically reload nginx if the letsencrypt certificate is renewed.
1 parent 51595fd commit 98fd764

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

service_config/nginx/Dockerfile

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
FROM nginx:mainline-alpine
1+
FROM nginx:mainline
2+
3+
# Copy over the scripts
4+
COPY reloader.sh /
5+
COPY entrypoint.sh /
6+
7+
# Make the scripts executable
8+
RUN chmod +x /reloader.sh /entrypoint.sh
9+
10+
# Copy over the nginx config
211
COPY nginx.conf /etc/nginx/nginx.conf
12+
13+
# Install the requirements
14+
RUN apt-get update && apt-get install -y inotify-tools
15+
16+
# Clean up the apt cache
17+
RUN apt-get clean autoclean && apt-get autoremove -y && rm -rf /var/lib/{apt,dpkg,cache,log}/
18+
19+
ENTRYPOINT [ "/entrypoint.sh" ]
20+
CMD ["nginx", "-g", "daemon off;"]

service_config/nginx/entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
sh -c "/reloader.sh &"
4+
exec "$@"

service_config/nginx/reloader.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# This directories must me there to watch the files inside
4+
mkdir -p /etc/letsencrypt/live
5+
6+
while true
7+
do
8+
inotifywait -r --exclude .swp -e create -e modify -e delete -e move /etc/letsencrypt/live
9+
nginx -t
10+
if [ $? -eq 0 ]; then
11+
echo "Detected Nginx change"
12+
echo "Executing: nginx -s reload"
13+
nginx -s reload
14+
else
15+
echo "Errors detected in nginx config, not reloading."
16+
fi
17+
done

0 commit comments

Comments
 (0)