ansible/roles/nginx/templates/nginx-logrotate.sh

25 lines
373 B
Bash
Executable file

#!/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