rotating log file with newsyslog on freebsd

From WebHostingNeeds.com
Jump to: navigation, search

http://blogs.bizhat.com/bizhat/2005/11/04/freebsd-log-file-rotation-with-newsyslog/


NewSysLog


FreeBSD use /etc/newsyslog.conf to rotate log files.


Added

/home/backup/*.log                      644  4     *    @T00  B    /var/run/httpd.pid  30


To end of /etc/newsyslog.conf

/home/backup/*.log		location of log files
644				chmod 644 the log file
4				Keep 4 logs
*				Don't rotate log file on size of of log
@T00				Rotate log on midnight
B				Binary, else newsyslog will add time of log generation to log files.
/var/run/httpd.pid		PID of Apache
30				Is signal number of gracefull restart of apache


                   $D0     rotate every night at midnight (same as @T00)
                   $D23    rotate every day at 23:00 (same as @T23)
                   $W0D23  rotate every week on Sunday at 23:00
                   $W5D16  rotate every week on Friday at 16:00
                   $M1D0   rotate at the first day of every month at midnight
                           (i.e., the start of the day; same as @01T00)
                   $M5D6   rotate on every 5th day of month at 6:00 (same as
                           @05T06)


To rotate Apache Log Add

/var/log/httpd-access_log  644  7   100   24   B   /var/run/httpd.pid 30


sig_num, we use 30 to restart apache


You can find path to httpd.pid from httpd.conf

# grep PidFile /usr/local/etc/apache/httpd.conf
# PidFile: The file in which the server should record its process
PidFile /var/run/httpd.pid

http://www.onlamp.com/pub/a/bsd/2001/06/14/Big_Scary_Daemons.html