diff --git a/modules/lidarr/manifests/config.pp b/modules/lidarr/manifests/config.pp new file mode 100644 index 0000000..10cc689 --- /dev/null +++ b/modules/lidarr/manifests/config.pp @@ -0,0 +1,27 @@ +class lidarr::config ( + $user = $lidarr::params::user, + $group = $lidarr::params::group, + $base_path = $lidarr::params::base_path, + $bind_address = $lidarr::bind_address, + $port = $lidarr::port, + $ssl_port = $lidarr::ssl_port, + $enable_ssl = $lidarr::enable_ssl, + $launch_browser = $lidarr::launch_browser, + $api_key = $lidarr::api_key, + $authentication_method = $lidarr::authentication_method, + $authentication_required = $lidarr::authentication_required, + $branch = $lidarr::branch, + $log_level = $lidarr::log_level, + $ssl_cert_path = $lidarr::ssl_cert_path, + $ssl_cert_password = $lidarr::ssl_cert_password, + $url_base = $lidarr::url_base, + $instance_name = $lidarr::instance_name, +) { + file { "${base_path}/config.xml": + ensure => file, + content => template('lidarr/lidarr_config.xml.erb'), + owner => $user, + group => $group, + mode => '0644', + } +} diff --git a/modules/lidarr/manifests/init.pp b/modules/lidarr/manifests/init.pp new file mode 100644 index 0000000..a97a02a --- /dev/null +++ b/modules/lidarr/manifests/init.pp @@ -0,0 +1,36 @@ +# manage lidarr +class lidarr ( + $packages = $lidarr::params::packages, + $user = $lidarr::params::user, + $group = $lidarr::params::group, + $base_path = $lidarr::params::base_path, + $install_path = $lidarr::params::install_path, + $config_folder = $lidarr::params::config_folder, + $app_folder = $lidarr::params::app_folder, + $archive_name = $lidarr::params::archive_name, + $archive_url = $lidarr::params::archive_url, + $executable = $lidarr::params::executable, + $service_enable = $lidarr::params::service_enable, + $service_name = $lidarr::params::service_name, + $bind_address = $lidarr::params::bind_address, + $port = $lidarr::params::port, + $ssl_port = $lidarr::params::ssl_port, + $enable_ssl = $lidarr::params::enable_ssl, + $launch_browser = $lidarr::params::launch_browser, + $api_key = $lidarr::params::api_key, + $authentication_method = $lidarr::params::authentication_method, + $authentication_required = $lidarr::params::authentication_required, + $branch = $lidarr::params::branch, + $log_level = $lidarr::params::log_level, + $ssl_cert_path = $lidarr::params::ssl_cert_path, + $ssl_cert_password = $lidarr::params::ssl_cert_password, + $url_base = $lidarr::params::url_base, + $instance_name = $lidarr::params::instance_name, +) inherits lidarr::params { + + include lidarr::install + include lidarr::config + include lidarr::service + + Class['lidarr::install'] -> Class['lidarr::config'] -> Class['lidarr::service'] +} diff --git a/modules/lidarr/manifests/install.pp b/modules/lidarr/manifests/install.pp new file mode 100644 index 0000000..ae962e5 --- /dev/null +++ b/modules/lidarr/manifests/install.pp @@ -0,0 +1,58 @@ +# instsall lidarr +class lidarr::install ( + $packages = $lidarr::packages, + $user = $lidarr::user, + $group = $lidarr::group, + $base_path = $lidarr::base_path, + $install_path = $lidarr::install_path, + $config_folder = $lidarr::config_folder, + $app_folder = $lidarr::app_folder, + $archive_name = $lidarr::archive_name, + $archive_url = $lidarr::archive_url, + $executable = $lidarr::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_lidarr_files'], + } + + exec { 'move_lidarr_files': + command => "/usr/bin/mv ${install_path}/Lidarr/* ${install_path}", + creates => "${install_path}/${executable}", + } +} diff --git a/modules/lidarr/manifests/params.pp b/modules/lidarr/manifests/params.pp new file mode 100644 index 0000000..d783d58 --- /dev/null +++ b/modules/lidarr/manifests/params.pp @@ -0,0 +1,49 @@ +# lidarr params +class lidarr::params ( + Array[String] $packages = [ + 'mediainfo', + 'libzen', + 'libmediainfo', + 'gettext', + 'sqlite.x86_64', + 'par2cmdline', + 'python3-feedparser', + 'python3-configobj', + 'python3-cheetah', + 'python3-dbus', + 'libxslt-devel', + 'libchromaprint', + ], + String $user = 'lidarr', + String $group = 'lidarr', + Stdlib::Absolutepath $base_path = '/opt/lidarr', + Stdlib::Absolutepath $install_path = '/opt/lidarr/bin', + Stdlib::Absolutepath $config_folder = '/home/lidarr/.config', + Stdlib::Absolutepath $app_folder = '/home/lidarr/.config/Lidarr', + String $archive_version = '2.3.3', + String $archive_name = 'Lidarr.master.linux-core-x64.tar.gz', + Stdlib::HTTPUrl $archive_url = "https://git.query.consul/api/packages/unkinben/generic/lidarr/${archive_version}/", + String $executable = 'Lidarr/Lidarr', + String $service_name = 'lidarr', + Boolean $service_enable = true, + + # params for the configuration file + Stdlib::Host $bind_address = '127.0.0.1', + Stdlib::Port $port = 8686, + Stdlib::Port $ssl_port = 9696, + 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 = 'lidarr', +) { } diff --git a/modules/lidarr/manifests/service.pp b/modules/lidarr/manifests/service.pp new file mode 100644 index 0000000..a0e2eeb --- /dev/null +++ b/modules/lidarr/manifests/service.pp @@ -0,0 +1,21 @@ +# manage lidarr service +class lidarr::service ( + $service_enable = $lidarr::service_enable, + $service_name = $lidarr::service_name, + $user = $lidarr::user, + $group = $lidarr::user, + $install_path = $lidarr::install_path, + $executable = $lidarr::executable, + $base_path = $lidarr::base_path, +) { + if $service_enable { + include ::systemd + + systemd::unit_file { "${service_name}.service": + content => template('lidarr/lidarr.service.erb'), + enable => true, + active => true, + subscribe => File["${base_path}/config.xml"], + } + } +} diff --git a/modules/lidarr/templates/lidarr.service.erb b/modules/lidarr/templates/lidarr.service.erb new file mode 100644 index 0000000..fa79541 --- /dev/null +++ b/modules/lidarr/templates/lidarr.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/lidarr/templates/lidarr_config.xml.erb b/modules/lidarr/templates/lidarr_config.xml.erb new file mode 100644 index 0000000..739204f --- /dev/null +++ b/modules/lidarr/templates/lidarr_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 -%>