Skip to content

Commit 2a3fa5f

Browse files
committed
Rotate nginx log files.
1 parent 9ef1240 commit 2a3fa5f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ RUN \
3131
certbot \
3232
openssl \
3333
apache2-utils \
34+
logrotate \
3435
&& \
36+
# Adjust the logrotate config file.
37+
sed-patch 's|^/var/log/messages|#/var/log/messages|' /etc/logrotate.conf && \
3538
# Clean some uneeded stuff from mariadb.
3639
rm -r \
3740
/var/lib/mysql \

rootfs/etc/logrotate.d/nginx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/config/log/nginx/*.log {
2+
daily
3+
compress
4+
rotate 14
5+
missingok
6+
notifempty
7+
nocreate
8+
nodateext
9+
size 1024k
10+
sharedscripts
11+
postrotate
12+
test ! -f /run/nginx/nginx.pid || kill -USR1 `cat /run/nginx/nginx.pid`
13+
endscript
14+
}

rootfs/etc/services.d/logrotate/run

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/with-contenv sh
2+
3+
set -e # Exit immediately if a command exits with a non-zero status.
4+
5+
# Make sure we appear with a proper name under `ps`.
6+
if [ ! -L "$0" ]; then
7+
SV_NAME="$(basename "$(pwd)")"
8+
ln -sf run "$SV_NAME"
9+
exec ./"$SV_NAME" "$@"
10+
fi
11+
12+
log() {
13+
echo "[$(basename "$0")] $*"
14+
}
15+
16+
log "starting..."
17+
while true; do
18+
s6-applyuidgid -u $USER_ID -g $GROUP_ID -G ${SUP_GROUP_IDS:-$GROUP_ID} /usr/sbin/logrotate -s /config/logrotate.status /etc/logrotate.conf
19+
EXITVALUE=$?
20+
if [ $EXITVALUE != 0 ]; then
21+
log "exited abnormally with [$EXITVALUE]"
22+
fi
23+
sleep 3600
24+
done
25+
26+
# vim:ft=sh:ts=4:sw=4:et:sts=4

0 commit comments

Comments
 (0)