feat: add readarr module

- add media::readarr role
This commit is contained in:
Ben Vincent 2024-06-27 21:21:18 +10:00
parent bbf9944ef5
commit 0b7f07692c
8 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,27 @@
class readarr::config (
$user = $readarr::params::user,
$group = $readarr::params::group,
$base_path = $readarr::params::base_path,
$bind_address = $readarr::bind_address,
$port = $readarr::port,
$ssl_port = $readarr::ssl_port,
$enable_ssl = $readarr::enable_ssl,
$launch_browser = $readarr::launch_browser,
$api_key = $readarr::api_key,
$authentication_method = $readarr::authentication_method,
$authentication_required = $readarr::authentication_required,
$branch = $readarr::branch,
$log_level = $readarr::log_level,
$ssl_cert_path = $readarr::ssl_cert_path,
$ssl_cert_password = $readarr::ssl_cert_password,
$url_base = $readarr::url_base,
$instance_name = $readarr::instance_name,
) {
file { "${base_path}/config.xml":
ensure => file,
content => template('readarr/readarr_config.xml.erb'),
owner => $user,
group => $group,
mode => '0644',
}
}

View File

@ -0,0 +1,36 @@
# manage readarr
class readarr (
$packages = $readarr::params::packages,
$user = $readarr::params::user,
$group = $readarr::params::group,
$base_path = $readarr::params::base_path,
$install_path = $readarr::params::install_path,
$config_folder = $readarr::params::config_folder,
$app_folder = $readarr::params::app_folder,
$archive_name = $readarr::params::archive_name,
$archive_url = $readarr::params::archive_url,
$executable = $readarr::params::executable,
$service_enable = $readarr::params::service_enable,
$service_name = $readarr::params::service_name,
$bind_address = $readarr::params::bind_address,
$port = $readarr::params::port,
$ssl_port = $readarr::params::ssl_port,
$enable_ssl = $readarr::params::enable_ssl,
$launch_browser = $readarr::params::launch_browser,
$api_key = $readarr::params::api_key,
$authentication_method = $readarr::params::authentication_method,
$authentication_required = $readarr::params::authentication_required,
$branch = $readarr::params::branch,
$log_level = $readarr::params::log_level,
$ssl_cert_path = $readarr::params::ssl_cert_path,
$ssl_cert_password = $readarr::params::ssl_cert_password,
$url_base = $readarr::params::url_base,
$instance_name = $readarr::params::instance_name,
) inherits readarr::params {
include readarr::install
include readarr::config
include readarr::service
Class['readarr::install'] -> Class['readarr::config'] -> Class['readarr::service']
}

View File

@ -0,0 +1,58 @@
# instsall readarr
class readarr::install (
$packages = $readarr::packages,
$user = $readarr::user,
$group = $readarr::group,
$base_path = $readarr::base_path,
$install_path = $readarr::install_path,
$config_folder = $readarr::config_folder,
$app_folder = $readarr::app_folder,
$archive_name = $readarr::archive_name,
$archive_url = $readarr::archive_url,
$executable = $readarr::executable,
) {
$_packages = $packages ? {
Array => true,
default => false,
}
if $_packages {
ensure_packages($packages, {ensure => 'installed'})
}
group { $group:
ensure => present,
}
user { $user:
ensure => present,
shell => '/sbin/nologin',
groups => $group,
managehome => true,
}
file { [ $base_path, $install_path, $config_folder, $app_folder ]:
ensure => directory,
owner => $user,
group => $group,
}
archive { $archive_name:
path => "/tmp/${archive_name}",
source => "${archive_url}${archive_name}",
extract => true,
extract_path => $install_path,
creates => "${install_path}/${executable}",
cleanup => true,
require => File[$install_path],
user => $user,
group => $group,
notify => Exec['move_readarr_files'],
}
exec { 'move_readarr_files':
command => "/usr/bin/mv ${install_path}/Readarr/* ${install_path}",
creates => "${install_path}/${executable}",
}
}

View File

