title: gunicorn process holding reference to logrotated files causing disk space to run out
body: <p>i am using logrotate to rotate gunicorn access / error logs.</p>
  
  <pre><code>{
    su root root
    missingok
    compress
    dateext
    dateformat .%Y%m%d
    notifempty
    sharedscripts
    postrotate
        # Send USR1 signal to the gunicorn master, which will cause it to reopen log files.
        # http://docs.gunicorn.org/en/latest/deploy.html#logging
        /bin/kill -USR1 $(cat /var/run/xxxx/api.pid 2&gt;/dev/null) 2&gt; /dev/null || true
    endscript
  }
  </code></pre>
  
  <p>The logs gets rotated correctly and compressed, and a new log file is created.  however gunicorn does not release the pointer to the deleted log file, and continues to write to that log file.  because of this the file space on the disk is not released and log lines are lost.</p>
  
  <p>i can see the entries with lsof</p>
  
  <pre><code>gunicorn  22284           root    9w   REG  252,1 43263609     0 117968 /usr/cachelogic/log/gunicorn_unapi_access.log-20190410 (deleted)
  </code></pre>
  
  <p>if i restart gunicorn service, the file space is freed up and the process also writes logs to the new file.  but the old logs which were written to the deleted file are lost. </p>
  
  <p>i would like to solve the logrotate issue without restarting the service.  How to ensure that logs are being written to the new log file instead of the logrotated file, and the disk space is being released.</p>