mirror of
https://github.com/bitwarden/server.git
synced 2025-01-21 21:41:21 +01:00
Rotate nginx logs (#601)
* Rotate nginx logs * Create logrotate.sh * Update Dockerfile * Update entrypoint.sh * Update Dockerfile * Update logrotate.sh * No reason to disable logrotate * Update logrotate.sh * Update entrypoint.sh * typo * Avoid useless output * Use gosu
This commit is contained in:
parent
c7d34a7ac6
commit
47bda1e6d0
@ -13,12 +13,14 @@ COPY proxy.conf /etc/nginx
|
|||||||
COPY mime.types /etc/nginx
|
COPY mime.types /etc/nginx
|
||||||
COPY security-headers.conf /etc/nginx
|
COPY security-headers.conf /etc/nginx
|
||||||
COPY security-headers-ssl.conf /etc/nginx
|
COPY security-headers-ssl.conf /etc/nginx
|
||||||
|
COPY logrotate.sh /
|
||||||
COPY entrypoint.sh /
|
COPY entrypoint.sh /
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
EXPOSE 8443
|
EXPOSE 8443
|
||||||
|
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh \
|
||||||
|
&& chmod +x /logrotate.sh
|
||||||
|
|
||||||
HEALTHCHECK CMD curl --insecure -Lfs https://localhost:8443/alive || curl -Lfs http://localhost:8080/alive || exit 1
|
HEALTHCHECK CMD curl --insecure -Lfs https://localhost:8443/alive || curl -Lfs http://localhost:8080/alive || exit 1
|
||||||
|
|
||||||
|
@ -41,4 +41,8 @@ chown -R $USERNAME:$GROUPNAME /var/run/nginx
|
|||||||
chown -R $USERNAME:$GROUPNAME /var/cache/nginx
|
chown -R $USERNAME:$GROUPNAME /var/cache/nginx
|
||||||
chown -R $USERNAME:$GROUPNAME /var/log/nginx
|
chown -R $USERNAME:$GROUPNAME /var/log/nginx
|
||||||
|
|
||||||
|
# Launch a loop to rotate nginx logs on a daily basis
|
||||||
|
|
||||||
|
gosu $USERNAME:$GROUPNAME /bin/sh -c "/logrotate.sh loop >/dev/null 2>&1 &"
|
||||||
|
|
||||||
exec gosu $USERNAME:$GROUPNAME nginx -g 'daemon off;'
|
exec gosu $USERNAME:$GROUPNAME nginx -g 'daemon off;'
|
||||||
|
15
util/Nginx/logrotate.sh
Normal file
15
util/Nginx/logrotate.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
[ "$1" == "loop" ] && sleep $((24 * 3600 - (`date +%H` * 3600 + `date +%M` * 60 + `date +%S`)))
|
||||||
|
ts=$(date +%Y%m%d_%H%M%S)
|
||||||
|
mv /var/log/nginx/access.log /var/log/nginx/access.$ts.log
|
||||||
|
mv /var/log/nginx/error.log /var/log/nginx/error.$ts.log
|
||||||
|
kill -USR1 `cat /var/run/nginx/nginx.pid`
|
||||||
|
sleep 1
|
||||||
|
gzip /var/log/nginx/access.$ts.log
|
||||||
|
gzip /var/log/nginx/error.$ts.log
|
||||||
|
find /var/log/nginx/ -name "*.gz" -mtime +32 -delete
|
||||||
|
[ "$1" != "loop" ] && break
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user