I've noticed that one of our servers starts returning errors just after logrotate runs, i.e. in nginx error log I can see:
[error] 8501#0: *118126869 recv() failed (104: Connection reset by
peer) while reading response header from upstream, client: xxx.yyy.zz.ww, server: www.test.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9011", host: "www.test.com"
I have tried adding a postrotate action that would make the php reload gracefully but the error is still happening, our current logrotate is as follows:
/var/log/php5-fpm.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root root
postrotate
[ ! -f /var/run/php5-fpm.pid ] || kill -USR2 `cat /var/run/php5-fpm.pid`
endscript
}
PHP config is as follows:
[www-9011]
user = www-data
group = www-data
listen = 127.0.0.1:9011
listen.backlog = 65535
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 10s;
pm.max_requests = 500
rlimit_files = 16384
chdir = /
catch_workers_output = no
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
We're running on ubuntu 12.04 and php 5.3.10
Best Answer
Send USR1 instead
https://github.com/php/php-src/blob/b7a7b1a624c97945c0aaa49d46ae996fc0bdb6bc/sapi/fpm/fpm/fpm_events.c#L94
The source code shows this is specifially for rotating files, I know Ubuntu 14.04 didn't handle fpm reloads (USR2) very well, I assume its the same for older versions too.
So change to
to simply rotate the logs