feat: add victorialogs module (#374)
- add module for victorialogs - add hieradata for vl insert/select/storage - manage packages, directories, services, etc - manage exporting metrics Reviewed-on: #374
This commit was merged in pull request #374.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
class victorialogs::node (
|
||||
Boolean $enable = false,
|
||||
String $user = 'victorialogs',
|
||||
String $group = 'victorialogs',
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_service = true,
|
||||
Array[String] $packages = ['victoria-logs', 'vlutils'],
|
||||
Stdlib::Absolutepath $exec_path = '/usr/bin/victoria-logs',
|
||||
Stdlib::Absolutepath $data_path = '/var/lib/victorialogs',
|
||||
Stdlib::Absolutepath $vars_file = '/etc/default/victoria-logs',
|
||||
Hash[String, Variant[String, Array[String]]] $options = {},
|
||||
) {
|
||||
|
||||
# if enabled, manage this service
|
||||
if $enable {
|
||||
|
||||
# install required packages
|
||||
if $packages {
|
||||
ensure_packages($packages, {ensure => 'installed'})
|
||||
}
|
||||
|
||||
# manage the user/group
|
||||
if $manage_user {
|
||||
group { $group:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
user { $user:
|
||||
ensure => present,
|
||||
shell => '/usr/sbin/nologin',
|
||||
groups => $group,
|
||||
managehome => true,
|
||||
}
|
||||
}
|
||||
|
||||
# manage directories
|
||||
file { [ $data_path ]:
|
||||
ensure => directory,
|
||||
owner => $user,
|
||||
group => $group,
|
||||
}
|
||||
|
||||
# manage environment options file
|
||||
file { $vars_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('victorialogs/options.erb'),
|
||||
}
|
||||
|
||||
# manage the systemd service
|
||||
if $manage_service {
|
||||
|
||||
# manage the subscribed resources
|
||||
if 'tls' in $options and $options['tls'] == 'true' {
|
||||
if 'tlsCertFile' in $options and 'tlsKeyFile' in $options {
|
||||
# tls option AND certs listed, subscribe to the options file and certs
|
||||
$subscribe = [File[$vars_file],File[$options['tlsCertFile']], File[$options['tlsKeyFile']]]
|
||||
}else{
|
||||
# tls option but no certs listed, just subscribe to the options file
|
||||
warning('TLS is enabled but tlsCertFile or tlsKeyFile is missing from victorialogs options.')
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
}else{
|
||||
# no tls option, just subscribe to the options file
|
||||
$subscribe = [File[$vars_file]]
|
||||
}
|
||||
|
||||
# Use these in notifications or file resources
|
||||
systemd::unit_file { 'victorialogs.service':
|
||||
content => template('victorialogs/victorialogs.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
subscribe => $subscribe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<%
|
||||
opts = @options || {}
|
||||
lines = []
|
||||
|
||||
def undefish?(v)
|
||||
v.respond_to?(:strip) && v.strip.downcase == 'undef'
|
||||
end
|
||||
|
||||
opts.each do |key, val|
|
||||
flag = "-#{key}"
|
||||
|
||||
case val
|
||||
when Array
|
||||
need_bare = false
|
||||
val.each do |v|
|
||||
if undefish?(v)
|
||||
need_bare = true
|
||||
else
|
||||
lines << "#{flag}=#{v}"
|
||||
end
|
||||
end
|
||||
lines << flag if need_bare
|
||||
else
|
||||
if undefish?(val)
|
||||
lines << flag
|
||||
else
|
||||
lines << "#{flag}=#{val}"
|
||||
end
|
||||
end
|
||||
end
|
||||
%>
|
||||
OPTIONS="<%= lines.join(" \\\n ") %>"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=VictoriaMetrics vminsert service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=<%= @user %>
|
||||
Group=<%= @group %>
|
||||
Restart=always
|
||||
EnvironmentFile=<%= @vars_file %>
|
||||
ExecStart=<%= @exec_path %> $OPTIONS
|
||||
|
||||
PrivateTmp=yes
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=full
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user