From 3c85846fa2edd8d2f49de844a4c9bff84208ff35 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Fri, 15 May 2020 12:15:58 -0400 Subject: [PATCH] minidlna: Move sysctl config to /etc/sysctl.d/50-freedombox.conf /etc/sysctl.conf is owned by procps package. Test: Run minidlna install on fresh image. - /etc/sysctl.conf is not modified. - /etc/sysctl.d/50-freedombox.conf has the expected content. - /proc/sys/fs/inotify/max_user_watches contains 100000. - Running with these changes upgrades app version and triggers a setup. Changes in /etc/sysctl.conf are removed. After undoing the changes /etc/sysctl.conf is identical to pristine version installed from procps package. This can be obtained by running; rm -f /etc/sysctl.conf ; apt install --reinstall procps -o Dpkg::Options::=--force-confmiss Closes #1802. Signed-off-by: James Valleroy [sunil: Undo changes done in /etc/sysctl.conf in older versions] [sunil: Increment app version to trigger configuration migration] [sunil: Ensure that app is not re-enabled during migration] Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/minidlna | 36 ++++++++++++++++++++++------- plinth/modules/minidlna/__init__.py | 5 ++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/actions/minidlna b/actions/minidlna index 70f28d657..9afed64f7 100755 --- a/actions/minidlna +++ b/actions/minidlna @@ -15,6 +15,11 @@ from plinth.utils import grep CONFIG_PATH = '/etc/minidlna.conf' +SYSCTL_CONF = '''# This file is managed and overwritten by FreedomBox. +# Helps minidlna monitor changes in large media directories +fs.inotify.max_user_watches = 100000 +''' + def parse_arguments(): """Return parsed command line arguments as dictionary.""" @@ -33,19 +38,34 @@ def parse_arguments(): return parser.parse_args() +def _undo_old_configuration_changes(): + """Restore /etc/sysctl.conf to before our changes. + + Older version of minidlna app in FreedomBox < 20.9 wrote to + /etc/sysctl.conf directly. This will cause conffile prompt during upgrade + of procps package. Undo the changes so that upgrade can happen smoothly. + + """ + aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + + augeas.Augeas.NO_MODL_AUTOLOAD) + aug.set('/augeas/load/Sysctl/lens', 'Sysctl.lns') + aug.set('/augeas/load/Sysctl/incl[last() + 1]', '/etc/sysctl.conf') + aug.load() + + key_path = '/files/etc/sysctl.conf/fs.inotify.max_user_watches' + if aug.get(key_path) == '100000': + aug.remove(key_path) + aug.save() + + def subcommand_setup(arguments): """ Increase inotify watches per folder to allow minidlna to monitor changes in large media-dirs. """ - aug = augeas.Augeas( - flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD) - aug.set('/augeas/load/Sysctl/lens', 'Sysctl.lns') - aug.set('/augeas/load/Sysctl/incl[last() + 1]', '/etc/sysctl.conf') - aug.load() - - aug.set('/files/etc/sysctl.conf/fs.inotify.max_user_watches', '100000') - aug.save() + _undo_old_configuration_changes() + with open('/etc/sysctl.d/50-freedombox-minidlna.conf', 'w') as conf: + conf.write(SYSCTL_CONF) subprocess.run(['systemctl', 'restart', 'systemd-sysctl'], check=True) diff --git a/plinth/modules/minidlna/__init__.py b/plinth/modules/minidlna/__init__.py index 778b971b5..e888d0176 100644 --- a/plinth/modules/minidlna/__init__.py +++ b/plinth/modules/minidlna/__init__.py @@ -13,7 +13,7 @@ from plinth.modules.users.components import UsersAndGroups from .manifest import backup, clients # noqa -version = 1 +version = 2 managed_packages = ['minidlna'] @@ -94,4 +94,5 @@ def setup(helper, old_version=None): """Install and configure the package""" helper.install(managed_packages) helper.call('post', actions.superuser_run, 'minidlna', ['setup']) - helper.call('post', app.enable) + if not old_version: + helper.call('post', app.enable)