Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Splunk forwarder upgrades when going to version 9 #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions manifests/forwarder/service/nix.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
#
class splunk::forwarder::service::nix inherits splunk::forwarder::service {
if $splunk::forwarder::boot_start {
if versioncmp($splunk::forwarder::version, '9.0.0') >= 0 {
$accept_tos_command = [
"${splunk::forwarder::forwarder_homedir}/bin/splunk stop &&",
"${splunk::forwarder::forwarder_homedir}/bin/splunk start --accept-license --answer-yes",
]
} else {
$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",
]
}
$accept_tos_user = 'root'
$accept_tos_require = Exec['enable_splunkforwarder']
# Ensure splunk services *not* managed by the system service file are
Expand Down Expand Up @@ -41,6 +53,11 @@
# Commands to license and disable the SplunkUniversalForwarder
#
else {
$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",
]
$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
Expand Down Expand Up @@ -85,11 +102,7 @@
} 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,
Expand Down
27 changes: 27 additions & 0 deletions spec/classes/forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,33 @@
end
end

context 'when forwarder already installed for version 9' do
let(:facts) do
facts.merge(splunkforwarder_version: '8.0.4', service_provider: facts[:kernel] == 'FreeBSD' ? 'freebsd' : 'systemd')
end
let(:pre_condition) do
"class { 'splunk::params': version => '9.0.4' }"
end
let(:accept_tos_command) do
'/opt/splunkforwarder/bin/splunk stop && /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes'
end
let(:service_name) do
facts[:kernel] == 'FreeBSD' ? 'splunk' : 'SplunkForwarder'
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[#{service_name}]",
subscribe: 'Package[splunkforwarder]',
require: 'Exec[enable_splunkforwarder]',
refreshonly: 'true'
)
end
end

context 'when $splunk::params::manage_net_tools == false' do
let(:pre_condition) do
"class { 'splunk::params': manage_net_tools => false }"
Expand Down