From 33b85ff0de0e5d50ce820d115d1f9e3699e2aaef Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Fri, 8 Jan 2021 16:10:44 +0100 Subject: [PATCH] bundles/transmission: add bundle, add to home.downloadhelper --- bundles/transmission/items.py | 21 +++++++++ bundles/transmission/metadata.py | 79 ++++++++++++++++++++++++++++++++ nodes/home/downloadhelper.py | 10 ++++ 3 files changed, 110 insertions(+) create mode 100644 bundles/transmission/items.py create mode 100644 bundles/transmission/metadata.py diff --git a/bundles/transmission/items.py b/bundles/transmission/items.py new file mode 100644 index 0000000..f00b1ca --- /dev/null +++ b/bundles/transmission/items.py @@ -0,0 +1,21 @@ +from bundlewrap.metadata import metadata_to_json + +# transmission overwrites this on a restart. As of 2021-01 there's no +# way of disabling that. +files = { + '/etc/transmission-daemon/settings.json': { + 'content': metadata_to_json(node.metadata['transmission']['config']), + 'mode': '0444', + 'triggers': { + 'svc_systemd:transmission-daemon:reload', + }, + }, +} + +svc_systemd = { + 'transmission-daemon': { + 'needs': { + 'pkg_apt:transmission-daemon', + }, + }, +} diff --git a/bundles/transmission/metadata.py b/bundles/transmission/metadata.py new file mode 100644 index 0000000..7e63c33 --- /dev/null +++ b/bundles/transmission/metadata.py @@ -0,0 +1,79 @@ +defaults = { + 'apt': { + 'packages': { + 'transmission-daemon': {}, + 'transmission-remote-cli': {}, + }, + }, + 'icinga2_api': { + 'transmission': { + 'services': { + 'TRANSMISSION PROCESS': { + 'command_on_monitored_host': '/usr/lib/nagios/plugins/check_procs -a transmission-daemon -c 1:', + }, + }, + }, + }, + 'transmission': { + 'config': { + 'message-level': 2, + 'peer-port': 51413, + 'port-forwarding-enabled': False, + 'rename-partial-files': True, + 'rpc-authentication-required': False, + 'rpc-bind-address': '0.0.0.0', + 'rpc-enabled': True, + 'rpc-host-whitelist-enabled': False, + 'rpc-port': 9091, + 'rpc-url': '/transmission/', + 'rpc-whitelist-enabled': False, + 'start-added-torrents': True, + }, + }, +} + + +@metadata_reactor.provides( + 'iptables/bundle_rules/transmission', +) +def iptables(metadata): + interfaces = metadata.get('transmission/webinterface-on-interfaces', set()) + iptables = [] + + iptables.append('iptables_both -A INPUT -p udp --dport {} -j ACCEPT'.format( + metadata.get('transmission/config/peer-port'), + )) + + for iface in sorted(interfaces): + iptables.append('iptables_both -A INPUT -i {} -p tcp --dport {} -j ACCEPT'.format( + iface, + metadata.get('transmission/config/rpc-port'), + )) + + return { + 'iptables': { + 'bundle_rules': { + 'transmission': iptables, + }, + }, + } + + +@metadata_reactor.provides( + 'icinga2_api/transmission/services', +) +def icinga_web(metadata): + port = metadata.get('transmission/config/rpc-port') + path = metadata.get('transmission/config/rpc-url') + + return { + 'icinga2_api': { + 'transmission': { + 'services': { + 'TRANSMISSION WEB INTERFACE': { + 'command_on_monitored_host': f'/usr/local/share/icinga/plugins/check_http_url_for_string http://127.0.0.1:{port}{path} "Transmission"', + }, + }, + }, + }, + } diff --git a/nodes/home/downloadhelper.py b/nodes/home/downloadhelper.py index 108ff1c..cbd73cc 100644 --- a/nodes/home/downloadhelper.py +++ b/nodes/home/downloadhelper.py @@ -3,6 +3,7 @@ nodes['home.downloadhelper'] = { 'bundles': { 'iptables', 'nfs-client', + 'transmission', }, 'groups': { 'debian-buster', @@ -40,5 +41,14 @@ nodes['home.downloadhelper'] = { }, }, }, + 'transmission': { + 'config': { + 'download-dir': '/mnt/nas', + 'download-queue-size': 10, + }, + 'webinterface-on-interfaces': { + 'enp1s0.42', + }, + }, }, }