Skip to content

SUP-2404 Migrate from cron to systemd timers #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ spec/spec_helper.rb:
coverage_report: true
spec/default_facts.yml:
extra_facts:
pe_server_version: 2018.1.0
memory:
"system":
"total": "16.00 GiB"
"total_bytes": 17179869184
processors:
"count": 8
spec/default_facts.yml:
extra_facts:
pe_databases:
have_systemd: true
pe_postgresql_info:
installed_server_version: 9.6
pe_server_version: 2018.1.0
installed_server_version: 11
pe_server_version: 2019.8.6
memory:
system:
total: 16.00 GiB
Expand Down
43 changes: 0 additions & 43 deletions files/vacuum_full_tables.sh

This file was deleted.

11 changes: 11 additions & 0 deletions lib/facter/pe_databases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Facter.add(:pe_databases, type: :aggregate) do
confine kernel: 'Linux'

chunk(:have_systemd) do
if Puppet::FileSystem.exist?('/proc/1/comm') && Puppet::FileSystem.read('/proc/1/comm').include?('systemd')
{ have_systemd: true }
else
{ have_systemd: false }
end
end
end
41 changes: 41 additions & 0 deletions manifests/collect.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Create systemd units for repacking a given database type
define pe_databases::collect (
String $database_type = $title,
String $command = undef,
Boolean $disable_maintenance = false,
String $on_cal = undef,
) {

Service {
notify => Exec['pe_databases_daemon_reload'],
}
File {
notify => Exec['pe_databases_daemon_reload'],
}

$ensure_service = $disable_maintenance ? {
true => stopped,
default => running,
}

$ensure_file = $disable_maintenance ? {
true => absent,
default => present
}

file {"/etc/systemd/system/pe_databases-${database_type}.service":
ensure => $ensure_file,
content => epp('pe_databases/service.epp', { 'tables' => $database_type, 'command' => $command }),
}
file {"/etc/systemd/system/pe_databases-${database_type}.timer":
ensure => $ensure_file,
content => epp('pe_databases/timer.epp', { 'tables' => $database_type, 'on_cal' => $on_cal }),
}

service { "pe_databases-${database_type}.service": }
service { "pe_databases-${database_type}.timer":
ensure => $ensure_service,
enable => ! $disable_maintenance,
subscribe => File["/etc/systemd/system/pe_databases-${database_type}.timer"],
}
}
50 changes: 31 additions & 19 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @summary Tuning, maintenance, and backups for PE PostgreSQL.

class pe_databases (
Boolean $manage_database_backups = true,
Boolean $manage_database_backups = false,
Boolean $manage_database_maintenance = true,
Boolean $manage_postgresql_settings = true,
Boolean $manage_table_settings = true,
Expand All @@ -21,27 +21,39 @@
mode => '0755',
}

if $manage_database_maintenance {
include pe_databases::maintenance
exec { 'pe_databases_daemon_reload':
command => 'systemctl daemon-reload',
path => ['/bin', '/usr/bin'],
refreshonly => true,
}

# Do not manage postgresql_settings in 2018.1.0 or newer.
if $manage_postgresql_settings and (versioncmp('2018.1.0', $facts['pe_server_version']) > 0) {
include pe_databases::postgresql_settings
class { 'pe_databases::postgresql_settings::table_settings' :
manage_reports_autovacuum_cost_delay => $pe_databases::postgresql_settings::manage_reports_autovacuum_cost_delay,
factsets_autovacuum_vacuum_scale_factor => $pe_databases::postgresql_settings::factsets_autovacuum_vacuum_scale_factor,
reports_autovacuum_vacuum_scale_factor => $pe_databases::postgresql_settings::reports_autovacuum_vacuum_scale_factor,
require => Class['pe_databases::postgresql_settings'],
if $facts.dig('pe_databases', 'have_systemd') {
if $manage_database_maintenance and (versioncmp('2019.0.2', $facts['pe_server_version']) <= 0) {
class {'pe_databases::pg_repack':
disable_maintenance => lookup('pe_databases::maintenance::disable_maintenance', {'default_value' => false}),
}
if $manage_table_settings {
# This is to provide for situations, like PE XL,
# where the pe-puppetdb database does not exist on the PostgreSQL system being tuned.
# In PE XL, the Master and Replica run PostgreSQL for all databases *except* for pe-puppetdb.
include pe_databases::postgresql_settings::table_settings
}

if $manage_database_backups {
include pe_databases::backup
}
}
else {
notify { 'pe_databases_version_warn':
message => 'This module only supports PE 2019.0.2 and later',
loglevel => warning,
}
}
} elsif $manage_table_settings {
# This is to provide for situations, like PE XL,
# where the pe-puppetdb database does not exist on the PostgreSQL system being tuned.
# In PE XL, the Master and Replica run PostgreSQL for all databases *except* for pe-puppetdb.
include pe_databases::postgresql_settings::table_settings
}

if $manage_database_backups {
include pe_databases::backup
else {
notify { 'pe_databases_systemd_warn':
message => 'This module only works with systemd as the provider',
loglevel => warning,
}
}
}
31 changes: 0 additions & 31 deletions manifests/maintenance.pp

This file was deleted.

94 changes: 0 additions & 94 deletions manifests/maintenance/pg_repack.pp

This file was deleted.

68 changes: 0 additions & 68 deletions manifests/maintenance/vacuum_full.pp

This file was deleted.

Loading