Search:

PmWiki

pmwiki.org

edit SideBar

Main / Logrotate

Linux Daemon

When creating a service control script, standard practice is to redirect any terminal output to a log file instead.

LOGFILE=/var/log/daemon.log

daemon &> $LOGFILE

Note the behavior with logrotate changes depending on if you use > or >>.

Critical Configuration Knowledge

Unless you restart the application when the log is rotated, keep in mind that the name change from daemon.log to daemon.log.1 is ignored by the app and it will keep writing to daemon.log.1 after a rotate. Note that using the copytruncate option isn't exactly a fix because the applications keeps writing to the same file with the same offset (https://serverfault.com/questions/221337/logrotate-successful-original-file-goes-back-to-original-size) so it appears that the file size on disk keeps growing even after being zeroed out. So you need to be sure that if you are opening the file for write within your application, you need O_APPEND set or use >> for a redirect.

On Debian, you can do a manual logrotate with /usr/sbin/logrotate -f /etc/logrotate.d/<daemonname> just on your one log or /usr/sbin/logrotate -f /etc/logrotate.conf for everything.

Using the -d option for debug is also a dry-run, meaning it won't actually rotate even if it's supposed to.

Notes on shell I/O redirects

&> will redirect both stdout and stderr
2>/dev/null will get rid of stderr


Page last modified on September 28, 2023, at 05:48 PM