forked from LibreSchool/libreschool.org
log rotation
This commit is contained in:
parent
6e7b4d830a
commit
7d7667f1f9
@ -9,7 +9,7 @@ FROM alpine:latest
|
||||
|
||||
RUN \
|
||||
apk -U upgrade && \
|
||||
apk add nginx curl && \
|
||||
apk add nginx curl logrotate && \
|
||||
mkdir -p /wwwroot /logs
|
||||
|
||||
COPY docker/rootfs /
|
||||
@ -24,4 +24,4 @@ RUN nginx -t
|
||||
|
||||
HEALTHCHECK --timeout=10s CMD curl --silent --fail -o /dev/null http://127.0.0.1:80/
|
||||
|
||||
ENTRYPOINT [ "/usr/sbin/nginx" ]
|
||||
ENTRYPOINT [ "/bin/sh", "/app/entrypoint.sh" ]
|
||||
|
20
README.md
20
README.md
@ -78,3 +78,23 @@ services:
|
||||
ports:
|
||||
- 6080:80
|
||||
```
|
||||
|
||||
## Configure log rotation
|
||||
|
||||
By default logs are stored in a volume mounted on `/logs` directory inside the container.
|
||||
The access log file is `/logs/nginx.access.log` and it is rotate daily with a configurable retention, `7 days` by default.
|
||||
|
||||
```yaml
|
||||
version: "3.9"
|
||||
services:
|
||||
web:
|
||||
image: git.libreschool.org/libreschool/libreschool.org:latest
|
||||
restart: always
|
||||
container_name: libreschool_website
|
||||
volumes:
|
||||
- ./logs:/logs
|
||||
environment:
|
||||
LOG_DAYS: 14
|
||||
ports:
|
||||
- 6080:80
|
||||
```
|
||||
|
28
docker/rootfs/app/entrypoint.sh
Executable file
28
docker/rootfs/app/entrypoint.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
############ CHECK LOG DIRECTORY
|
||||
mkdir -p /logs
|
||||
chown nginx:www-data /logs
|
||||
chmod 0755 /logs
|
||||
|
||||
############ CONFIGURE LOGROTATE
|
||||
LOG_DAYS=${LOG_DAYS:-7}
|
||||
|
||||
############ START CRON
|
||||
crond -b
|
||||
cat >/etc/logrotate.d/nginx <<EOF
|
||||
/logs/nginx.access.log {
|
||||
missingok
|
||||
daily
|
||||
rotate ${LOG_DAYS}
|
||||
compress
|
||||
delaycompress
|
||||
sharedscripts
|
||||
postrotate
|
||||
/usr/sbin/nginx -s reopen
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
############ START
|
||||
/usr/sbin/nginx
|
Loading…
x
Reference in New Issue
Block a user