1

I'm looking at switching my log rotate setup to rotate logs hourly instead of daily. I think I've got the config ready to go but wanted to check whether the config would trigger a reload/restart of the process with the postrotate options?

I'm running this on ubuntu 16.04 and have copied my config from /etc/cron.daily to /etc/cron.hourly ready to go

Here's my config here from the logrotate.d/nginx file:

/var/log/nginx/*/*.log {
    hourly
    missingok
    rotate 720
    compress
    delaycompress
    notifempty
    create 640 nginx adm
    sharedscripts
    postrotate
            if [ -f /var/run/nginx.pid ]; then
                    kill -USR1 `cat /var/run/nginx.pid`
            fi
    endscript
}

If this does kill the process, is there a way around this step?

3

The command you can see:

 kill -USR1 `cat /var/run/nginx.pid`

does not actually kill the process.

Instead, kill sends a specific signal "USR1" which for nginx has a specific meaning and tells the nginx master process to reopen it's log files.
This effectively means that nginx starts writing to the new log files.

With some other programs that aren't designed as proper daemons and don't understand this signal this might be a problem and you would have to kill and restart them. That doesn't apply to NGinx.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.