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

@ -45,6 +45,21 @@
- error.log
when: ansible_os_family == "OpenBSD"
- name: install custom logrotate
template:
dest: /usr/local/sbin/nginx-logrotate
src: nginx-logrotate.sh
mode: 0755
owner: root
group: "{{ ansible_wheel }}"
- name: add logrotate cron job
cron:
name: nginx-logrotate
hour: "0"
minute: "0"
job: /usr/local/sbin/nginx-logrotate
# https://bugzilla.redhat.com/show_bug.cgi?id=1725248
- block:
- name: create drop-in directory for service

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