Skip to content

logrotate

With thanks to Robert, this is a solution for the log problems of ask, using the logrotate program.

the problem

Ask logs to logfile, but especially Scheduler.log frequently becomes so large (231) that some functions break in the Scheduler agent. Rather then fixing the problem, meaning recompilation and much more bother, we use this solution.

the solution

Use logrotate to break up and recycle the logfiles. Not only does this fix the problem, it also keeps the files system cleaner than the old solution.

You need a configuration file for logrotate to work, with the files that you want to rotate and the options. On ask.almende.com i choose for /data/ask/logrotate/ask.conf :

/data/ask/logrotate/ask.conf
"/data/ask/install_mar17_2006/hans/install/var/log/*/*.log" {
       daily
       copytruncate
       rotate 21
       compress
}

"/data/ask/install_mar17_2006/iris/install/var/log/*/*.log" {
       daily
       copytruncate
       rotate 21
       compress
}

As you see you can use wildcard, but be careful because logrotate will also truncate you precious source files or executables. So it would be good practice to do :

list logs
ls /data/ask/install_mar17_2006/hans/install/var/log/*/*.log

This will neatly show what files are involved. The options are rather descriptive, copytruncate truncates the file and copies it to logfile.1 and compress also zips it. The file just stays open after truncation, so ask won't crash. rotate means it will count up to 21. So it renames logfile to logfile.1, logfile.1 logfile.2 ... etc and remove logfile.21 You can test the setup with the command

test config file
logrotate -s /data/ask/logrotate/status /data/ask/logrotate/ask.conf

It won't rotate yet, because you said daily but you can view the status file to see if it worked. If you really want to know if it works, fiddle with the dates in the status file (set them a day back) and rerun the command. If you are satisfied, put the command in a crontab (this example runs at 02:00)

crontab entry
0 2 * * * /usr/sbin/logrotate -s /data/ask/logrotate/status /data/ask/logrotate/ask.conf > /dev/null