From 50186eea6a0816040cc760696d7833c92031500a Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 19 Mar 2020 17:21:21 -0700 Subject: [PATCH] upgrades: Use internal scheduler instead of systemd timer - For setting up backports repositories. Using an internal scheduler is easy to maintain in the long run. - Run it more frequently when in developer mode. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/upgrades/__init__.py | 16 +++++++++++++++- .../freedombox-setup-repositories.service | 19 ------------------- .../freedombox-setup-repositories.timer | 12 ------------ 3 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.service delete mode 100644 plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.timer diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index d737f2eb1..de1f794a6 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -9,7 +9,7 @@ from django.utils.translation import ugettext_noop import plinth from plinth import actions from plinth import app as app_module -from plinth import menu +from plinth import cfg, glib, menu from .manifest import backup # noqa, pylint: disable=unused-import @@ -46,6 +46,11 @@ class UpgradesApp(app_module.App): self._show_new_release_notification() + # Check every day for setting up apt backport sources, every 3 minutes + # in debug mode. + interval = 180 if cfg.develop else 24 * 3600 + glib.schedule(interval, _setup_repositories) + def _show_new_release_notification(self): """When upgraded to new release, show a notification.""" from plinth.notification import Notification @@ -95,6 +100,10 @@ def setup(helper, old_version=None): # increment. helper.call('post', actions.superuser_run, 'upgrades', ['setup']) + # Try to setup apt repositories, if needed, if possible, on first install + # and on version increment. + helper.call('post', _setup_repositories, None) + def is_enabled(): """Return whether the module is enabled.""" @@ -110,3 +119,8 @@ def enable(): def disable(): """Disable the module.""" actions.superuser_run('upgrades', ['disable-auto']) + + +def _setup_repositories(data): + """Setup apt backport repositories.""" + actions.superuser_run('upgrades', ['setup-repositories']) diff --git a/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.service b/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.service deleted file mode 100644 index 99b1a4a22..000000000 --- a/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.service +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -[Unit] -Description=FreedomBox: Setup software repositories - -[Service] -ExecStart=/usr/share/plinth/actions/upgrades setup-repositories -Type=oneshot -LockPersonality=yes -PrivateDevices=yes -PrivateTmp=yes -ProtectControlGroups=yes -ProtectKernelLogs=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -ProtectSystem=yes -RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 -RestrictRealtime=yes -SystemCallArchitectures=native diff --git a/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.timer b/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.timer deleted file mode 100644 index 8702cebab..000000000 --- a/plinth/modules/upgrades/data/lib/systemd/system/freedombox-setup-repositories.timer +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -[Unit] -Description=FreedomBox: Daily check for setting up software repositories - -[Timer] -OnCalendar=daily -AccuracySec=12h -Persistent=true - -[Install] -WantedBy=multi-user.target