Skip to content

Commit

Permalink
Added ability to delete old releases
Browse files Browse the repository at this point in the history
Move the URL releases to their own directory under /opt to create the possibility for Puppet to remove old releases that are no longer used.
  • Loading branch information
SaschaDoering committed Jun 15, 2022
1 parent 001ec20 commit 521d843
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
# If version >= 0.10.0 then install amtool - Alertmanager validation tool
file { "${bin_dir}/amtool":
ensure => link,
target => "/opt/${package_name}-${version}.${os}-${arch}/amtool",
target => "${prometheus::basepath}/${package_name}-${version}.${os}-${arch}/amtool",
}

if $manage_config {
Expand Down
10 changes: 5 additions & 5 deletions manifests/daemon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
Hash[String[1], Scalar] $env_vars = {},
Stdlib::Absolutepath $env_file_path = $prometheus::env_file_path,
Optional[String[1]] $extract_command = $prometheus::extract_command,
Stdlib::Absolutepath $extract_path = '/opt',
Stdlib::Absolutepath $archive_bin_path = "/opt/${name}-${version}.${os}-${arch}/${name}",
Stdlib::Absolutepath $extract_path = $prometheus::basepath,
Stdlib::Absolutepath $archive_bin_path = "${prometheus::basepath}/${name}-${version}.${os}-${arch}/${name}",
Boolean $export_scrape_job = false,
Stdlib::Host $scrape_host = $facts['networking']['fqdn'],
Optional[Stdlib::Port] $scrape_port = undef,
Expand All @@ -89,17 +89,17 @@
case $install_method {
'url': {
if $download_extension == '' {
file { "/opt/${name}-${version}.${os}-${arch}":
file { "${prometheus::basepath}/${name}-${version}.${os}-${arch}":
ensure => directory,
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0755',
}
-> archive { "/opt/${name}-${version}.${os}-${arch}/${name}":
-> archive { "${prometheus::basepath}/${name}-${version}.${os}-${arch}/${name}":
ensure => present,
source => $real_download_url,
checksum_verify => false,
before => File["/opt/${name}-${version}.${os}-${arch}/${name}"],
before => File["${prometheus::basepath}/${name}-${version}.${os}-${arch}/${name}"],
proxy_server => $proxy_server,
proxy_type => $proxy_type,
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/dellhw_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# @param version
# The binary release version
# @param omreport_path
# The file path to the omReport executable (default "/opt/dell/srvadmin/bin/omreport")
# The file path to the omReport executable (default "/opt/prometheus/dell/srvadmin/bin/omreport")
# @param scrape_ipadress
# The ip address that the exporter will to listen to (default '')
# @param proxy_server
Expand Down Expand Up @@ -84,7 +84,7 @@
String[1] $scrape_job_name = 'dellhw',
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $bin_name = undef,
Stdlib::Unixpath $omreport_path = '/opt/dell/srvadmin/bin/omreport',
Stdlib::Unixpath $omreport_path = "${prometheus::basepath}/dell/srvadmin/bin/omreport",
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
) inherits prometheus {
Expand Down Expand Up @@ -127,7 +127,7 @@
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
bin_name => $bin_name,
archive_bin_path => "/opt/dellhw_exporter-${version}.${os}-${arch}/dellhw_exporter",
archive_bin_path => "${prometheus::basepath}/dellhw_exporter-${version}.${os}-${arch}/dellhw_exporter",
proxy_server => $proxy_server,
proxy_type => $proxy_type,
}
Expand Down
20 changes: 20 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
# Optional proxy server, with port number if needed. ie: https://example.com:8080
# @param proxy_type
# Optional proxy server type (none|http|https|ftp)
# @param clean_url_releases
# If this variable is activated, the releases are no longer installed under /opt but under /opt/prometheus. In addition, all releases that are no longer used are automatically deleted.
class prometheus (
String $user,
String $group,
Expand Down Expand Up @@ -307,6 +309,7 @@
Boolean $include_default_scrape_configs = true,
Optional[String[1]] $proxy_server = undef,
Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
Boolean $clean_url_releases = false,
) {
case $arch {
'x86_64', 'amd64': { $real_arch = 'amd64' }
Expand All @@ -321,6 +324,23 @@
}
}

if $clean_url_releases {
$basepath = '/opt/prometheus'

file { $basepath:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
backup => false,
force => true,
purge => true,
recurse => true,
}
} else {
$basepath = '/opt'
}

if $manage_prometheus_server {
include prometheus::server
}
Expand Down
14 changes: 7 additions & 7 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
archive { "/tmp/prometheus-${prometheus::server::version}.${prometheus::server::download_extension}":
ensure => present,
extract => true,
extract_path => '/opt',
extract_path => $prometheus::basepath,
source => $prometheus::server::real_download_url,
checksum_verify => false,
creates => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus",
creates => "${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus",
cleanup => true,
extract_command => $prometheus::extract_command,
}
-> file {
"/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus":
"${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus":
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0555';
"${prometheus::server::bin_dir}/prometheus":
ensure => link,
notify => $prometheus::server::notify_service,
target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus";
target => "${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/prometheus";
"${prometheus::server::bin_dir}/promtool":
ensure => link,
target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/promtool";
target => "${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/promtool";
$prometheus::server::shared_dir:
ensure => directory,
owner => $prometheus::server::user,
Expand All @@ -46,11 +46,11 @@
"${prometheus::server::shared_dir}/consoles":
ensure => link,
notify => $prometheus::server::notify_service,
target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/consoles";
target => "${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/consoles";
"${prometheus::server::shared_dir}/console_libraries":
ensure => link,
notify => $prometheus::server::notify_service,
target => "/opt/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/console_libraries";
target => "${prometheus::basepath}/prometheus-${prometheus::server::version}.${prometheus::server::os}-${prometheus::server::real_arch}/console_libraries";
}
}
'package': {
Expand Down
2 changes: 1 addition & 1 deletion manifests/ipsec_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}
else {
$release = "v${version}"
$archive_bin_path = "/opt/ipsec_exporter-v${version}.${os}-${arch}"
$archive_bin_path = "${prometheus::basepath}/ipsec_exporter-v${version}.${os}-${arch}"
}
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${release}.${os}-${arch}.${download_extension}")

Expand Down
2 changes: 1 addition & 1 deletion manifests/mongodb_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
if versioncmp($version, '0.7.0') < 0 or versioncmp($version, '0.20.4') >= 0 {
$archive_bin_path = undef # use default
} else {
$archive_bin_path = '/opt/mongodb_exporter'
$archive_bin_path = "${prometheus::basepath}/mongodb_exporter"
}

$notify_service = $restart_on_change ? {
Expand Down
2 changes: 1 addition & 1 deletion manifests/nginx_prometheus_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# nginx_prometheus_exporter lacks currently as of version 0.9.0
# TODO: patch prometheus::daemon to support custom extract directories
$real_install_method = 'none'
$install_dir = "/opt/${package_name}-${version}.${os}-${arch}"
$install_dir = "${prometheus::basepath}/${package_name}-${version}.${os}-${arch}"
file { $install_dir:
ensure => 'directory',
owner => 'root',
Expand Down
2 changes: 1 addition & 1 deletion manifests/openldap_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
if versioncmp($version, '2.2.1') >= 0 {
$real_download_extension = 'gz'
$real_download_url = pick($download_url,"${download_url_base}/download/${release}/${package_name}-${os}-${prometheus::real_arch}.gz")
$extract_path = "/opt/openldap_exporter-${version}.${os}-${prometheus::real_arch}"
$extract_path = "${prometheus::basepath}/openldap_exporter-${version}.${os}-${prometheus::real_arch}"
$archive_bin_path = "${extract_path}/openldap_exporter-${os}-${prometheus::real_arch}"
$extract_command = "gzip -cd %s > ${archive_bin_path}"
file { $extract_path:
Expand Down
2 changes: 1 addition & 1 deletion manifests/php_fpm_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
# php-fpm_exporter lacks currently as of version 2.0.4
# TODO: patch prometheus::daemon to support custom extract directories
$real_install_method = 'none'
$install_dir = "/opt/${package_name}-${version}.${os}-${arch}"
$install_dir = "${prometheus::basepath}/${package_name}-${version}.${os}-${arch}"
file { $install_dir:
ensure => 'directory',
owner => 'root',
Expand Down
2 changes: 1 addition & 1 deletion manifests/postgres_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
# postgres_exporter lacks.
# TODO: patch prometheus::daemon to support custom extract directories
$exporter_install_method = 'none'
$install_dir = "/opt/${service_name}-${version}.${os}-${arch}"
$install_dir = "${prometheus::basepath}/${service_name}-${version}.${os}-${arch}"
file { $install_dir:
ensure => 'directory',
owner => 'root',
Expand Down
2 changes: 1 addition & 1 deletion manifests/puppetdb_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
bin_name => $bin_name,
archive_bin_path => "/opt/prometheus-puppetdb-exporter-${version}.${os}-${arch}/prometheus-puppetdb-exporter",
archive_bin_path => "${prometheus::basepath}/prometheus-puppetdb-exporter-${version}.${os}-${arch}/prometheus-puppetdb-exporter",
proxy_server => $proxy_server,
proxy_type => $proxy_type,
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/pushprox_client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
install_method => $install_method,
version => $version,
download_extension => $download_extension,
archive_bin_path => "/opt/PushProx-${version}.${os}-${arch}/pushprox-client",
archive_bin_path => "${prometheus::basepath}/PushProx-${version}.${os}-${arch}/pushprox-client",
os => $os,
arch => $arch,
real_download_url => $real_download_url,
Expand Down
2 changes: 1 addition & 1 deletion manifests/pushprox_proxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
install_method => $install_method,
version => $version,
download_extension => $download_extension,
archive_bin_path => "/opt/PushProx-${version}.${os}-${arch}/pushprox-proxy",
archive_bin_path => "${prometheus::basepath}/PushProx-${version}.${os}-${arch}/pushprox-proxy",
os => $os,
arch => $arch,
real_download_url => $real_download_url,
Expand Down
2 changes: 1 addition & 1 deletion manifests/redis_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
# redis_exporter lacks before version 1.0.0
# TODO: patch prometheus::daemon to support custom extract directories
$real_install_method = 'none'
$install_dir = "/opt/${service_name}-${version}.${os}-${arch}"
$install_dir = "${prometheus::basepath}/${service_name}-${version}.${os}-${arch}"
file { $install_dir:
ensure => 'directory',
owner => 'root',
Expand Down
4 changes: 2 additions & 2 deletions manifests/snmp_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
}

$_source = $config_template ? {
'' => "file:/opt/snmp_exporter-${version}.${os}-${arch}/snmp.yml",
'' => "file:${prometheus::basepath}/snmp_exporter-${version}.${os}-${arch}/snmp.yml",
default => undef,
}

$_require = $config_template ? {
'' => File["/opt/snmp_exporter-${version}.${os}-${arch}/snmp_exporter"],
'' => File["${prometheus::basepath}/snmp_exporter-${version}.${os}-${arch}/snmp_exporter"],
default => undef,
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/ssl_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
], ' ')

# SSL exporter is not packaged into a directory
$extract_path = "/opt/${service_name}-${version}.${os}-${arch}"
$extract_path = "${prometheus::basepath}/${service_name}-${version}.${os}-${arch}"
file { $extract_path:
ensure => 'directory',
owner => 'root',
Expand Down

0 comments on commit 521d843

Please sign in to comment.