[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#838369: apt: apt-daily's call to apt-get check prevents u-a from repairing the dpkg database



Control: tag -1 patch

Hi,

As discussed via IRC, attached patches:
* add a --fix-only option to unattended-upgrades that makes it call
dpkg --configure -a if needed
* make apt call u-u with the new option, replacing the call to apt-get check

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net-
From 27addc6855d83a50adea9d41bfe1ead3f8f7eb9e Mon Sep 17 00:00:00 2001
From: Raphael Geissert <geissert@debian.org>
Date: Mon, 19 Dec 2016 15:10:23 +0100
Subject: [PATCH] Add a --fix-only option

---
 unattended-upgrade |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/unattended-upgrade b/unattended-upgrade
index e68d3e9..3a194d6 100755
--- a/unattended-upgrade
+++ b/unattended-upgrade
@@ -1197,7 +1197,7 @@ def main(options, rootdir=""):
     mem_log = _setup_logging(options)
 
     # check if today is a patch day
-    if not is_update_day():
+    if not is_update_day() and not options.fix_only:
         return
 
     # format (origin, archive), e.g. ("Ubuntu","dapper-security")
@@ -1249,6 +1249,10 @@ def main(options, rootdir=""):
             logging.debug("Unclean dpkg state, but locked, another package "
                           "manager working?")
 
+    if options.fix_only:
+        logging.info("Option --fix-only given, *not* doing anything else")
+        return
+
     # check and get lock
     try:
         apt_pkg.pkgsystem_lock()
@@ -1516,6 +1520,9 @@ if __name__ == "__main__":
     parser.add_option("", "--dry-run",
                       action="store_true", default=False,
                       help=_("Simulation, download but do not install"))
+    parser.add_option("", "--fix-only",
+                      action="store_true", default=False,
+                      help=_("Fix the dpkg database if needed, do not download nor install"))
     parser.add_option("", "--minimal-upgrade-steps",
                       action="store_true", default=False,
                       help=_("Upgrade in minimal steps (and allow "
-- 
1.7.2.5

From e5d9edc147c1c1a3be030ee47de89daf6953beb2 Mon Sep 17 00:00:00 2001
From: Raphael Geissert <geissert@debian.org>
Date: Thu, 15 Dec 2016 16:46:11 +0100
Subject: [PATCH] apt.systemd.daily: call unattended-upgrade --fix-only

Drop the call to apt-get check as it prevents apt-daily from working
in case the dpkg database is in a dirty state.  The check was meant to
detect and exit in case the lock was being held by another process,
but it would offer no guarantee later on.

Replace it with a call to u-u --fix-only, a new option, to repair the
dpkg database if needed.

Closes: #838369
---
 debian/apt.systemd.daily |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily
index 03d41ba..52004f5 100755
--- a/debian/apt.systemd.daily
+++ b/debian/apt.systemd.daily
@@ -337,10 +337,16 @@ if [ "$VERBOSE" -ge 3 ]; then
     set -x
 fi
 
-# check if we can lock the cache and if the cache is clean
-if which apt-get >/dev/null 2>&1 && ! eval apt-get check $XAPTOPT $XSTDERR ; then
-    debug_echo "error encountered in cron job with \"apt-get check\"."
-    exit 0
+# call unattended-upgrade to fix the dpkg database if needed
+if which unattended-upgrade >/dev/null 2>&1 && ! eval unattended-upgrade --fix-only $XSTDOUT $XSTDERR ; then
+    exit_code=$?
+
+    # if u-u doesn't know about --fix-only ignore the error
+    # (OptionParser exits with code 2 in that case)
+    if [ $exit_code -ne 2 ]; then
+	debug_echo "error encountered in cron job with \"unattended-upgrade --fix-only\"."
+	exit $exit_code
+    fi
 fi
 
 # Global current time in seconds since 1970-01-01 00:00:00 UTC
-- 
1.7.2.5


Reply to: