Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does logrotate depend on cron?

Tags:

cron

logrotate

in the logrotate manpage, they say:

"Normally, logrotate is run as a daily cron job".

Does that mean that logrotate uses cron (or is executed by cron)? If so, does that mean that if I don't configure a cron job via crontab (for instance), logrotate will not work?

like image 635
ling Avatar asked Nov 12 '14 13:11

ling


People also ask

Where is logrotate in cron?

The system runs logrotate on a schedule, usually daily. On most distributions, the script that runs logrotate daily is located at /etc/cron. daily/logrotate .

At what time does logrotate run?

By default, the installation of logrotate creates a crontab file inside /etc/cron. daily named logrotate. As it is the case with the other crontab files inside this directory, it will be executed daily starting at 6:25 am if anacron is not installed.

Does logrotate run as root?

logrotate succeeds when manually run as root, but fails with "Read-only file system" when run by logrotate. service.

How often does logrotate run?

Normally, logrotate is run as a daily cron job. It will not modify a log more than once in one day unless the criterion for that log is based on the log's size and logrotate is being run more than once each day, or unless the -f or --force option is used. Any number of config files may be given on the command line.


2 Answers

You CAN run logrotate manually WITHOUT cron.

logrotate <configuration file>

However if you want to run logrotate on a scheduled basis, yes you will need cron.

Your package manager should create a default schedule in /etc/cron.daily/logrotate that runs logrotate with the default /etc/logrotate.conf configuration. You can also place your custom configurations in /etc/logrotate.d/ since the default configuration has a line that include all configurations in this directory.

include /etc/logrotate.d

If you want to run logrotate with a custom schedule, you can place your cron job in /etc/cron.d/.

For example, this would trigger logrotate using /etc/custom-logrotate.conf configuration every day at two o'clock.

0 2 * * * root /usr/sbin/logrotate /etc/custom-logrotate.conf

Checkout crontab guru if you need help with cron expression.

like image 200
Victor Wong Avatar answered Oct 30 '22 13:10

Victor Wong


Yes, normaly, cron executes logrotate on a daily base. I depends on your linux distro, but the normal is to have cron running it.

You can check if have the file /etc/cron.daily/logrotate If thats the case, you distro uses cron to run logrotate.

If you are using docker, this can bring some problem, currently cron doesn't run inside a container.

like image 23
João Luís Avatar answered Oct 30 '22 14:10

João Luís