/opt/osstech/var/log/unicornidm/unicornidm.log
{
    # ---------- common settings ----------
    # It seems that we cannot declare common settings out of each log file block because options declared as such affect other services' logrotate behaviours.
    olddir old
    missingok
    # not-if-empty: do not rotate if the file is empty
    notifempty
    compress
    # -------------------------------------

    # 27 * 7 = about half year
    rotate 27
    weekly
    # Delay compression of the youngest rotated log file because
    # old processes (uWSGI workers) may continue to write logs to it until gracefully restarted.
    delaycompress

    # This log file is reopend by Python logging.handlers.WatchedFileHandler
    # when a new log message is arrived after rotation.
}


/opt/osstech/var/log/unicornidm/uwsgi.log
{
    # ---------- common settings ----------
    olddir old
    missingok
    # not-if-empty: do not rotate if the file is empty
    notifempty
    compress
    # create log files immediately after rotation and before postrotate script execution
    create
    # -------------------------------------

    rotate 27
    weekly
    delaycompress
    # uWSGI's touch-logreopen option
    # http://uwsgi-docs.readthedocs.io/en/latest/Options.html#touch-logreopen
    postrotate
        touch /opt/osstech/var/log/unicornidm/uwsgi.reopentrigger
    endscript
}


/opt/osstech/var/log/unicornidm/mongod.log
{
    # ---------- common settings ----------
    olddir old
    missingok
    # not-if-empty: do not rotate if the file is empty
    notifempty
    compress
    # create log files immediately after rotation and before postrotate script execution
    create
    # -------------------------------------

    rotate 27
    weekly
    delaycompress
    postrotate
        if [ -f /var/opt/osstech/lib/unicornidm/mongod.pid ] && ps --pid `cat /var/opt/osstech/lib/unicornidm/mongod.pid` > /dev/null; then
            # https://docs.mongodb.com/manual/tutorial/rotate-log-files/#forcing-a-log-rotation-with-sigusr1
            # `|| true` is to avoid error reports when mongod is stopping at the same time.
            kill -USR1 `cat /var/opt/osstech/lib/unicornidm/mongod.pid` || true
        fi
    endscript
}
