I have an all-default Ubuntu VPS machine with Nginx, for a few light WordPress sites with say up to 5 plugins, 10 webpages, 20 images each.
So far I cleaned all default logs (or at least some of them) automatically, in the following way with crontab
:
0 0 * * 0 find /var/mail/* /var/log/* -type f -exec truncate -s 0 {} \;
I understood some consider it better to use logrotate that will achieve basically similar targets and will cover more logs (or potentially more logs) and is communal and well maintained. I thus prefer to use logrotate because of that.
I really have no special desires from logrotate, I assume I should be fine with its default, basic configuration. I thus asked myself how should I configure logrotate in crontab
in a default, shortest way.
I found this tutorial and some others but they all feel to me as diving a bit deeper than what I need - an Out Of Box conf for a VPS machine with Ubuntu-Nginx and WordPress.
If I understand correct from what I've read, this should be enough:
0 * * * * /usr/sbin/logrotate
If I'd like to have a state
file (a log for logrotate which as I assume, is not obligatory) I could do it this way:
0 * * * * /usr/sbin/logrotate home/user/logrotate.conf --state /home/user/logrotate-state
Is this the most basic, common configuration one could have for logrotate and was I wrong in anything in any assumption here?
Logrotate in Ubuntu is already configured to operate daily, and to log it's actions to syslog (which it also rotates).
Logrotate's existing cron job is located at /etc/cron.daily/logrotate
Manual configuration is not required. You can, of course, change the default setup if you wish - few do.
Logrotate has it's roots the good-old-days when disk space was much more expensive, an easy method of limiting the space used by logfiles. Logfiles tend to decrease in value over time at varying rates, hence the ability to customize the rotation and deletion of each.