nginx: Add log rotation script and cron job

This commit is contained in:
Timo Makinen 2021-09-16 17:49:42 +00:00
parent 287e8264fc
commit 5d8bf1c994
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#!/bin/sh
set -e
umask 022
[ -f /var/run/nginx.pid ] || exit 0
SUFFIX="$(date +%Y%m%d-%H%M%S)"
LOGS=""
for log in "{{ nginx_logdir }}"/*.log ; do
[ -s "$log" ] || continue
mv "$log" "${log}.${SUFFIX}"
LOGS="${LOGS} ${log}.${SUFFIX}"
done
[ -z "$LOGS" ] && exit 0
kill -USR1 "$(cat /var/run/nginx.pid)"
sleep 5
for log in $LOGS ; do
gzip "$log"
done