diff --git a/REFERENCE.md b/REFERENCE.md
index 54d3a7a..0e91581 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -47,6 +47,7 @@ The following parameters are available in the `otelcol` class:
* [`package_name`](#-otelcol--package_name)
* [`package_ensure`](#-otelcol--package_ensure)
* [`service_name`](#-otelcol--service_name)
+* [`service_configcheck`](#-otelcol--service_configcheck)
* [`environment_file`](#-otelcol--environment_file)
* [`run_options`](#-otelcol--run_options)
* [`config_file`](#-otelcol--config_file)
@@ -93,6 +94,14 @@ Name of the service used
Default value: `$package_name`
+##### `service_configcheck`
+
+Data type: `Boolean`
+
+Check config before service reloads
+
+Default value: `true`
+
##### `environment_file`
Data type: `String`
diff --git a/manifests/init.pp b/manifests/init.pp
index f0656ba..25fa850 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -6,6 +6,8 @@
# Ensure for the package
# @param service_name
# Name of the service used
+# @param service_configcheck
+# Check config before service reloads
# @param environment_file
# path of the environment file used for service
# @param run_options
@@ -52,6 +54,7 @@
String $package_name = 'otelcol',
Enum['present','absent','installed','latest'] $package_ensure = 'installed',
String $service_name = $package_name,
+ Boolean $service_configcheck = true,
String $environment_file = "/etc/${package_name}/${package_name}.conf",
Optional[String] $run_options = undef,
String $config_file = "/etc/${package_name}/config.yaml",
diff --git a/manifests/service.pp b/manifests/service.pp
index 5747823..e492c7e 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -14,20 +14,36 @@
# @api private
class otelcol::service (
Stdlib::Ensure::Service $ensure = $otelcol::service_ensure,
+ String $config_check_command = "${otelcol::service_name} validate --config=${otelcol::config_file}",
+ Boolean $config_check = $otelcol::service_configcheck,
) {
# include install
include otelcol::install
- # systemd::dropin_file { 'otelcol_service':
- # unit => 'otelcol.service',
- # content => epp('otelcol/otelcol.dropin.epp'),
- # filename => 'otelcol_override.conf',
- # }
- # ~>
+ if $config_check {
+ exec { 'otelcol_config_check':
+ command => $config_check_command,
+ refreshonly => true,
+ path => [
+ '/usr/local/sbin',
+ '/usr/local/bin',
+ '/usr/sbin',
+ '/usr/bin',
+ '/sbin',
+ '/bin',
+ ],
+ }
+ }
+
+ $service_require = $config_check ? {
+ true => [Exec['otelcol_config_check'], Package['otelcol']],
+ false => Package['otelcol'],
+ }
+
service { 'otelcol':
ensure => $ensure,
name => $otelcol::service_name,
- require => Package['otelcol'],
+ require => $service_require,
subscribe => [Concat['otelcol-config'], File['otelcol-environment']],
}
}
diff --git a/spec/classes/otelcol_spec.rb b/spec/classes/otelcol_spec.rb
index 56cb090..b435dd7 100644
--- a/spec/classes/otelcol_spec.rb
+++ b/spec/classes/otelcol_spec.rb
@@ -341,6 +341,17 @@
it { is_expected.to contain_service('otelcol').with_ensure('stopped') }
end
+ context 'with service_configcheck' do
+ let :params do
+ {
+ service_configcheck: true,
+ }
+ end
+
+ it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_service('otelcol').that_requires('Exec[otelcol_config_check]') }
+ end
+
context 'do not manage Service' do
let :params do
{