puppet: Factor out cron job creation.

This commit is contained in:
Alex Vandiver 2024-04-19 11:52:04 -04:00 committed by Tim Abbott
parent c607594d11
commit 6e981c18d5
25 changed files with 102 additions and 208 deletions

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
* * * * * zulip /usr/lib/nagios/plugins/zulip_app_frontend/check_send_receive_time --site=https://$(/home/zulip/deployments/current/scripts/get-django-setting NAGIOS_BOT_HOST) >/dev/null

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
* * * * * zulip /usr/lib/nagios/plugins/zulip_zephyr_mirror/check_user_zephyr_mirror_liveness >/dev/null

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
0 8 * * * zulip /home/zulip/deployments/current/tools/fetch-contributor-data

View File

@ -62,11 +62,9 @@ class kandra::app_frontend {
# Each server does its own fetching of contributor data, since # Each server does its own fetching of contributor data, since
# we don't have a way to synchronize that among several servers. # we don't have a way to synchronize that among several servers.
file { '/etc/cron.d/fetch-contributor-data': zulip::cron { 'fetch-contributor-data':
ensure => file, hour => '8',
owner => 'root', minute => '0',
group => 'root', command => '/home/zulip/deployments/current/tools/fetch-contributor-data',
mode => '0644',
source => 'puppet:///modules/kandra/cron.d/fetch-contributor-data',
} }
} }

View File

@ -3,43 +3,29 @@ class kandra::prod_app_frontend_once {
include zulip::hooks::push_git_ref include zulip::hooks::push_git_ref
include zulip::hooks::zulip_notify include zulip::hooks::zulip_notify
file { '/etc/cron.d/update-first-visible-message-id': zulip::cron { 'update-first-visible-message-id':
ensure => file, hour => '7',
owner => 'root', minute => '*',
group => 'root', manage => 'calculate_first_visible_message_id --lookback-hours 30',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/calculate-first-visible-message-id',
} }
file { '/etc/cron.d/invoice-plans': zulip::cron { 'invoice-plans':
ensure => file, hour => '22',
owner => 'root', minute => '0',
group => 'root', }
mode => '0644', zulip::cron { 'downgrade-small-realms-behind-on-payments':
source => 'puppet:///modules/zulip/cron.d/invoice-plans', hour => '17',
minute => '0',
} }
file { '/etc/cron.d/downgrade-small-realms-behind-on-payments': zulip::cron { 'check_send_receive_time':
ensure => file, hour => '*',
owner => 'root', minute => '*',
group => 'root', command => '/usr/lib/nagios/plugins/zulip_app_frontend/check_send_receive_time --site=https://$(/home/zulip/deployments/current/scripts/get-django-setting NAGIOS_BOT_HOST) >/dev/null',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/downgrade-small-realms-behind-on-payments',
} }
zulip::cron { 'check_user_zephyr_mirror_liveness':
file { '/etc/cron.d/check_send_receive_time': hour => '*',
ensure => file, minute => '*',
owner => 'root', command => '/usr/lib/nagios/plugins/zulip_zephyr_mirror/check_user_zephyr_mirror_liveness >/dev/null',
group => 'root',
mode => '0644',
source => 'puppet:///modules/kandra/cron.d/check_send_receive_time',
}
file { '/etc/cron.d/check_user_zephyr_mirror_liveness':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/kandra/cron.d/check_user_zephyr_mirror_liveness',
} }
} }

View File

@ -1,10 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Daily cron job for retention policy - archives existing messages based on the policy
# and cleans expired entries from the archive.
0 6 * * * zulip /home/zulip/deployments/current/manage.py archive_messages >/dev/null
# Daily cron job for cleaning up old, unclaimed attachments and their corresponding files.
# Ideally should not run at the same time as the previous job, to avoid races.
0 5 * * * zulip /home/zulip/deployments/current/manage.py delete_old_unclaimed_attachments -f >/dev/null

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
0 7 * * * zulip /home/zulip/deployments/current/manage.py calculate_first_visible_message_id --lookback-hours 30

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
30 * * * * zulip /home/zulip/deployments/current/manage.py check_analytics_state

View File

@ -1,4 +0,0 @@
MAILTO=root
# Clear all expired Django sessions at 10:22 PM every day.
22 22 * * * zulip cd /home/zulip/deployments/current && ./manage.py clearsessions

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
0 17 * * * zulip /home/zulip/deployments/current/manage.py downgrade_small_realms_behind_on_payments

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
17 * * * * zulip /home/zulip/deployments/current/manage.py fetch_tor_exit_nodes

View File

@ -1,5 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
0 22 * * * zulip /home/zulip/deployments/current/manage.py invoice_plans

View File

@ -1,3 +0,0 @@
PATH=/bin:/usr/bin:/usr/local/bin
0 2 * * * postgres /usr/local/bin/pg_backup_and_purge >/var/log/pg_backup_and_purge.log 2>&1

View File

@ -1,6 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Cron job to promote users to full members system group.
35 * * * * zulip /home/zulip/deployments/current/manage.py promote_new_full_members

View File

@ -1,7 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Cron job to restart the Zulip server weekly, with the goal of
# minimizing the impact of any memory leaks that we might grow.
0 6 * * 7 zulip /home/zulip/deployments/current/scripts/restart-server --fill-cache

View File

@ -1,4 +0,0 @@
MAILTO=root
# Send digest emails once a day. Time is in UTC.
0 18 * * * zulip cd /home/zulip/deployments/current && ./manage.py enqueue_digest_emails

View File

