Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am moving all my server's log rotation tasks for logrotate. The server has several PHP-FPM pools, each of them configured with a separated error_log directive.

The logrotate recipe for the logs is fairly simple:

/var/log/php/*.log
{
        rotate 7
        daily
        missingok
        notifempty
        delaycompress
        compress
        dateext
        sharedscripts
        postrotate
                # Need for signaling the php-fpm process?
        endscript
}

Should I send some signal to php-fpm pools to catch the new handles for the error_log files (in postrotate script)? If yes, which signal?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

In addition to the normal signals, PHP-FPM recognizes two 'user-defined' signals: SIGUSR1 and SIGUSR2.

  • SIGUSR1 - will cycle the log files
  • SIGUSR2 - graceful reload of all workers + reload of fpm conf/binary

For log file rotation, SIGUSR1 would be well suited. With specific reference to your scenario, a sample logrotate config is detailed on this page. The signal is passed as follows:

kill -USR1 `cat /path/to/php-fpm.pid`

PHP-FPM signals are defined at: http://php-fpm.org/wiki/Documentation

share|improve this answer
    
Thanks for your answer! Can you confirm that SIGUSR1 is needed also to rotate the pools' logs? In the referred page, they discuss only about the php-fpm's main log that is apparently "always open" by the process. However, calling SIGUSR1 does not hurt... ;) –  Ville Mattila Nov 2 '12 at 9:03
    
With most setups, logrotate will move the old file and create a new one. If a process holds a file handle to the original file, it will continue to write to that file even though it has been moved (i.e. it will not use the new file). There are several solutions to this: a) use copytruncate - which will copy the file and truncate the original, so the file being written to is the truncated one b) send the logging process a signal to reload its log files c) pipe logs through an intermediate process which will deal with rotation. –  cyberx86 Nov 4 '12 at 4:15
    
There are a few additional possibilities that complicate things - PHP-FPM can pass errors back through to the web server (which will handle logging) or it can write the logs directly. In essence, if the logging process keeps its file handle to the log (which would be probable in most cases) then you should signal to it that it needs to reload the logs. –  cyberx86 Nov 4 '12 at 4:26
    
I see, thanks. I have configured the PHP-FPM pools to write the error_logs themselves. I will need to do some more research to confirm that SIGUSR1 really cycles pool logs too. If it does not, copytruncate might be the best way to go then. Maybe somewhere from PHP-FPM source I could find whether error_log handles are opened on request (no need for signaling) or if the handles are kept open always (signaling or copytruncate required). Let's see... –  Ville Mattila Nov 4 '12 at 15:07

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.