mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
setup: Disable install/upgrade when dpkg/apt is running
Show a warning message that a package manager is running. This prevents users from getting an installation error just because another installation/upgrade is running. Closes: #625.
This commit is contained in:
parent
6a53dd015e
commit
76a63d102b
@ -28,6 +28,8 @@ import sys
|
||||
|
||||
from plinth import cfg
|
||||
|
||||
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
@ -41,6 +43,8 @@ def parse_arguments():
|
||||
'module', help='name of module for which package is being installed')
|
||||
subparser.add_argument(
|
||||
'packages', nargs='+', help='list of packages to install')
|
||||
subparsers.add_parser('is-package-manager-busy',
|
||||
help='Return whether package manager is busy')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
@ -94,6 +98,14 @@ def _assert_managed_packages(module, packages):
|
||||
assert package in module.managed_packages
|
||||
|
||||
|
||||
def subcommand_is_package_manager_busy(_):
|
||||
"""Return whether package manager is busy."""
|
||||
try:
|
||||
subprocess.check_output(['lsof', LOCK_FILE])
|
||||
except subprocess.CalledProcessError:
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@ -28,7 +28,6 @@ import sys
|
||||
|
||||
CONF_FILE = '/etc/apt/apt.conf.d/50unattended-upgrades'
|
||||
AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades'
|
||||
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||
LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
|
||||
|
||||
|
||||
@ -42,8 +41,6 @@ def parse_arguments():
|
||||
help='Check if automatic upgrades are enabled')
|
||||
subparsers.add_parser('enable-auto', help='Enable automatic upgrades')
|
||||
subparsers.add_parser('disable-auto', help='Disable automatic upgrades.')
|
||||
subparsers.add_parser('is-package-manager-busy',
|
||||
help='Return whether package manager is busy')
|
||||
subparsers.add_parser('get-log', help='Print the automatic upgrades log')
|
||||
|
||||
subparsers.required = True
|
||||
@ -129,14 +126,6 @@ def setup():
|
||||
conffile.write(' "origin=Debian";\n')
|
||||
|
||||
|
||||
def subcommand_is_package_manager_busy(_):
|
||||
"""Return whether package manager is busy."""
|
||||
try:
|
||||
subprocess.check_output(['lsof', LOCK_FILE])
|
||||
except subprocess.CalledProcessError:
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def subcommand_get_log(_):
|
||||
"""Print the automatic upgrades log."""
|
||||
try:
|
||||
|
||||
@ -84,11 +84,10 @@ class UpgradesConfigurationView(FormView):
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
||||
def is_package_manager_busy():
|
||||
"""Return whether a package manager is running."""
|
||||
try:
|
||||
actions.superuser_run('upgrades', ['is-package-manager-busy'])
|
||||
actions.superuser_run('packages', ['is-package-manager-busy'])
|
||||
return True
|
||||
except actions.ActionError:
|
||||
return False
|
||||
|
||||
@ -50,8 +50,19 @@
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
value="{% trans "Install" %}" />
|
||||
{% if package_manager_is_busy %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{% blocktrans trimmed %}
|
||||
Another installation or upgrade is already running.
|
||||
Please wait for a few moments before trying again.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
disabled="disabled" value="{% trans "Install" %}" />
|
||||
{% else %}
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
value="{% trans "Install" %}" />
|
||||
{% endif %}
|
||||
</form>
|
||||
{% elif setup_helper.get_state == 'needs-update' %}
|
||||
<p>
|
||||
@ -63,8 +74,19 @@
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
value="{% trans "Update" %}" />
|
||||
{% if package_manager_is_busy %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{% blocktrans trimmed %}
|
||||
Another installation or upgrade is already running.
|
||||
Please wait for a few moments before trying again.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
disabled="disabled" value="{% trans "Install" %}" />
|
||||
{% else %}
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
value="{% trans "Update" %}" />
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ import time
|
||||
|
||||
from . import forms, frontpage
|
||||
import plinth
|
||||
from plinth import actions
|
||||
|
||||
|
||||
@public
|
||||
@ -208,8 +209,17 @@ class SetupView(TemplateView):
|
||||
"""Return the context data rendering the template."""
|
||||
context = super(SetupView, self).get_context_data(**kwargs)
|
||||
context['setup_helper'] = self.kwargs['setup_helper']
|
||||
context['package_manager_is_busy'] = self.is_package_manager_busy()
|
||||
return context
|
||||
|
||||
def is_package_manager_busy(self):
|
||||
"""Return whether a package manager is running."""
|
||||
try:
|
||||
actions.superuser_run('packages', ['is-package-manager-busy'])
|
||||
return True
|
||||
except actions.ActionError:
|
||||
return False
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
"""Handle installing/upgrading applications.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user