mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
upgrades: Check for held freedombox package daily
Guard against removing a hold while the package manager is busy. Test: 1. Place hold on freedombox package. 2. Wait 3 minutes in development mode. - Package is held. 3. Touch /var/lib/freedombox/package-held. 4. Wait 3 minutes in development mode. - Package is not held. - Flag is removed. Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
967d68cb92
commit
a24fcb2c90
@ -18,9 +18,8 @@ import apt.cache
|
|||||||
import apt_inst
|
import apt_inst
|
||||||
import apt_pkg
|
import apt_pkg
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth.action_utils import apt_hold_freedombox, run_apt_command
|
from plinth.action_utils import (apt_hold_freedombox, is_package_manager_busy,
|
||||||
|
run_apt_command)
|
||||||
LOCK_FILE = '/var/lib/dpkg/lock'
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -115,12 +114,10 @@ def _assert_managed_packages(module, packages):
|
|||||||
|
|
||||||
|
|
||||||
def subcommand_is_package_manager_busy(_):
|
def subcommand_is_package_manager_busy(_):
|
||||||
"""Return whether package manager is busy.
|
"""Check whether package manager is busy.
|
||||||
This command uses the `lsof` command to check whether the dpkg lock file
|
|
||||||
is open which indicates that the package manager is busy"""
|
An exit code of zero indicates that package manager is busy."""
|
||||||
try:
|
if not is_package_manager_busy():
|
||||||
subprocess.check_output(['lsof', LOCK_FILE])
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,8 @@ import time
|
|||||||
|
|
||||||
from plinth.action_utils import (apt_hold, apt_hold_flag, apt_hold_freedombox,
|
from plinth.action_utils import (apt_hold, apt_hold_flag, apt_hold_freedombox,
|
||||||
apt_unhold_freedombox, debconf_set_selections,
|
apt_unhold_freedombox, debconf_set_selections,
|
||||||
run_apt_command, service_daemon_reload,
|
is_package_manager_busy, run_apt_command,
|
||||||
service_restart)
|
service_daemon_reload, service_restart)
|
||||||
from plinth.modules.apache.components import check_url
|
from plinth.modules.apache.components import check_url
|
||||||
from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as
|
from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as
|
||||||
snapshot_is_supported, load_augeas as
|
snapshot_is_supported, load_augeas as
|
||||||
@ -145,7 +145,7 @@ def _run():
|
|||||||
|
|
||||||
# In case freedombox package was left in held state by an
|
# In case freedombox package was left in held state by an
|
||||||
# interrupted process, release it.
|
# interrupted process, release it.
|
||||||
if apt_hold_flag.exists():
|
if apt_hold_flag.exists() and not is_package_manager_busy():
|
||||||
apt_unhold_freedombox()
|
apt_unhold_freedombox()
|
||||||
|
|
||||||
subprocess.Popen(['systemctl', 'start', 'freedombox-manual-upgrade'],
|
subprocess.Popen(['systemctl', 'start', 'freedombox-manual-upgrade'],
|
||||||
@ -538,6 +538,11 @@ def subcommand_start_dist_upgrade(arguments):
|
|||||||
Check if a new stable release is available, and start dist-upgrade process
|
Check if a new stable release is available, and start dist-upgrade process
|
||||||
if updates are enabled.
|
if updates are enabled.
|
||||||
"""
|
"""
|
||||||
|
# In case freedombox package was left in held state by an
|
||||||
|
# interrupted process, release it.
|
||||||
|
if apt_hold_flag.exists() and not is_package_manager_busy():
|
||||||
|
apt_unhold_freedombox()
|
||||||
|
|
||||||
upgrade_ready, reason = _check_dist_upgrade(arguments.test)
|
upgrade_ready, reason = _check_dist_upgrade(arguments.test)
|
||||||
if upgrade_ready:
|
if upgrade_ready:
|
||||||
with open(DIST_UPGRADE_SERVICE_PATH, 'w') as service_file:
|
with open(DIST_UPGRADE_SERVICE_PATH, 'w') as service_file:
|
||||||
|
|||||||
@ -455,3 +455,15 @@ def apt_unhold_freedombox():
|
|||||||
subprocess.check_call(['apt-mark', 'unhold', 'freedombox'])
|
subprocess.check_call(['apt-mark', 'unhold', 'freedombox'])
|
||||||
if apt_hold_flag.exists():
|
if apt_hold_flag.exists():
|
||||||
apt_hold_flag.unlink()
|
apt_hold_flag.unlink()
|
||||||
|
|
||||||
|
|
||||||
|
def is_package_manager_busy():
|
||||||
|
"""Return whether package manager is busy.
|
||||||
|
This command uses the `lsof` command to check whether the dpkg lock file
|
||||||
|
is open which indicates that the package manager is busy"""
|
||||||
|
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||||
|
try:
|
||||||
|
subprocess.check_output(['lsof', LOCK_FILE])
|
||||||
|
return True
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user