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.
This commit is contained in:
Alex Vandiver
2020-10-19 20:33:42 -07:00
committed by Tim Abbott
parent 4cca1a2076
commit 3ab9b31d2f
3 changed files with 33 additions and 24 deletions

View File

@@ -27,4 +27,4 @@ serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; include files themselves. ; include files themselves.
[include] [include]
files = /etc/supervisor/conf.d/*.conf files = /etc/supervisor/conf.d/*.conf /etc/supervisor/conf.d/zulip/*.conf

View File

@@ -5,7 +5,7 @@ class zulip::common {
$nagios_plugins = 'monitoring-plugins-basic' $nagios_plugins = 'monitoring-plugins-basic'
$nagios_plugins_dir = '/usr/lib/nagios/plugins' $nagios_plugins_dir = '/usr/lib/nagios/plugins'
$nginx = 'nginx-full' $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_conf_file = '/etc/supervisor/supervisord.conf'
$supervisor_service = 'supervisor' $supervisor_service = 'supervisor'
$supervisor_start = '/etc/init.d/supervisor start' $supervisor_start = '/etc/init.d/supervisor start'
@@ -15,7 +15,7 @@ class zulip::common {
$nagios_plugins = 'nagios-plugins' $nagios_plugins = 'nagios-plugins'
$nagios_plugins_dir = '/usr/lib64/nagios/plugins' $nagios_plugins_dir = '/usr/lib64/nagios/plugins'
$nginx = 'nginx' $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_conf_file = '/etc/supervisord.conf'
$supervisor_service = 'supervisord' $supervisor_service = 'supervisord'
$supervisor_start = 'systemctl start supervisord' $supervisor_start = 'systemctl start supervisord'
@@ -25,4 +25,5 @@ class zulip::common {
fail('osfamily not supported') fail('osfamily not supported')
} }
} }
$supervisor_conf_dir = "${supervisor_system_conf_dir}/zulip"
} }

View File

@@ -1,15 +1,37 @@
class zulip::supervisor { class zulip::supervisor {
$supervisor_service = $zulip::common::supervisor_service
package { 'supervisor': ensure => 'installed' } package { 'supervisor': ensure => 'installed' }
if $::osfamily == 'redhat' { file { $zulip::common::supervisor_system_conf_dir:
file { $zulip::common::supervisor_conf_dir: ensure => 'directory',
ensure => 'directory', require => Package['supervisor'],
owner => 'root', owner => 'root',
group => '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 # 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 # /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', source => 'puppet:///modules/zulip/supervisor/supervisord.conf',
notify => Exec['supervisor-restart'], 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],
}
}
} }