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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-03-19 17:21:21 -07:00 committed by James Valleroy
parent 94883b3c92
commit 50186eea6a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 15 additions and 32 deletions

View File

@ -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'])

View File

@ -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

View File

@ -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