Skip to content

Logrotate fails to start due to duplicate match #6847

@zwets

Description

@zwets

The logrotate service (at least on a monolith) fails to start with:

Apr 02 09:00:01 sprite logrotate[5747]: error: monolith:3 duplicate log entry for /home/cchq/www/monolith/log/commcare-hq.gunicorn.log
Apr 02 09:00:01 sprite logrotate[5747]: error: found error in file monolith, skipping
Apr 02 09:00:01 sprite systemd[1]: logrotate.service: Main process exited, code=exited, status=1/FAILURE

The issue is that in /etc/logrotate.d/monolith the glob "/home/cchq/www/monolith/log/*.log" matches commcare-hq.gunicorn.log, which is already matched in /etc/logrotate.d/commcare-hq-gunicorn.

Logrotate 3.21.0 introduced the option ignoreduplicates, which, if added in /etc/logrotate.d/commcare-hq-gunicorn, would resolve the issue provided that monolith ($environment) is alphabetically after commcare-hq-unicorn.

Either way, Ubuntu Jammy is on logrotate 3.19.0 so this doesn't help for the current release.

Possible fixes:

  • Quick & dirty: remove the commcare-hq-gunicorn logrotate config, so that commcare-hq.gunicorn.log is matched by the *.log glob; however note that it probably needs its copytruncate option

  • Quick: move the commcare-hq.gunicorn.log elsewhere, for instance to a subdirectory of the log directory

  • Clean: replace the *.log glob in the $environment logrotate config by the list of actual expected log file names; this is what I see:

        "/home/cchq/www/${environment}/log/celery*.log"
        "/home/cchq/www/${environment}/log/django.log"
        "/home/cchq/www/${environment}/log/formplayer-spring.log"
        "/home/cchq/www/${environment}/log/handle_*.log"
        "/home/cchq/www/${environment}/log/${environment}*.log"
        "/home/cchq/www/${environment}/log/pillowtop-*.log"
        "/home/cchq/www/${environment}/log/queue_schedule_instances.log"
        "/home/cchq/www/${environment}/log/run_*.log"
        "/home/cchq/www/${environment}/log/${branch?}-*.log"  # looks like branch prefix?
    
  • Proper: give each component its own logrotate config, matching its own log file pattern or, if that pattern is unpredictable, its own log subdirectory, so that a plain subdir/*.log will work for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions