Skip to content

Commit

Permalink
Merge b30a607 into f818422
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Jan 30, 2020
2 parents f818422 + b30a607 commit 0ba22eb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
24 changes: 24 additions & 0 deletions manifests/forwarder/service/nix.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class splunk::forwarder::service::nix inherits splunk::forwarder::service {

if $splunk::forwarder::boot_start {
$accept_tos_user = 'root'
$accept_tos_require = Exec['enable_splunkforwarder']
# Ensure splunk services *not* managed by the system service file are
# gracefully shut down prior to enabling boot-start. Should the service
# file be enabled while binary-managed splunk services are running, you
Expand Down Expand Up @@ -36,6 +38,8 @@
# Commands to license and disable the SplunkUniversalForwarder
#
else {
$accept_tos_user = $splunk::forwarder::splunk_user
$accept_tos_require = Exec['license_splunkforwarder']
# Accept the license when disabling splunk in case system service files are
# present before installing splunk. The splunk package does not remove the
# service files when uninstalled.
Expand Down Expand Up @@ -72,4 +76,24 @@
}
}

# If forwarder is already installed, refresh from package changes
if $facts['splunkforwarder_version'] {
$accept_tos_subscribe = Package[$splunk::forwarder::package_name]
} else {
$accept_tos_subscribe = undef
}
$accept_tos_command = [
"${splunk::forwarder::forwarder_homedir}/bin/splunk stop &&",
"${splunk::forwarder::forwarder_homedir}/bin/splunk start --accept-license --answer-yes &&",
"${splunk::forwarder::forwarder_homedir}/bin/splunk stop",
]
exec { 'splunk-forwarder-accept-tos':
command => join($accept_tos_command, ' '),
user => $accept_tos_user,
before => Service[$splunk::forwarder::service_name],
subscribe => $accept_tos_subscribe,
require => $accept_tos_require,
refreshonly => true,
}

}
48 changes: 48 additions & 0 deletions spec/classes/forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,54 @@

end
end

context 'when forwarder not already installed' do
let(:facts) do
facts.merge(splunkforwarder_version: nil, service_provider: 'systemd')
end
let(:pre_condition) do
"class { 'splunk::params': version => '7.2.2' }"
end
let(:accept_tos_command) do
'/opt/splunkforwarder/bin/splunk stop && /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes && /opt/splunkforwarder/bin/splunk stop'
end

it_behaves_like 'splunk forwarder'
it do
is_expected.to contain_exec('splunk-forwarder-accept-tos').with(
command: accept_tos_command,
user: 'root',
before: 'Service[SplunkForwarder]',
subscribe: nil,
require: 'Exec[enable_splunkforwarder]',
refreshonly: 'true'
)
end
end

context 'when forwarder already installed' do
let(:facts) do
facts.merge(splunkforwarder_version: '7.3.3', service_provider: 'systemd')
end
let(:pre_condition) do
"class { 'splunk::params': version => '7.2.2' }"
end
let(:accept_tos_command) do
'/opt/splunkforwarder/bin/splunk stop && /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes && /opt/splunkforwarder/bin/splunk stop'
end

it_behaves_like 'splunk forwarder'
it do
is_expected.to contain_exec('splunk-forwarder-accept-tos').with(
command: accept_tos_command,
user: 'root',
before: 'Service[SplunkForwarder]',
subscribe: 'Package[splunkforwarder]',
require: 'Exec[enable_splunkforwarder]',
refreshonly: 'true'
)
end
end
end
end
end
Expand Down

0 comments on commit 0ba22eb

Please sign in to comment.