java.nginx.lograte.yml
1.02 KB
# logrotate java nginx
# 1. configure logrotate
# 2. configure crontab: crontab: 0 2 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
- hosts: java-nginx
vars:
logrotate_scripts:
- name: java-nginx-logrotate
paths:
- "/Data/logs/nginx/*.log"
options:
- daily
- dateext
- rotate 720
- olddir /Data/logs/nginx/backup
- notifempty
- compress
- sharedscripts
scripts:
postrotate: "[ ! -f /Data/local/openresty-1.9.15.1/nginx/logs/nginx.pid ] || kill -USR1 `cat /Data/local/openresty-1.9.15.1/nginx/logs/nginx.pid`"
remote_user: root
roles:
- logrotate
tasks:
- name: remove existed precated crontab
shell: "crontab -u root -l |grep -v 'logrotate' |crontab -u root -"
- name: create cron jobs for logrotate
cron:
name: "rotate for java nginx logs"
minute: "0"
hour: "2"
job: "/usr/sbin/logrotate -f /etc/logrotate.d/java-nginx-logrotate"
become_user: "root"