@ -0,0 +1,48 @@
# readarr params
class readarr::params (
Array[String] $packages = [
'mediainfo',
'libzen',
'libmediainfo',
'gettext',
'sqlite.x86_64',
'par2cmdline',
'python3-feedparser',
'python3-configobj',
'python3-cheetah',
'python3-dbus',
'libxslt-devel',
],
String $user = 'readarr',
String $group = 'readarr',
Stdlib::Absolutepath $base_path = '/opt/readarr',
Stdlib::Absolutepath $install_path = '/opt/readarr/bin',
Stdlib::Absolutepath $config_folder = '/home/readarr/.config',
Stdlib::Absolutepath $app_folder = '/home/readarr/.config/Readarr',
String $archive_version = '0.3.28',
String $archive_name = 'Readarr.develop.linux-core-x64.tar.gz',
Stdlib::HTTPUrl $archive_url = "https://git.query.consul/api/packages/unkinben/generic/readarr/${archive_version}/",
String $executable = 'Readarr/Readarr',
String $service_name = 'readarr',
Boolean $service_enable = true,
# params for the configuration file
Stdlib::Host $bind_address = '127.0.0.1',
Stdlib::Port $port = 8787,
Stdlib::Port $ssl_port = 9797,
Boolean $enable_ssl = false,
Boolean $launch_browser = true,
String $api_key = '32-digit-random-string-goes-here',
Enum[
'Forms',
'Basic',
'External'
] $authentication_method = 'External',
Enum['Enabled', 'Disabled'] $authentication_required = 'Enabled',
String $branch = 'main',
Enum['debug', 'info', 'warn', 'error', 'fatal'] $log_level = 'info',
Optional[String] $ssl_cert_path = undef,
Optional[String] $ssl_cert_password = undef,
Optional[String] $url_base = undef,
String $instance_name = 'readarr',
) { }

View File

@ -0,0 +1,21 @@
# manage readarr service
class readarr::service (
$service_enable = $readarr::service_enable,
$service_name = $readarr::service_name,
$user = $readarr::user,
$group = $readarr::user,
$install_path = $readarr::install_path,
$executable = $readarr::executable,
$base_path = $readarr::base_path,
) {
if $service_enable {
include ::systemd
systemd::unit_file { "${service_name}.service":
content => template('readarr/readarr.service.erb'),
enable => true,
active => true,
subscribe => File["${base_path}/config.xml"],
}
}
}

View File

@ -0,0 +1,14 @@
[Unit]
Description=<%= @service_name %> Daemon
After=syslog.target network.target
[Service]
User=<%= @user %>
Group=<%= @group %>
Type=simple
ExecStart=<%= @install_path %>/<%= @executable %> -nobrowser -data=<%= @base_path %>
KillMode=process
Restart=on-failure
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,16 @@
<Config>
<BindAddress><%= @bind_address %></BindAddress>
<Port><%= @port %></Port>
<SslPort><%= @ssl_port %></SslPort>
<EnableSsl><%= @enable_ssl.to_s.capitalize %></EnableSsl>
<LaunchBrowser><%= @launch_browser.to_s.capitalize %></LaunchBrowser>
<ApiKey><%= @api_key %></ApiKey>
<AuthenticationMethod><%= @authentication_method %></AuthenticationMethod>
<AuthenticationRequired><%= @authentication_required %></AuthenticationRequired>
<Branch><%= @branch %></Branch>
<LogLevel><%= @log_level %></LogLevel>
<SslCertPath><%= @ssl_cert_path || '' %></SslCertPath>
<SslCertPassword><%= @ssl_cert_password || '' %></SslCertPassword>
<UrlBase><%= @url_base || '' %></UrlBase>
<InstanceName><%= @instance_name %></InstanceName>
</Config><%- # No newline at the end of the file -%>

View File

@ -0,0 +1,10 @@
# readarr server profile
class roles::apps::media::readarr {
if $facts['firstrun'] {
include profiles::defaults
include profiles::firstrun::init
}else{
include profiles::defaults
include profiles::base
}
}