From 9e67cd1c88812fe4f4ca9b66b7239fbd31b77e9a Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Sat, 23 Jan 2021 18:56:12 +0100 Subject: [PATCH] add daily logrotate to nginx --- docker-compose.yml | 1 + docker/nginx/Dockerfile | 8 +++++--- docker/nginx/logrotate | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 docker/nginx/logrotate diff --git a/docker-compose.yml b/docker-compose.yml index 416f4e92..cfeccaa4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,6 +69,7 @@ services: volumes: - ./docker/nginx/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro + - ./docker/nginx/logrotate:/etc/logrotate.d/nginx:ro - ./docker/data/nginx/cache:/data/nginx/cache - ./docker/data/nginx/logs:/usr/local/openresty/nginx/logs - ./docker/data/nginx/skynet:/data/nginx/skynet:ro diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index a0abc542..f5f33c7b 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -1,7 +1,9 @@ FROM openresty/openresty:1.19.3.1-8-bionic -# RUN apt-get update -qq && apt-get install cron logrotate -qq +RUN apt-get update -qq && apt-get install cron logrotate -qq RUN luarocks install luasocket -# CMD ["sh", "-c", "service cron start;", "/usr/local/openresty/bin/openresty -g daemon off;"] -CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"] +# change "syslog" user to "adm" user in logrotate.conf +RUN sed -i 's/^su root syslog/su root adm/' /etc/logrotate.conf + +CMD ["sh", "-c", "service cron start ; /usr/local/openresty/bin/openresty -g 'daemon off;'"] diff --git a/docker/nginx/logrotate b/docker/nginx/logrotate new file mode 100644 index 00000000..c8ee3f40 --- /dev/null +++ b/docker/nginx/logrotate @@ -0,0 +1,13 @@ +/usr/local/openresty/nginx/logs/*.log { + daily + dateext + rotate 3650 + missingok + notifempty + nocompress + create 640 root root + sharedscripts + postrotate + [ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid` + endscript +} \ No newline at end of file