diff --git a/modules/readarr/manifests/config.pp b/modules/readarr/manifests/config.pp new file mode 100644 index 0000000..4ba8065 --- /dev/null +++ b/modules/readarr/manifests/config.pp @@ -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', + } +} diff --git a/modules/readarr/manifests/init.pp b/modules/readarr/manifests/init.pp new file mode 100644 index 0000000..e29fe10 --- /dev/null +++ b/modules/readarr/manifests/init.pp @@ -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'] +} diff --git a/modules/readarr/manifests/install.pp b/modules/readarr/manifests/install.pp new file mode 100644 index 0000000..49280d1 --- /dev/null +++ b/modules/readarr/manifests/install.pp @@ -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}", + } +} diff --git a/modules/readarr/manifests/params.pp b/modules/readarr/manifests/params.pp new file mode 100644 index 0000000..61f06f9 --- /dev/null +++ b/modules/readarr/manifests/params.pp @@ -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', +) { } diff --git a/modules/readarr/manifests/service.pp b/modules/readarr/manifests/service.pp new file mode 100644 index 0000000..a3dabb4 --- /dev/null +++ b/modules/readarr/manifests/service.pp @@ -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"], + } + } +} diff --git a/modules/readarr/templates/readarr.service.erb b/modules/readarr/templates/readarr.service.erb new file mode 100644 index 0000000..fa79541 --- /dev/null +++ b/modules/readarr/templates/readarr.service.erb @@ -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 diff --git a/modules/readarr/templates/readarr_config.xml.erb b/modules/readarr/templates/readarr_config.xml.erb new file mode 100644 index 0000000..739204f --- /dev/null +++ b/modules/readarr/templates/readarr_config.xml.erb @@ -0,0 +1,16 @@ + + <%= @bind_address %> + <%= @port %> + <%= @ssl_port %> + <%= @enable_ssl.to_s.capitalize %> + <%= @launch_browser.to_s.capitalize %> + <%= @api_key %> + <%= @authentication_method %> + <%= @authentication_required %> + <%= @branch %> + <%= @log_level %> + <%= @ssl_cert_path || '' %> + <%= @ssl_cert_password || '' %> + <%= @url_base || '' %> + <%= @instance_name %> +<%- # No newline at the end of the file -%> diff --git a/site/roles/manifests/apps/media/readarr.pp b/site/roles/manifests/apps/media/readarr.pp new file mode 100644 index 0000000..0dfcf55 --- /dev/null +++ b/site/roles/manifests/apps/media/readarr.pp @@ -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 + } +}