From 3ab9b31d2fb5f5a8a63bdfcb5ff3073dd0b2a52d Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Mon, 19 Oct 2020 20:33:42 -0700 Subject: [PATCH] puppet: Purge all un-managed supervisor configuration files. Relying on `defined(Class['...'])` makes the class sensitive to resource evaluation ordering, and thus brittle. It is also only functional for a single service (thumbor). Generalize by using `purge => true` for the directory to automatically remove all un-managed files. This is more general than the previous form, and may result in additional not-managed services being removed. --- .../zulip/files/supervisor/supervisord.conf | 2 +- puppet/zulip/manifests/common.pp | 5 +- puppet/zulip/manifests/supervisor.pp | 50 +++++++++++-------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/puppet/zulip/files/supervisor/supervisord.conf b/puppet/zulip/files/supervisor/supervisord.conf index b010b718a8..52bdd0f005 100644 --- a/puppet/zulip/files/supervisor/supervisord.conf +++ b/puppet/zulip/files/supervisor/supervisord.conf @@ -27,4 +27,4 @@ serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket ; include files themselves. [include] -files = /etc/supervisor/conf.d/*.conf +files = /etc/supervisor/conf.d/*.conf /etc/supervisor/conf.d/zulip/*.conf diff --git a/puppet/zulip/manifests/common.pp b/puppet/zulip/manifests/common.pp index e5516dbc44..f64c039bc6 100644 --- a/puppet/zulip/manifests/common.pp +++ b/puppet/zulip/manifests/common.pp @@ -5,7 +5,7 @@ class zulip::common { $nagios_plugins = 'monitoring-plugins-basic' $nagios_plugins_dir = '/usr/lib/nagios/plugins' $nginx = 'nginx-full' - $supervisor_conf_dir = '/etc/supervisor/conf.d' + $supervisor_system_conf_dir = '/etc/supervisor/conf.d' $supervisor_conf_file = '/etc/supervisor/supervisord.conf' $supervisor_service = 'supervisor' $supervisor_start = '/etc/init.d/supervisor start' @@ -15,7 +15,7 @@ class zulip::common { $nagios_plugins = 'nagios-plugins' $nagios_plugins_dir = '/usr/lib64/nagios/plugins' $nginx = 'nginx' - $supervisor_conf_dir = '/etc/supervisord.d/conf.d' + $supervisor_system_conf_dir = '/etc/supervisord.d/conf.d' $supervisor_conf_file = '/etc/supervisord.conf' $supervisor_service = 'supervisord' $supervisor_start = 'systemctl start supervisord' @@ -25,4 +25,5 @@ class zulip::common { fail('osfamily not supported') } } + $supervisor_conf_dir = "${supervisor_system_conf_dir}/zulip" } diff --git a/puppet/zulip/manifests/supervisor.pp b/puppet/zulip/manifests/supervisor.pp index f95a1a1656..00b1b42465 100644 --- a/puppet/zulip/manifests/supervisor.pp +++ b/puppet/zulip/manifests/supervisor.pp @@ -1,15 +1,37 @@ class zulip::supervisor { + $supervisor_service = $zulip::common::supervisor_service + package { 'supervisor': ensure => 'installed' } - if $::osfamily == 'redhat' { - file { $zulip::common::supervisor_conf_dir: - ensure => 'directory', - owner => 'root', - group => 'root', - } + file { $zulip::common::supervisor_system_conf_dir: + ensure => 'directory', + require => Package['supervisor'], + owner => 'root', + group => 'root', } - $supervisor_service = $zulip::common::supervisor_service + file { $zulip::common::supervisor_conf_dir: + ensure => 'directory', + require => Package['supervisor'], + owner => 'root', + group => 'root', + purge => true, + recurse => true, + notify => Service[$supervisor_service], + } + + # These files were moved from /etc/supervisor/conf.d/ into a zulip/ + # subdirectory in 2020-10 in version 4.0; these lines can be removed + # in Zulip version 5.0 and later. + file { [ + "${zulip::common::supervisor_system_conf_dir}/cron.conf", + "${zulip::common::supervisor_system_conf_dir}/nginx.conf", + "${zulip::common::supervisor_system_conf_dir}/thumbor.conf", + "${zulip::common::supervisor_system_conf_dir}/zulip_db.conf", + "${zulip::common::supervisor_system_conf_dir}/zulip.conf", + ]: + ensure => absent, + } # In the dockervoyager environment, we don't want/need supervisor to be started/stopped # /bin/true is used as a decoy command, to maintain compatibility with other @@ -81,18 +103,4 @@ class zulip::supervisor { source => 'puppet:///modules/zulip/supervisor/supervisord.conf', notify => Exec['supervisor-restart'], } - - # We need a block here to handle deleting the old thumbor.conf file, - # unless zulip::thumbor has been enabled. It would be cleaner - # to use tidy instead of exec here, but notify is broken with it - # (https://tickets.puppetlabs.com/browse/PUP-6021) - # so we wouldn't be able to notify the supervisor service. - $thumbor_enabled = defined(Class['zulip::thumbor']) - if !$thumbor_enabled { - exec { 'cleanup_thumbor_supervisor_conf_file': - command => "rm ${zulip::common::supervisor_conf_dir}/thumbor.conf", - onlyif => "test -e ${zulip::common::supervisor_conf_dir}/thumbor.conf", - notify => Service[$zulip::common::supervisor_service], - } - } }