puppet-prod/site/profiles/manifests/media/jellyfin.pp
Ben Vincent b3347f9226 chore: migrate media applications (#299)
- migrate media applications to new cephfs pool + incus
- enable exporting haproxy
- move ceph-client-setup to only apply to non-lxc hosts
- ensure unrar is installed for nzbget
- updated jellyfin use of data_dir
- set lxc instances for jellyfin to use /shared/apps/jellyfin

Reviewed-on: https://git.query.consul/unkinben/puppet-prod/pulls/299
2025-05-25 20:27:17 +10:00

120 lines
3.8 KiB
Puppet

# profiles::media::jellyfin
class profiles::media::jellyfin (
Stdlib::Absolutepath $media_root = '/shared/media',
Stdlib::Absolutepath $data_dir = '/data/jellyfin',
Stdlib::Absolutepath $lib_dir = "${data_dir}/var/lib",
Stdlib::Absolutepath $cache_dir = "${data_dir}/var/cache",
Stdlib::Absolutepath $config_dir = "${data_dir}/etc",
Stdlib::Absolutepath $log_dir = "${data_dir}/var/log",
Stdlib::Absolutepath $ffmpeg_path = '/usr/local/bin/ffmpeg',
Stdlib::Absolutepath $sysconfig_file = '/etc/sysconfig/jellyfin',
Stdlib::Absolutepath $migration_flag = '/etc/sysconfig/jellyfin_migration_done',
String $service_name = 'jellyfin',
Boolean $migrate_data = true,
) {
if $facts['virtual'] != 'lxc' {
include profiles::ceph::client
# manage the sharedvol
profiles::storage::cephfsvol {"${::facts['networking']['fqdn']}_media":
mount => $media_root,
keyring => '/etc/ceph/ceph.client.media.keyring',
cephfs_name => 'media',
cephfs_fs => 'mediafs',
require => Profiles::Ceph::Keyring['media'],
}
# export haproxy balancemember
profiles::haproxy::balancemember { "${facts['networking']['fqdn']}_443":
service => 'be_jellyfin',
ports => [443],
options => [
"cookie ${facts['networking']['hostname']}",
'ssl',
'verify none',
'check',
'inter 2s',
'rise 3',
'fall 2',
]
}
}
mkdir::p {[$data_dir, $lib_dir, $cache_dir, $config_dir, $log_dir]:}
-> file { [$data_dir, $lib_dir, $cache_dir, $config_dir, $log_dir]:
ensure => directory,
owner => 'jellyfin',
group => 'jellyfin',
mode => '0755',
}
if $migrate_data and ! $facts['jellyfin_migration_done'] {
exec { "stop-${service_name}":
command => "/usr/bin/systemctl stop ${service_name}",
require => File[$sysconfig_file],
}
exec { 'move-jellyfin-lib':
command => "/usr/bin/rsync -av /var/lib/jellyfin/ ${lib_dir}/ && rm -rf /var/lib/jellyfin",
creates => "${lib_dir}/config",
require => [File[$lib_dir], Exec["stop-${service_name}"]],
}
exec { 'move-jellyfin-cache':
command => "/usr/bin/rsync -av /var/cache/jellyfin/ ${cache_dir}/ && rm -rf /var/cache/jellyfin",
creates => "${cache_dir}/config",
require => [File[$cache_dir], Exec["stop-${service_name}"]],
}
exec { 'move-jellyfin-config':
command => "/usr/bin/rsync -av /etc/jellyfin/ ${config_dir}/ && rm -rf /etc/jellyfin",
creates => "${config_dir}/config",
require => [File[$config_dir], Exec["stop-${service_name}"]],
}
exec { 'move-jellyfin-log':
command => "/usr/bin/rsync -av /var/log/jellyfin/ ${log_dir}/ && rm -rf /var/log/jellyfin",
creates => "${log_dir}/config",
require => [File[$log_dir], Exec["stop-${service_name}"]],
}
exec { 'create-migration-flag':
command => "/usr/bin/touch ${migration_flag}",
creates => $migration_flag,
require => [
Exec['move-jellyfin-lib'],
Exec['move-jellyfin-cache'],
Exec['move-jellyfin-config'],
Exec['move-jellyfin-log']
],
}
exec { "start-${service_name}":
command => "/usr/bin/systemctl start ${service_name}",
require => Exec['create-migration-flag'],
}
}
file { $sysconfig_file:
ensure => file,
content => template('profiles/jellyfin/sysconfig.erb'),
notify => [
Systemd::Daemon_reload["${service_name}_service"],
Service[$service_name]
],
}
file { '/etc/systemd/system/jellyfin.service.d/override.conf':
ensure => file,
content => template('profiles/jellyfin/override.conf.erb'),
notify => [
Systemd::Daemon_reload["${service_name}_service"],
Service[$service_name]
],
}
systemd::daemon_reload {"${service_name}_service":}
}