web.nginx.lograte.yml
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# logrotate web nginx
# 1. configure logrotate
# 2. configure crontab: crontab: 0 2 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
- hosts: web-nginx
vars:
logrotate_scripts:
- name: web-nginx-logrotate
paths:
- "/Data/logs/nginx/*.log"
- "/Data/logs/nginx/nginx-activity-yoho-cn/*.log"
- "/Data/logs/nginx/activity-yoho-cn/*.log"
options:
- daily
- dateext
- rotate 30
- olddir /Data/logs/nginx/backup
- notifempty
- compress
- sharedscripts
scripts:
postrotate: "[ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/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 web nginx logs"
minute: "0"
hour: "2"
job: "/usr/sbin/logrotate -f /etc/logrotate.d/web-nginx-logrotate"
become_user: "root"