Preferred method to reopen the log with logrotate

Maxim Dounin mdounin at mdounin.ru
Wed Jun 1 16:42:08 UTC 2022


Hello!

On Wed, Jun 01, 2022 at 08:07:13AM -0700, Roger Fischer wrote:

> Hello,
> 
> there seem to be two methods to tell nginx to re-open the log 
> file after the file was rotated (we use logrotate).
> 
> 1) nginx -s reopen
> 
> 2) kill -USR1
> 
> Which is the preferred method, and why.
> 
> I am asking because we have seen nginx -s reopen failing because 
> of a transient issue with the configuration. According to the 
> man page reopen should be the same as SIGUSR1, but the error we 
> saw implies that the config was reloaded (ie SIGHUP).

Preferred method is to use kill, it is more effective and has less 
intermediate operations (such as parsing the configuration to find 
out path to the pid file) which can fail.

The "nginx -s ..." command was introduced to support Windows, 
where there is no kill.  On Unix systems, it is essentially 
equivalent to "kill <signal> /path/to/nginx.pid", except it 
accepts user-friendly signal names and parses nginx configuration 
to find out path to the pid file.  It might be easier to use in 
user-interactive scenarios, though it might be costly as it parses 
nginx configuration, and it might not work at all in some specific 
cases (such as incorrect on-disk configuration you've mentioned, 
or on-disk configuration not compatible with on-disk nginx 
binary).  As such, it is not generally recommended to use the 
"nginx -s ..." form on Unix, especially in automatic tasks such as 
log rotation.

-- 
Maxim Dounin
http://mdounin.ru/



More information about the nginx mailing list