Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forever log and logrotate

I use forever to launch my nodeJs server and I choose the log file :

forever -l /home/api/log/api_output.log start server.js

I use logrotate to move logfile every day (like advise here : NodeJS/Forever archive logs), after one day my directory is like this :

-rw-r--r-- 1 root root 0 avril 18 12:00 api_output.log

-rw-r--r-- 1 root root 95492 avril 18 12:01 api_output.log-20140418

So, rotation is working, but the logs messages are now written in api_output.log-20140418, instead of api_output.log

Maybe somebody can help me ?

like image 640
igor Avatar asked Apr 18 '14 10:04

igor


People also ask

What is Copytruncate in logrotate?

copytruncate : Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever.

What is logrotate used for?

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. Normally, logrotate is run as a daily cron job.

How do I logrotate var log messages?

The command /usr/bin/chattr -a is run to remove the append-only attribute from /var/log/messages. The endscript command marks the end of the prerotate portion of this script. The next line, postrotate, specifies the following commands are to be run on /var/log/messages after the file has been rotated by logrotate.

How do I run logrotate per hour?

Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly. As pointed out by yellow1pl the solution is to copy the file /etc/cron. daily/logrotate into the /etc/cron.


1 Answers

I forgot copytruncate option in my config file, now it's working :

/etc/logrotate.d/api :

/home/api/log/api_output.log {
  #size 50k
  daily
  dateext
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  #create 644 root
  copytruncate  
}
like image 156
igor Avatar answered Oct 13 '22 15:10

igor