@ -1,6 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Cron job to send zulip update announcements hourly, if there are any.
47 * * * * zulip /home/zulip/deployments/current/manage.py send_zulip_update_announcements

View File

@ -1,6 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Cron job to soft deactivate long term idle users daily.
0 5 * * * zulip /home/zulip/deployments/current/manage.py soft_deactivate_users -d >/dev/null

View File

@ -1,6 +0,0 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=zulip
# Run update analytics tables every 5 minutes past the hour
5 * * * * zulip /home/zulip/deployments/current/manage.py update_analytics_counts

View File

@ -245,12 +245,8 @@ class zulip::app_frontend_base {
} }
# This cron job does nothing unless RATE_LIMIT_TOR_TOGETHER is enabled. # This cron job does nothing unless RATE_LIMIT_TOR_TOGETHER is enabled.
file { '/etc/cron.d/fetch-tor-exit-nodes': zulip::cron { 'fetch-tor-exit-nodes':
ensure => file, minute => '17',
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/fetch-tor-exit-nodes',
} }
# This was originally added with a typo in the name. # This was originally added with a typo in the name.
file { '/etc/cron.d/fetch-for-exit-nodes': file { '/etc/cron.d/fetch-for-exit-nodes':

View File

@ -21,67 +21,43 @@ class zulip::app_frontend_once {
notify => Service[$zulip::common::supervisor_service], notify => Service[$zulip::common::supervisor_service],
} }
file { '/etc/cron.d/send-digest-emails': # Every-hour
ensure => file, zulip::cron { 'update-analytics-counts':
owner => 'root', minute => '5',
group => 'root', }
mode => '0644', zulip::cron { 'check-analytics-state':
source => 'puppet:///modules/zulip/cron.d/send-digest-emails', minute => '30',
}
zulip::cron { 'promote-new-full-members':
minute => '35',
}
zulip::cron { 'send_zulip_update_announcements':
minute => '47',
} }
file { '/etc/cron.d/update-analytics-counts': # Daily
ensure => file, zulip::cron { 'soft-deactivate-users':
owner => 'root', hour => '5',
group => 'root', minute => '0',
mode => '0644', manage => 'soft_deactivate_users -d',
source => 'puppet:///modules/zulip/cron.d/update-analytics-counts', }
zulip::cron { 'delete-old-unclaimed-attachments':
hour => '5',
minute => '0',
manage => 'delete_old_unclaimed_attachments -f',
}
zulip::cron { 'archive-messages':
hour => '6',
minute => '0',
}
zulip::cron { 'send-digest-emails':
hour => '18',
minute => '0',
manage => 'enqueue_digest_emails',
}
zulip::cron { 'clearsessions':
hour => '22',
minute => '22',
} }
file { '/etc/cron.d/check-analytics-state':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/check-analytics-state',
}
file { '/etc/cron.d/soft-deactivate-users':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/soft-deactivate-users',
}
file { '/etc/cron.d/promote-new-full-members':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/promote-new-full-members',
}
file { '/etc/cron.d/archive-messages':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/archive-messages',
}
file { '/etc/cron.d/clearsessions':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/clearsessions',
}
file { '/etc/cron.d/send_zulip_update_announcements':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/cron.d/send_zulip_update_announcements',
}
} }

View File

@ -0,0 +1,25 @@
define zulip::cron(
String $minute,
String $hour = '*',
String $dow = '*',
String $user = 'zulip',
Optional[String] $command = undef,
Optional[String] $manage = undef,
) {
if $command != undef {
$run = $command
} elsif $manage != undef {
$run = "cd /home/zulip/deployments/current/ && ./manage.py ${manage} >/dev/null"
} else {
$underscores = regsubst($title, '-', '_', 'G')
$run = "cd /home/zulip/deployments/current/ && ./manage.py ${underscores} >/dev/null"
}
file { "/etc/cron.d/${title}":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('zulip/cron.template.erb'),
}
}

View File

@ -25,12 +25,11 @@ class zulip::postgresql_backups {
], ],
} }
file { '/etc/cron.d/pg_backup_and_purge': zulip::cron { 'pg_backup_and_purge':
ensure => present, hour => '2',
owner => 'root', minute => '0',
group => 'root', command => '/usr/local/bin/pg_backup_and_purge >/var/log/pg_backup_and_purge.log 2>&1',
mode => '0644', user => 'postgres',
source => 'puppet:///modules/zulip/cron.d/pg-backup-and-purge',
require => [ require => [
File['/var/log/pg_backup_and_purge.log'], File['/var/log/pg_backup_and_purge.log'],
File['/usr/local/bin/pg_backup_and_purge'], File['/usr/local/bin/pg_backup_and_purge'],

View File

@ -66,11 +66,10 @@ class zulip::profile::app_frontend {
} }
# Restart the server regularly to avoid potential memory leak problems. # Restart the server regularly to avoid potential memory leak problems.
file { '/etc/cron.d/restart-zulip': zulip::cron { 'restart-zulip':
ensure => file, hour => '6',
owner => 'root', minute => '0',
group => 'root', dow => '7',
mode => '0644', command => '/home/zulip/deployments/current/scripts/restart-server --fill-cache',
source => 'puppet:///modules/zulip/cron.d/restart-zulip',
} }
} }

View File

@ -0,0 +1,7 @@
MAILTO=zulip
PATH=/usr/local/bin:/usr/bin:/bin
SHELL=/bin/bash
USER=<%= @user %>
<%= @minute %> <%= @hour %> * * <%= @dow %> <%= @user %> <%= @run %>