Skip to content

Commit

Permalink
Merge pull request voxpupuli#43 from billyperformance/reload_config
Browse files Browse the repository at this point in the history
Reload config
  • Loading branch information
bastelfreak committed Sep 9, 2017
2 parents 6b1b3ba + 00b9f23 commit f7deced
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ fixtures:
repositories:
archive: "https://github.com/voxpupuli/puppet-archive"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib"
systemd: "https://github.com/camptocamp/puppet-systemd"
symlinks:
"prometheus": "#{source_dir}"
1 change: 1 addition & 0 deletions manifests/alerts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ensure => 'file',
owner => $prometheus::user,
group => $prometheus::group,
notify => Class['::prometheus::service_reload'],
content => epp("${module_name}/alerts.epp"),
}
}
Expand Down
19 changes: 14 additions & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@

if $prometheus::init_style {

# the vast majority of files here are init-files
# so any change there should trigger a full service restart
# systemd reload comes from the systemd module
if $::prometheus::restart_on_change {
File {
notify => [Class['::prometheus::run_service']],
}
$systemd_notify = [Exec['systemctl-daemon-reload'], Class['::prometheus::run_service']]
} else {
$systemd_notify = Exec['systemctl-daemon-reload']
}

case $prometheus::init_style {
'upstart' : {
file { '/etc/init/prometheus.conf':
Expand All @@ -31,13 +43,9 @@
mode => '0644',
owner => 'root',
group => 'root',
notify => $systemd_notify,
content => template('prometheus/prometheus.systemd.erb'),
}
~> exec { 'prometheus-systemd-reload':
command => 'systemctl daemon-reload',
path => [ '/usr/bin', '/bin', '/usr/sbin' ],
refreshonly => true,
}
}
'sysv' : {
file { '/etc/init.d/prometheus':
Expand Down Expand Up @@ -90,6 +98,7 @@
owner => $prometheus::user,
group => $prometheus::group,
mode => $prometheus::config_mode,
notify => Class['::prometheus::service_reload'],
content => template($config_template),
}

Expand Down
9 changes: 3 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
#
# [*restart_on_change*]
# Should puppet restart prometheus on configuration change? (default true)
# Note: this applies only to command-line options changes. Configuration
# options are always *reloaded* without restarting.
#
# [*init_style*]
# Service startup scripts style (e.g. rc, upstart or systemd)
Expand Down Expand Up @@ -167,10 +169,6 @@

$config_hash_real = deep_merge($config_defaults, $config_hash)
validate_hash($config_hash_real)
$notify_service = $restart_on_change ? {
true => Class['::prometheus::run_service'],
default => undef,
}

anchor {'prometheus_first': }
-> class { '::prometheus::install': }
Expand All @@ -179,14 +177,13 @@
rule_files => $rule_files,
scrape_configs => $scrape_configs,
purge => $purge_config_dir,
notify => $notify_service,
config_template => $config_template,
}
-> class { '::prometheus::alerts':
location => $config_dir,
alerts => $alerts,
notify => $notify_service,
}
-> class { '::prometheus::run_service': }
-> class { '::prometheus::service_reload': }
-> anchor {'prometheus_last': }
}
1 change: 0 additions & 1 deletion manifests/run_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
name => $init_selector,
enable => $prometheus::service_enable,
hasrestart => true,
restart => '/usr/bin/pkill -HUP prometheus',
}
}
}
23 changes: 23 additions & 0 deletions manifests/service_reload.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This class implements prometheus service reload
# without restarting the whole service when a config
# changes
class prometheus::service_reload() {

if $prometheus::manage_service == true {
$init_selector = $prometheus::run_service::init_selector

$prometheus_reload = $prometheus::init_style ? {
'systemd' => "systemctl reload ${init_selector}",
'upstart' => "upstart reload ${init_selector}",
'sysv' => "/etc/init.d/${init_selector} reload",
'sles' => "/etc/init.d/${init_selector} reload",
'debian' => "/etc/init.d/${init_selector} reload",
'launchd' => "launchctl stop ${init_selector} && launchctl start ${init_selector}",
}

exec { 'prometheus-reload':
command => $prometheus_reload,
refreshonly => true,
}
}
}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"name":"puppet/archive",
"version_requirement":">=1.3.0 <2.0.0"
},
{
"name":"camptocamp/systemd",
"version_requirement":">=0.4.0 <1.0.0"
},
{
"name":"puppetlabs/stdlib",
"version_requirement":">= 4.6.0 <5.0.0"
Expand Down

0 comments on commit f7deced

Please sign in to comment.