Skip to content

Commit

Permalink
simplify service reload by using concat/validate_cmd
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
faxm0dem committed Mar 29, 2015
1 parent 8e2eebc commit 239b270
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 57 deletions.
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$order = '5'
) {
concat::fragment { "syslog_ng::config ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => "${content}\n",
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/destination.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$order = '70'

concat::fragment { "syslog_ng::destination ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/filter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$order = '50'

concat::fragment { "syslog_ng::filter ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
26 changes: 10 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class syslog_ng (
$config_file = $::syslog_ng::params::config_file,
$tmp_config_file = $::syslog_ng::params::tmp_config_file,
$package_name = $::syslog_ng::params::package_name,
$service_name = $::syslog_ng::params::service_name,
$module_prefix = $::syslog_ng::params::module_prefix,
Expand All @@ -24,44 +23,39 @@
validate_array($modules)
validate_hash($init_config_hash)

class {'syslog_ng::reload':
syntax_check_before_reloads => $syntax_check_before_reloads
}

if ($manage_package) {
package { $::syslog_ng::params::package_name:
ensure => present,
before => [
Concat[$tmp_config_file],
Concat[$config_file],
Exec[syslog_ng_reload]
]
}
syslog_ng::module {$modules:}
}

concat { $tmp_config_file:
@concat { $config_file:
ensure => present,
path => $tmp_config_file,
path => $config_file,
owner => $user,
group => $group,
warn => true,
ensure_newline => true,
}

class {'syslog_ng::reload':
syntax_check_before_reloads => $syntax_check_before_reloads
}


notice("tmp_config_file: ${tmp_config_file}")
notice("config_file: ${config_file}")
concat::fragment {'syslog_ng header':
target => $tmp_config_file,
target => $config_file,
content => $config_file_header,
order => '01'
}
file {$config_file:
ensure => present,
path => $config_file,
require => Concat[$tmp_config_file]
}
if $manage_init_defaults {
$merged_init_config_hash = merge($init_config_hash,$::syslog_ng::params::init_config_hash)
file {$init_config_file:
Expand Down
2 changes: 1 addition & 1 deletion manifests/log.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
) {
$order = '80'
concat::fragment { "syslog_ng::log ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_log($params),
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/options.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$order = '10'

concat::fragment { "syslog_ng::options ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_options($options),
order => $order
}
Expand Down
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}
}
$service_name = 'syslog-ng'
$tmp_config_file = '/tmp/syslog-ng.conf.tmp'
$config_file = '/etc/syslog-ng/syslog-ng.conf'
$config_file_header = "# This file was generated by Puppet's ihrwein-syslog_ng module"
}
2 changes: 1 addition & 1 deletion manifests/parser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$order = '40'

concat::fragment { "syslog_ng::parser ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
18 changes: 4 additions & 14 deletions manifests/reload.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
include syslog_ng::params

$config_file = $::syslog_ng::config_file
$tmp_config_file = $::syslog_ng::params::tmp_config_file
$exec_path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:'

$syslog_ng_ctl_full_path = "${::syslog_ng::sbin_path}/syslog-ng-ctl"
$syslog_ng_full_path = "${::syslog_ng::sbin_path}/syslog-ng"

exec { 'syslog_ng_syntax_check':
command => "${syslog_ng_full_path} --syntax-only --cfgfile ${tmp_config_file}",
path => $exec_path,
refreshonly => true
}
$syslog_ng_syntax_check_cmd = "${syslog_ng_full_path} --syntax-only --cfgfile %"

notice("syslog_ng::reload: syntax_check_before_reloads=${syntax_check_before_reloads}")

Expand All @@ -27,15 +22,10 @@
logoutput => true,
}

exec { 'syslog_ng_deploy_config':
command => "cp ${tmp_config_file} ${config_file}",
path => $exec_path,
refreshonly => true
}

if $syntax_check_before_reloads {
File[$tmp_config_file] ~> Exec['syslog_ng_syntax_check'] ~> Exec['syslog_ng_deploy_config'] ~> Exec['syslog_ng_reload']
Concat <| title == $config_file |> { validate_cmd => $syslog_ng_syntax_check_cmd }
} else {
File[$tmp_config_file] ~> Exec['syslog_ng_deploy_config'] ~> Exec['syslog_ng_reload']
Concat <| title == $config_file |>
}
Concat[$config_file] ~> Exec['syslog_ng_reload']
}
2 changes: 1 addition & 1 deletion manifests/rewrite.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$order = '30'

concat::fragment { "syslog_ng::rewrite ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$order = '60'

concat::fragment { "syslog_ng::source ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/template.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$order = '20'

concat::fragment { "syslog_ng::template ${title}":
target => $::syslog_ng::tmp_config_file,
target => $::syslog_ng::config_file,
content => generate_statement($id, $type, $params),
order => $order
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
{
"name": "puppetlabs/concat",
"version_requirement": ">= 1.0.0"
"version_requirement": ">= 1.2.0"
}
]
}
34 changes: 18 additions & 16 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,25 @@
should contain_syslog_ng__module('baz')
}
end
context 'When asked to check syntax before reload' do
let(:params) {{
:syntax_check_before_reloads => true
}}
it {
should contain_file('/tmp/syslog-ng.conf.tmp').that_notifies('Exec[syslog_ng_syntax_check]')
should contain_exec('syslog_ng_syntax_check').that_notifies('Exec[syslog_ng_deploy_config]')
should contain_exec('syslog_ng_deploy_config').that_notifies('Exec[syslog_ng_reload]')
}
end
context 'When asked not to check syntax before reload' do
let(:params) {{
:syntax_check_before_reloads => false
}}
context 'When config changes' do
it {
should contain_file('/tmp/syslog-ng.conf.tmp').that_notifies('Exec[syslog_ng_deploy_config]')
should contain_exec('syslog_ng_deploy_config').that_notifies('Exec[syslog_ng_reload]')
should contain_concat('/etc/syslog-ng/syslog-ng.conf').that_notifies('Exec[syslog_ng_reload]')
}
context 'and asked to check syntax before reload' do
let(:params) {{
:syntax_check_before_reloads => true
}}
it {
should contain_concat('/etc/syslog-ng/syslog-ng.conf').with_validate_cmd(/syntax-only/)
}
end
context 'and asked not to check syntax before reload' do
let(:params) {{
:syntax_check_before_reloads => false
}}
it {
should contain_concat('/etc/syslog-ng/syslog-ng.conf').without_validate_cmd
}
end
end
end

0 comments on commit 239b270

Please sign in to comment.