diff --git a/docs/production/deployment.md b/docs/production/deployment.md index f761c03a06..a036990c02 100644 --- a/docs/production/deployment.md +++ b/docs/production/deployment.md @@ -791,6 +791,11 @@ Override the default uwsgi backlog of 128 connections. Override the default `uwsgi` (Django) process count of 6 on hosts with more than 3.5GiB of RAM, 4 on hosts with less. +#### `access_log_retention_days` + +Number of days of access logs to keep, for both nginx and the application. +Defaults to 14 days. + ### `[postfix]` #### `mailname` diff --git a/puppet/zulip/manifests/nginx.pp b/puppet/zulip/manifests/nginx.pp index d2743fb2f6..d6115c8cf1 100644 --- a/puppet/zulip/manifests/nginx.pp +++ b/puppet/zulip/manifests/nginx.pp @@ -76,13 +76,14 @@ class zulip::nginx { group => 'adm', mode => '0750', } + $access_log_retention_days = zulipconf('application_server','access_log_retention_days', 14) file { '/etc/logrotate.d/nginx': ensure => file, require => Package[$zulip::common::nginx], owner => 'root', group => 'root', mode => '0644', - source => 'puppet:///modules/zulip/logrotate/nginx', + content => template('zulip/logrotate/nginx.template.erb'), } package { 'certbot': ensure => installed, diff --git a/puppet/zulip/manifests/profile/app_frontend.pp b/puppet/zulip/manifests/profile/app_frontend.pp index 42242a4fff..e82ff71d0c 100644 --- a/puppet/zulip/manifests/profile/app_frontend.pp +++ b/puppet/zulip/manifests/profile/app_frontend.pp @@ -23,12 +23,13 @@ class zulip::profile::app_frontend { content => template('zulip/nginx/zulip-enterprise.template.erb'), notify => Service['nginx'], } + $access_log_retention_days = zulipconf('application_server','access_log_retention_days', 14) file { '/etc/logrotate.d/zulip': - ensure => file, - owner => 'root', - group => 'root', - mode => '0644', - source => 'puppet:///modules/zulip/logrotate/zulip', + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => template('zulip/logrotate/zulip.template.erb'), } file { '/etc/nginx/sites-enabled/zulip-enterprise': ensure => link, diff --git a/puppet/zulip/files/logrotate/nginx b/puppet/zulip/templates/logrotate/nginx.template.erb similarity index 88% rename from puppet/zulip/files/logrotate/nginx rename to puppet/zulip/templates/logrotate/nginx.template.erb index ad1d97af54..052955a529 100644 --- a/puppet/zulip/files/logrotate/nginx +++ b/puppet/zulip/templates/logrotate/nginx.template.erb @@ -1,7 +1,7 @@ /var/log/nginx/*.log { daily missingok - rotate 14 + rotate <%= @access_log_retention_days %> compress delaycompress notifempty diff --git a/puppet/zulip/files/logrotate/zulip b/puppet/zulip/templates/logrotate/zulip.template.erb similarity index 94% rename from puppet/zulip/files/logrotate/zulip rename to puppet/zulip/templates/logrotate/zulip.template.erb index 2858ef1b50..0248291cca 100644 --- a/puppet/zulip/files/logrotate/zulip +++ b/puppet/zulip/templates/logrotate/zulip.template.erb @@ -32,8 +32,8 @@ /var/log/zulip/server.log { missingok - rotate 10 - size 500M + rotate <%= @access_log_retention_days %> + daily compress delaycompress notifempty diff --git a/scripts/log-search b/scripts/log-search index 2e8297f018..745b23ee23 100755 --- a/scripts/log-search +++ b/scripts/log-search @@ -25,18 +25,31 @@ from typing import Protocol from django.conf import settings -from scripts.lib.zulip_tools import BOLD, CYAN, ENDC, FAIL, GRAY, OKBLUE +from scripts.lib.zulip_tools import ( + BOLD, + CYAN, + ENDC, + FAIL, + GRAY, + OKBLUE, + get_config, + get_config_file, +) def parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(description="Search logfiles, ignoring commonly-fetched URLs.") log_selection = parser.add_argument_group("File selection") log_selection_options = log_selection.add_mutually_exclusive_group() + access_log_retention_days = int( + get_config(get_config_file(), "application_server", "access_log_retention_days", "14") + ) log_selection_options.add_argument( "--log-files", "-n", help="Number of log files to search", - choices=range(1, 16), + choices=range(1, access_log_retention_days + 2), + metavar=f"[1-{access_log_retention_days+1}]", type=int, ) log_selection_options.add_argument(