]> git.saurik.com Git - apt.git/commitdiff
Use the ConditionACPower feature of systemd in the apt-daily service
authorNicolas Le Cam <niko.lecam@gmail.com>
Wed, 22 Jun 2016 19:39:38 +0000 (21:39 +0200)
committerJulian Andres Klode <jak@debian.org>
Mon, 27 Jun 2016 09:22:02 +0000 (11:22 +0200)
.. instead of hardcoding the functionnality in the apt.systemd.daily
script.

Also make the compatibility cron job provide the same functionnality
for systems that do not use systemd.

Closes: #827930
debian/apt-daily.service
debian/apt.apt-compat.cron.daily
debian/apt.systemd.daily

index 941263d05151eb3d4dee9139e30a59bdb1c995cd..904ed5d5108240dc0c8f2025ac03aa645c0d4678 100644 (file)
@@ -1,6 +1,7 @@
 [Unit]
 Description=Daily apt activities
 Documentation=man:apt(8)
+ConditionACPower=true
 
 [Service]
 Type=oneshot
index 1ea843008590fa5e54119c9b68ac39f19a95e9f3..095a44c4ad3f7b08c54e83bf2a7a32eb95501471 100644 (file)
@@ -11,6 +11,23 @@ if [ -d /run/systemd/system ]; then
     exit 0
 fi
 
+check_power()
+{
+    # laptop check, on_ac_power returns:
+    #       0 (true)    System is on main power
+    #       1 (false)   System is not on main power
+    #       255 (false) Power status could not be determined
+    # Desktop systems always return 255 it seems
+    if which on_ac_power >/dev/null 2>&1; then
+        on_ac_power
+        POWER=$?
+        if [ $POWER -eq 1 ]; then
+            return 1
+        fi
+    fi
+    return 0
+}
+
 # sleep for a random interval of time (default 30min)
 # (some code taken from cron-apt, thanks)
 random_sleep()
@@ -28,6 +45,11 @@ random_sleep()
     sleep $TIME
 }
 
-# run daily job
+# delay the job execution by a random amount of time
 random_sleep
+
+# ensure we don't do this on battery
+check_power || exit 0
+
+# run daily job
 exec /usr/lib/apt/apt.systemd.daily
index 15024c892907f81a2ff2b0f7802f6ab1100c8ffa..d034d8c1a3024c1cbd5c614269172251e7ffd7ee 100644 (file)
@@ -290,27 +290,6 @@ debug_echo()
     fi
 }
 
-check_power()
-{
-    # laptop check, on_ac_power returns:
-    #       0 (true)    System is on main power
-    #       1 (false)   System is not on main power
-    #       255 (false) Power status could not be determined
-    # Desktop systems always return 255 it seems
-    if which on_ac_power >/dev/null 2>&1; then
-        on_ac_power
-        POWER=$?
-        if [ $POWER -eq 1 ]; then
-           debug_echo "exit: system NOT on main power"
-           return 1
-        elif [ $POWER -ne 0 ]; then
-           debug_echo "power status ($POWER) undetermined, continuing"
-        fi
-        debug_echo "system is on main power."
-    fi
-    return 0
-}
-
 # ------------------------ main ----------------------------
 
 if test -r /var/lib/apt/extended_states; then
@@ -358,8 +337,6 @@ if [ "$VERBOSE" -ge 3 ]; then
     set -x
 fi
 
-check_power || exit 0
-
 # 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\"."
@@ -410,9 +387,6 @@ fi
 # deal with BackupArchiveInterval
 do_cache_backup $BackupArchiveInterval
 
-# ensure we don't do this on battery
-check_power || exit 0
-
 # include default system language so that "apt-get update" will
 # fetch the right translated package descriptions
 if [ -r /etc/default/locale ]; then