Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
628a3dc
fix: use systemd::unit_file for service
Aug 23, 2021
7c3684e
fix: wait until restarting service
Aug 23, 2021
8144493
fix: notify service-install when files changed
Aug 23, 2021
d9353d4
fix: restart correct service when updating config
Aug 23, 2021
c2d1e06
fix: add Start-Limit Burst for Promtail
Aug 23, 2021
ac83b6f
feat: implement support for windows
Sep 16, 2021
ebc2114
fix: convert to string type
Sep 16, 2021
ec25d16
fix: add supported architecture 'x64'
Sep 16, 2021
a908547
fix: actually use absolute-path type
Sep 16, 2021
7b06435
fix: install windows service correctly before using service class
Sep 16, 2021
810743a
fix: correctly register service
Sep 17, 2021
c20d9f6
fix: remove New-Service definition in promtail::service class
Sep 17, 2021
7cd029a
fix: remove unused require of the installed service
Sep 17, 2021
02f5cb8
Revert "fix: remove unused require of the installed service"
Sep 17, 2021
3eaf2a6
Revert "fix: remove New-Service definition in promtail::service class"
Sep 17, 2021
bc0a286
fix(service): install windows service with sc.exe
Sep 18, 2021
1161f52
fix: install and manage service with sc.exe only
Sep 18, 2021
633a89b
fix: hopefully install service correctly
Sep 20, 2021
b977bad
fix: actual install promtail windows service
Sep 20, 2021
35f1024
fix: install windows service as automatic startup
Sep 20, 2021
5b73154
fix: path of service for installation
Sep 20, 2021
cf50843
fix: mistyping in hiera.yaml
Sep 20, 2021
1ca3a88
feat: add support of windows to metadata
Sep 20, 2021
114ac66
fix: use nssm package to support windows service
Sep 20, 2021
f890bce
fix: add correct ensure state to nssm::service definition
Sep 20, 2021
79bfb86
fix: require nssm package
Sep 20, 2021
924d350
fix: how config path is given to nssm::service definition
Sep 20, 2021
e647edb
fix: update required nssm package
Sep 20, 2021
e5158a7
fix: app parameter to enquote the config path
Sep 20, 2021
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: 0 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ lookup_options:
'^promtail::password_file_content$':
convert_to: 'Sensitive'

promtail::bin_dir: '/usr/local/bin'
promtail::service_ensure: 'running'
promtail::service_enable: true
promtail::version: 'v2.0.0'
Expand Down
5 changes: 5 additions & 0 deletions files/promtail.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ Description=Promtail agent from Grafana
Documentation=https://github.com/grafana/loki/tree/master/docs/clients/promtail
After=network.target

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
ExecStart=/usr/local/bin/promtail -config.file=/etc/promtail/config.yaml
ExecReload=/bin/kill -HUP $MAINPID

Restart=on-failure
RestartSec=2s
RestartForceExitStatus=SIGPIPE
KillMode=control-group

Expand Down
2 changes: 1 addition & 1 deletion hiera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defaults: # Used for any hierarchy level that omits these keys.
data_hash: yaml_data # Use the built-in YAML backend.

hierarchy:
- name: 'kermel'
- name: 'kernel'
path: "kernel/%{facts.kernel}.yaml"
- name: 'common'
path: 'common.yaml'
14 changes: 8 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
class promtail::config {
case $facts['kernel'] {
'Linux': {
$config_dir = '/etc/promtail'
$config_file = "${promtail::config_dir}/config.yaml"
}
'windows': {
$config_file = "${promtail::config_dir}\\config.yaml"
}
default: { fail("${facts['kernel']} is not supported") }
}

file { $config_dir:
file { $promtail::config_dir:
ensure => directory,
}

$config_file = "${config_dir}/config.yaml"

concat { $config_file:
ensure => present,
notify => Service['promtail'],
ensure => present,
require => File[$promtail::config_dir],
notify => $promtail::service::service_to_notify,
}

concat::fragment { 'config_header':
Expand Down
40 changes: 26 additions & 14 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
# @param [Stdlib::Absolutepath] bin_dir
# The directory in which to create a symlink to the promtail binary
#
# @param [Stdlib::Absolutepath] config_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since newer puppet-strings releases, you don't have to provide the datatype here, puppet-strings will read it from the actual code

# The directory in which the promtail config is stored
#
# @param [Stdlib::Absolutepath] data_dir
# The directory in which to versions of promtail are stored and updated
#
# @param [Stdlib::Absolutepath] log_file_path
# The directory in logs should be stored (Windows only feature!)
#
# @param [String[1]] checksum
# The checksum of the promtail binary.
# Note: each platform has its own checksum.
Expand Down Expand Up @@ -123,20 +132,23 @@
# }
#
class promtail (
Boolean $service_enable,
Enum['running', 'stopped'] $service_ensure,
Hash $clients_config_hash,
Hash $positions_config_hash,
Hash $scrape_configs_hash,
Stdlib::Absolutepath $bin_dir,
String[1] $checksum,
String[1] $version,
Optional[Hash] $server_config_hash = undef,
Optional[Hash] $target_config_hash = undef,
Optional[Stdlib::Absolutepath] $password_file_path = undef,
Optional[Sensitive[String[1]]] $password_file_content = undef,
Stdlib::HTTPUrl $source_url = 'https://github.com/grafana/loki/releases/download',
) {
Boolean $service_enable,
Enum['running', 'stopped', 'absent'] $service_ensure,
Hash $clients_config_hash,
Hash $positions_config_hash,
Hash $scrape_configs_hash,
Stdlib::Absolutepath $bin_dir = $promtail::params::bin_dir,
Stdlib::Absolutepath $data_dir = $promtail::params::data_dir,
Stdlib::Absolutepath $config_dir = $promtail::params::config_dir,
Optional[Stdlib::Absolutepath] $log_file_path = undef,
String[1] $checksum,
String[1] $version,
Optional[Hash] $server_config_hash = undef,
Optional[Hash] $target_config_hash = undef,
Optional[Stdlib::Absolutepath] $password_file_path = undef,
Optional[Sensitive[String[1]]] $password_file_content = undef,
Stdlib::HTTPUrl $source_url = 'https://github.com/grafana/loki/releases/download',
) inherits promtail::params {
Class['promtail::install']
-> Class['promtail::config']
-> Class['promtail::service']
Expand Down
40 changes: 28 additions & 12 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@
include archive

case $facts['os']['architecture'] {
'x86_64', 'amd64': { $arch = 'amd64' }
'aarch64': { $arch = 'arm64' }
'armv7l': { $arch = 'arm' }
default: { fail("Unsupported kernel architecture: ${facts['os']['architecture']}") }
'x86_64', 'amd64', 'x64': { $arch = 'amd64' }
'aarch64': { $arch = 'arm64' }
'armv7l': { $arch = 'arm' }
default: { fail("Unsupported kernel architecture: ${facts['os']['architecture']}") }
}

case $facts['kernel'] {
'Linux': {
$data_dir = '/usr/local/promtail_data'
if versioncmp($promtail::version, 'v0.3.0') > 0 {
$release_file_name = "promtail-linux-${arch}"
} else {
$release_file_name = "promtail_linux_${arch}"
}
}
'windows': {
if versioncmp($promtail::version, 'v0.3.0') > 0 {
$release_file_name = "promtail-windows-${arch}.exe"
} else {
$release_file_name = "promtail_windows_${arch}.exe"
}
}
default: { fail("${facts['kernel']} is not yet supported") }
}

Expand All @@ -31,14 +37,20 @@
$archive_type = 'gz'
}

$version_dir = "${data_dir}/promtail-${promtail::version}"
$binary_path = "${version_dir}/${release_file_name}"
$version_dir = $facts['kernel'] ? {
'windows' => "${promtail::data_dir}\\${promtail::version}",
default => "${promtail::data_dir}/promtail-${promtail::version}"
}
$binary_path = $facts['kernel'] ? {
'windows' => "${version_dir}\\${release_file_name}",
default => "${version_dir}/${release_file_name}"
}

file { [$data_dir, $version_dir]:
file { [$promtail::bin_dir, $promtail::data_dir, $version_dir]:
ensure => directory,
}

archive { "${binary_path}.gz":
archive { "${binary_path}.${archive_type}":
ensure => present,
source => "${promtail::source_url}/${promtail::version}/${release_file_name}.${archive_type}",
extract => true,
Expand All @@ -49,17 +61,21 @@
cleanup => false,
}

$binary_link_path = $facts['kernel'] ? {
'windows' => "${promtail::bin_dir}\\promtail.exe",
default => "${promtail::bin_dir}/promtail"
}
file {
$binary_path:
ensure => file,
mode => '0755',
require => Archive["${binary_path}.gz"],
require => Archive["${binary_path}.${archive_type}"],
;
"${promtail::bin_dir}/promtail":
$binary_link_path:
ensure => link,
target => $binary_path,
require => File[$binary_path],
notify => Service['promtail'],
notify => $promtail::service::service_to_notify
;
}
}
20 changes: 20 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# @summary Default promtail variables
#
# Sets default variables per OS
#
# @api private
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this class is private I suggest adding assert_private() to the code

class promtail::params {
case $facts['kernel'] {
'Linux': {
$bin_dir = '/usr/local/bin'
$data_dir = '/usr/local/promtail_data'
$config_dir = '/etc/promtail'
Comment on lines +8 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These items belong in data/kernel/Linux.yaml

}
'windows': {
$bin_dir = 'C:\\Program Files\\promtail'
$data_dir = "${bin_dir}\\versions"
$config_dir = "${bin_dir}\\config"
Comment on lines +14 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These items belong in data/kernel/windows.yaml

}
default: { fail("${facts['kernel']} is not yet supported") }
}
}
22 changes: 22 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# @api private
class promtail::service {
$service_to_notify = Service['promtail']

case $facts['kernel'] {
'Linux': {
systemd::unit_file { 'promtail.service':
Expand All @@ -17,6 +19,26 @@
require => Systemd::Unit_file['promtail.service'],
}
}
'windows': {
require nssm

$nssm_presents = $promtail::service_ensure ? {
'running' => 'present',
default => $promtail::service_ensure
}
nssm::service { 'promtail':
ensure => $nssm_presents,
command => $promtail::install::binary_link_path,
app_parameters => "--config.file=\\\"${promtail::config::config_file}\\\"",
log_file_path => $promtail::log_file_path
}

service { 'promtail':
ensure => $promtail::service_ensure,
enable => $promtail::service_enable,
require => Nssm::Service['promtail'],
}
}
default: { fail("${facts['kernel']} is not supported") }
}
}
35 changes: 12 additions & 23 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,38 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 6.0.0 < 8.0.0"
},
{
"name": "mxzinke/nssm",
"version_requirement": ">= 1.0.3 < 2.0.0"
}
],
"operatingsystem_support": [
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7",
"8"
]
"operatingsystemrelease": ["7", "8"]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"7",
"8"
]
"operatingsystemrelease": ["7", "8"]
},
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"7",
"8"
]
"operatingsystemrelease": ["7", "8"]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": [
"7"
]
"operatingsystemrelease": ["7"]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"9",
"10"
]
"operatingsystemrelease": ["9", "10"]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"18.04"
]
}
"operatingsystemrelease": ["18.04"]
},
{ "operatingsystem": "Windows" }
],
"requirements": [
{
Expand Down