Ротация логов Traefik

This commit is contained in:
2026-04-25 13:39:46 +03:00
parent 9275db1598
commit a8c3f1b887
4 changed files with 38 additions and 0 deletions

View File

@@ -167,6 +167,17 @@ services:
- "4000:4000"
restart: unless-stopped
# ================== Ротация логов Traefik ==================
logrotate:
build:
context: ./logrotate
dockerfile: Dockerfile
volumes:
- traefik-logs:/var/log/traefik:rw
networks:
- eventhub-net
restart: unless-stopped
networks:
eventhub-net:
driver: bridge

View File

@@ -0,0 +1,6 @@
FROM alpine:latest
RUN apk add --no-cache logrotate dcron tzdata
COPY logrotate.conf /etc/logrotate.conf
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,9 @@
#!/bin/sh
# Запускаем cron в фоне
crond -f &
# Ждём, пока cron стартует
sleep 2
# Добавляем задание в crontab (запуск logrotate каждый час)
echo "0 * * * * /usr/sbin/logrotate /etc/logrotate.conf" | crontab -
# Бесконечный цикл, чтобы контейнер не завершался
tail -f /dev/null

View File

@@ -0,0 +1,12 @@
/var/log/traefik/access.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 0644 root root
postrotate
# сигнал для переоткрытия файла (необязательно, Traefik переоткроет автоматически при необходимости)
endscript
}