158

I followed this link to change log-rotate configuration for RHEL 6

After I made the change to config file, what should I do to let this take effect?

Abhijeet Kasurde
  • 487
  • 3
  • 17
BufBills
  • 3,035
  • 7
  • 22
  • 20

4 Answers4

212

logrotate uses crontab to work. It's scheduled work, not a daemon, so no need to reload its configuration.
When the crontab executes logrotate, it will use your new config file automatically.
If you need to test your config you can also execute logrotate on your own with the command:

logrotate /etc/logrotate.d/your-logrotate-config

Or as mentioned in comments, identify the logrotate line in the output of the command crontab -l and execute the command line refer to slm's answer to have a precise cron.daily explanation

Kiwy
  • 9,415
  • 13
  • 49
  • 79
  • 2
    Just to add to your answer, the cron entry for `logrotate` is scheduled to run once a day. – Ketan Maheshwari Feb 20 '14 at 17:12
  • @Ketan, so, how can i make it affect right away? thanks – BufBills Feb 20 '14 at 17:17
  • Not sure. One possibility is to find the corresponding entry from crontab via `crontab -l` and execute it. – Ketan Maheshwari Feb 20 '14 at 17:27
  • 2
    If you want it to take effect immediately run the cron afterwords. – slm Feb 20 '14 at 17:29
  • You can also just run `logrotate` directly as mentioned in the answer. – goldilocks Feb 20 '14 at 17:31
  • `/you/config/file` can be misunderstood as a path to a particular config for some application's logs, such as `/etc/logrotate.d/foo`. This is usually wrong; only the main config should be used because others can inherit some values from the main one. – Nick Volynkin Feb 01 '16 at 06:06
  • 9
    `logrotate` has a `-d` option for testing (or "debugging"), I'd recommend running it at least once with that. – FrustratedWithFormsDesigner Feb 23 '17 at 16:52
  • 1
    A very common frustration is the new, required su directive `su root syslog`. Which brings logrotate to a halt when not added in. To top off people's frustration, when they add the directive, and then run (force) logrotate, it continues to spit out "`error: skipping "/var/log/syslog" because parent directory has insecure permissions (It's world writable or writable by group which is not "root" ...`" for 20 hrs after the config change, as if the the settings/process are cached!? If you are stuck there, chgrp on /var/log to root, run logrotate, chgrp back to syslog. It will clear up by next run – ppostma1 May 24 '17 at 16:16
53

Most of the logrotate setups I've seen on various distros runs out of the /etc/cron.daily. There's a shell script there aptly named logrotate.

Example

$ ls -l /etc/cron.daily/logrotate 
-rwxr-xr-x 1 root root 180 May 18  2011 /etc/cron.daily/logrotate

Manual run

If you want to make it run manually simply run the script as root:

$ sudo /etc/cron.daily/logrotate

If you take a look at a script that's typically there, it shows you how you can also run logrotate manually, by simply running logrotate + the path to its configuration file.

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
Francois
  • 207
  • 2
  • 9
slm
  • 363,520
  • 117
  • 767
  • 871
49

It should be automatic via cron. You can force it to test your changes.

For global logrotate:

sudo logrotate -v -f /etc/logrotate.conf

For a single conf file:

sudo logrotate -v -f /etc/logrotate.d/someapp.conf
maskeda
  • 590
  • 3
  • 5
  • 19
    `-f` for force rotation, there is also `-d` for debug, which is also Dry run, it will print everything it would have done but not actually do it. – ThorSummoner Feb 22 '16 at 23:37
7

On my CentOS 6.5 machine for setting up logrotatefor nginx I had to do this:

logrotate /etc/logrotate.d/nginx

And then I checked if logrotate taking care of my new nginx config like this:

cat /var/lib/logrotate.status

Edit : cat /var/lib/logrotate/status

Ahsan
  • 171
  • 2
  • 6