From c187e05fade82b84061f4473ebd44cddb8f97051 Mon Sep 17 00:00:00 2001 From: MrMeeb Date: Sun, 2 Jun 2024 21:29:42 +0000 Subject: [PATCH] Add logrotate (#25) Adds logrotate, running every day at 00:00. Rotates `letsencrypt.log`, keeping 10 versions. Rotates `renew.log` at 100 megabytes Closes #10 Reviewed-on: https://git.mrmeeb.stream/MrMeeb/certbot-cron-docker/pulls/25 Co-authored-by: MrMeeb Co-committed-by: MrMeeb --- Dockerfile | 2 +- root/certbot-prepare.sh | 3 ++- root/logrotate.conf | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 root/logrotate.conf diff --git a/Dockerfile b/Dockerfile index a0b96dd..461eae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ ENV CLOUDFLARE_TOKEN= ENV CERT_COUNT=1 #Get required packages -RUN apk update && apk add curl bash python3 py3-virtualenv procps tzdata nano shadow xz busybox-suid openssl +RUN apk update && apk add curl bash python3 py3-virtualenv procps tzdata nano shadow xz busybox-suid openssl logrotate #Make folders RUN mkdir /config && \ diff --git a/root/certbot-prepare.sh b/root/certbot-prepare.sh index 7931fc0..a8af628 100644 --- a/root/certbot-prepare.sh +++ b/root/certbot-prepare.sh @@ -786,7 +786,8 @@ if [ $ONE_SHOT == "true" ]; then elif [ $ONE_SHOT == "false" ]; then - echo "$INTERVAL /config/.renew-list.sh >> /config/logs/renew.log" > /config/.crontab.txt + echo "$INTERVAL /config/.renew-list.sh >> /config/logs/renew.log + 0 0 * * * logrotate -v --state /config/logs/logrotate.status /logrotate.conf" > /config/.crontab.txt echo "" diff --git a/root/logrotate.conf b/root/logrotate.conf new file mode 100644 index 0000000..a5efd31 --- /dev/null +++ b/root/logrotate.conf @@ -0,0 +1,15 @@ +missingok + +/config/logs/letsencrypt.log { + daily + rotate 10 + postrotate + find /config/logs -type f -regex '.*letsencrypt\.log\.\(.[2-9]\|[2-9].\|[1-9][0-9]\{2,\}\).*' -delete + endscript +} + +/config/logs/renew.log { + rotate 5 + size 100k + compress +} \ No newline at end of file