问题原文
原帖链接 · Cliff Ennis · CC BY-SA 3.0
I have a logrotate script that is structured to rotate logs collected by syslog. Part of that script is to reload the syslog process. The problem is that the syslog reload runs for each matching log file it rotates and there are about 100 of them. How can I set up the logrotate script to reload the syslog process only once, after all individual logs have been processed?
/logs/* {
daily
rotate 7
compress
postrotate
/etc/init.d/syslog-ng reload 2>/dev/null
endscript
}
社区高分解答
原帖链接 · zfou · CC BY-SA 3.0
Use sharedscripts:
Normally logrotate runs the postrotate script every time it rotates a log. This is also true for multiple logs that use the same configuration block. For example, a web server configuration block that refers to both the access log and the error log will, if it rotates both, run the postrotate script twice (once for each file rotated). If both files are rotated, the web server is restarted twice.
To keep logrotate from running that script for every log, you can include the following command:
sharedscripts This command tells logrotate to check all the logs for that configuration block before running the postrotate script. If one or both of the logs is rotated, the postrotate script runs only once. If none of the logs is rotated, the postrotate script doesn’t run.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
