Skip to content

Fix windows installation adding archive extract method #333

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

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
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
Optional[String] $registry_file_permissions = $filebeat::params::registry_file_permissions,
Optional[String] $registry_flush = $filebeat::params::registry_flush,
Boolean $overwrite_pipelines = $filebeat::params::overwrite_pipelines,
Enum['shell', 'archive'] $extract_method = $filebeat::params::extract_method,

) inherits filebeat::params {
include stdlib
Expand Down
80 changes: 46 additions & 34 deletions manifests/install/windows.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,62 @@
}
}

# Note: We can use archive for unzip and cleanup, thus removing the following two resources.
# However, this requires 7zip, which archive can install via chocolatey:
# https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31
# I'm not choosing to impose those dependencies on anyone at this time...
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
}
if $filebeat::extract_method == 'shell' {
# Note: We can use archive for unzip and cleanup, thus removing the following two resources.
# However, this requires 7zip, which archive can install via chocolatey:
# https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L31
# I'm not choosing to impose those dependencies on anyone at this time...
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
}

# Core editions of Windows Server do not have a shell as such, so use the Shell.Application COM object doesn't work.
# Expand-Archive is a native powershell cmdlet which ships with Powershell 5, which in turn ships with Windows 10 and
# Windows Server 2016 and newer.
if ( (versioncmp($facts['os']['release']['full'], '2016') >= 0)
or (versioncmp($facts['os']['release']['full'], '2000') < 0 and versioncmp($facts['os']['release']['full'], '10') >= 0) ) {
$unzip_command = "Expand-Archive ${zip_file} \"${filebeat::install_dir}\""
}
else {
$unzip_command = "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)" # lint:ignore:140chars
}
# Core editions of Windows Server do not have a shell as such, so use the Shell.Application COM object doesn't work.
# Expand-Archive is a native powershell cmdlet which ships with Powershell 5, which in turn ships with Windows 10 and
# Windows Server 2016 and newer.
if ( (versioncmp($facts['os']['release']['full'], '2016') >= 0)
or (versioncmp($facts['os']['release']['full'], '2000') < 0 and versioncmp($facts['os']['release']['full'], '10') >= 0) ) {
$unzip_command = "Expand-Archive ${zip_file} \"${filebeat::install_dir}\""
}
else {
$unzip_command = "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${filebeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)" # lint:ignore:140chars
}

exec { "unzip ${filename}":
command => $unzip_command,
creates => $version_file,
require => [
File[$filebeat::install_dir],
Archive[$zip_file],
],
}
exec { "unzip ${filename}":
command => $unzip_command,
creates => $version_file,
require => [
File[$filebeat::install_dir],
Archive[$zip_file],
],
}

# Clean up after ourselves
file { $zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
# Clean up after ourselves
file { $zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
before => Exec["stop service ${filename}"],
}
} else {
archive { $zip_file:
source => $filebeat::real_download_url,
cleanup => true,
extract => true,
extract_path => $filebeat::install_dir,
creates => $version_file,
proxy_server => $filebeat::proxy_address,
before => Exec["stop service ${filename}"],
}
}

# You can't remove the old dir while the service has files locked...
exec { "stop service ${filename}":
command => 'Set-Service -Name filebeat -Status Stopped',
creates => $version_file,
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'filebeat\'") {exit 0} else {exit 1}',
require => Exec["unzip ${filename}"],
}

exec { "rename ${filename}":
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
$registry_path = '/var/lib/filebeat'
$registry_file_permissions = '0600'
$registry_flush = '0s'
$extract_method = 'shell'

# These are irrelevant as long as the template is set based on the major_version parameter
# if versioncmp('1.9.1', $::rubyversion) > 0 {
Expand Down