Puppet Class: metricbeat::install
- Inherits:
- metricbeat
- Defined in:
- manifests/install.pp
Summary
Manages the state of Package['metricbeat']Overview
metricbeat::install Manages the state of Package['metricbeat']
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'manifests/install.pp', line 7
class metricbeat::install inherits metricbeat {
if $::kernel == 'Windows' {
$filename = regsubst($metricbeat::real_download_url, '^https?.*\/([^\/]+)\.[^.].*', '\1')
$foldername = 'Metricbeat'
$zip_file = join([$metricbeat::tmp_dir, "${filename}.zip"], '/')
$install_folder = join([$metricbeat::install_dir, $foldername], '/')
$version_file = join([$install_folder, $filename], '/')
Exec {
provider => powershell,
}
if !defined(File[$metricbeat::install_dir]) {
file{$metricbeat::install_dir:
ensure => directory,
}
}
archive{ $zip_file:
source => $metricbeat::real_download_url,
cleanup => false,
creates => $version_file,
proxy_server => $metricbeat::proxy_address,
}
exec{"unzip ${filename}":
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${metricbeat::install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${zip_file}')).items(), 16)", # lint:ignore:140chars
creates => $version_file,
require => [
File[$metricbeat::install_dir],
Archive[$zip_file],
],
}
# Clean up after ourselves
file{$zip_file:
ensure => absent,
backup => false,
require => Exec["unzip ${filename}"],
}
# You can't remove the old dir while the service has files locked...
exec{"stop service ${filename}":
command => 'Set-Service -Name metricbeat -Status Stopped',
creates => $version_file,
onlyif => 'if(Get-WmiObject -Class Win32_Service -Filter "Name=\'metricbeat\'") {exit 0} else {exit 1}',
require => Exec["unzip ${filename}"],
}
exec{"rename ${filename}":
command => "Remove-Item '${install_folder}' -Recurse -Force -ErrorAction SilentlyContinue;Rename-Item '${metricbeat::install_dir}/${filename}' '${install_folder}'", # lint:ignore:140chars
creates => $version_file,
require => Exec["stop service ${filename}"],
}
exec{"mark ${filename}":
command => "New-Item '${version_file}' -ItemType file",
creates => $version_file,
require => Exec["rename ${filename}"],
}
exec{"install ${filename}":
cwd => $install_folder,
command => './install-service-metricbeat.ps1',
refreshonly => true,
subscribe => Exec["mark ${filename}"],
}
}
else {
if $metricbeat::ensure == 'present' {
$package_ensure = $metricbeat::package_ensure
}
else {
$package_ensure = $metricbeat::ensure
}
package{'metricbeat':
ensure => $package_ensure,
}
}
}
|