Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

/var/log/nginx/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 nginx adm
        sharedscripts
        postrotate
                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

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

What it is doing?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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