3

I am using logrotated to rotate gunicorn access logs. This is my logrotated configuration

/opt/api/log/access.log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        killall -s USR1 gunicorn
    endscript
}

The logs get rotated correctly, compressed, and a new access.log gets created. However, gunicorn does not release a 'pointer' to the old log file, so the rotation doesn't actually free up disk space.

I can still see entries for it using lsof

If I do an initctl restart api , gunicorn will restart and the disk space is finally freed up.

How can I free up the disk space in a cleaner way than restarting the service?

bwbrowning
  • 6,200
  • 7
  • 31
  • 36
  • Did you get the solution? Can you share configuration file? – neel Apr 06 '16 at 06:19
  • The gunicorn bugfix for this was released in November (https://github.com/benoitc/gunicorn/releases/tag/19.4). If you are using a newer version of gunicorn you should not have this problem, if you still see it you should file a bug with gunicorn – bwbrowning Apr 07 '16 at 01:59
  • Can you share configuration file, I am unable to find it anywhere? – neel Apr 07 '16 at 02:06
  • 1
    [gunicorn documentation](http://docs.gunicorn.org/en/stable/deploy.html#logging) now recommends restart command: `kill -USR1 $(cat /var/run/gunicorn.pid)` – Matthew Hegarty Aug 28 '17 at 13:33

2 Answers2

3

Usually Linux processes accept a special signal to notify them about log file rotation. In this case you are sending the signal SIGUSR1 to to process all gunicorn processes on the system.

The questions are

  • Does such process exist in your running system

  • Does gunicorn process accept SIGUSR1 signal

According to gunicorn source code USR1 should indeed rotate the logs

... so I suspect maybe killall doesn't send the command to the right processes.

To find out this, check your process listing with ps. If you find gunicorn processes, modify workers/base.py to print a log entry to see if they receive the signal. Try send the signal by hand and if it works then it is logrotate configuration which does not somehow work.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
1

Answering my own question, it seems like I have hit this bug: https://github.com/benoitc/gunicorn/issues/627

There is a fix for it, but it has not made its way into a release yet.

bwbrowning
  • 6,200
  • 7
  • 31
  • 36