In my /etc/logrotate.d/nginx I saw,

/var/log/nginx/*.log {
        rotate 52
        create 640 nginx adm
                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`

The postrotate script looks like killing the nginx process, which does not make sense so I must be wrong.

What it is doing?


Nginx responds to the USR1 signal by reopening its log files.

The USR1 signal kills a program by default, but it's meant to be handled to do whatever the program finds useful. Each program defines what it does with USR1 and USR2; for Nginx, that's reopening the log files (for log rotation) and executing a new instance (for upgrades).

By convention, most daemons respond to the HUP signal by reloading their configuration file. Nginx follows this convention. The original intent of the HUP signal was to signal the end of a session to interactive process (modem hang up — the user's gone, there's no point in continuing), but that meaning doesn't apply to daemons.


The kill command generically sends POSIX signals to a process. The normal invocation sends SIGTERM, which asks a process to terminate. However, in your case the signal being sent is SIGUSR1 which in your case, asks nginx to recycle its log files.

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.