/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
    postrotate
        systemctl reload osstech-unicornidm
    endscript

    # You can use `copytruncate` instead of `delaycompress` if you want to avoid reloading due to some reasons such as system availability.
    # Logs written after copy and before truncate are lost with this option though.
    # copytruncate
}


/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
    nodelaycompress
    # 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
    nodelaycompress
    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
    endscript
}

