From 007b22ee6fd33d9b03637577f8401a43c5e7c90c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Apr 2017 19:58:56 +0200 Subject: Allow the daily script to be run in two phases This adds an argument to the script which may be update, install, or empty. In the update cases, downloads are performed. In the install case, installs are performed. If empty, both are run. Gbp-Dch: ignore --- debian/apt.systemd.daily | 146 ++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 71 deletions(-) diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily index 03d41bae5..54a8871ea 100755 --- a/debian/apt.systemd.daily +++ b/debian/apt.systemd.daily @@ -384,97 +384,101 @@ if [ $UpdateInterval -eq 0 ] && exit 0 fi -# deal with BackupArchiveInterval -do_cache_backup $BackupArchiveInterval - -# include default system language so that "apt-get update" will -# fetch the right translated package descriptions -if [ -r /etc/default/locale ]; then - . /etc/default/locale - export LANG LANGUAGE LC_MESSAGES LC_ALL -fi +if [ "$1" = "update" -o -z "$1" ] ; then + # deal with BackupArchiveInterval + do_cache_backup $BackupArchiveInterval + + # include default system language so that "apt-get update" will + # fetch the right translated package descriptions + if [ -r /etc/default/locale ]; then + . /etc/default/locale + export LANG LANGUAGE LC_MESSAGES LC_ALL + fi -# update package lists -UPDATED=0 -UPDATE_STAMP=/var/lib/apt/periodic/update-stamp -if check_stamp $UPDATE_STAMP $UpdateInterval; then - if eval apt-get $XAPTOPT -y update $XSTDERR; then - debug_echo "download updated metadata (success)." - if which dbus-send >/dev/null 2>&1 && pidof dbus-daemon >/dev/null 2>&1; then - if dbus-send --system / app.apt.dbus.updated boolean:true ; then - debug_echo "send dbus signal (success)" + # update package lists + UPDATED=0 + UPDATE_STAMP=/var/lib/apt/periodic/update-stamp + if check_stamp $UPDATE_STAMP $UpdateInterval; then + if eval apt-get $XAPTOPT -y update $XSTDERR; then + debug_echo "download updated metadata (success)." + if which dbus-send >/dev/null 2>&1 && pidof dbus-daemon >/dev/null 2>&1; then + if dbus-send --system / app.apt.dbus.updated boolean:true ; then + debug_echo "send dbus signal (success)" + else + debug_echo "send dbus signal (error)" + fi else - debug_echo "send dbus signal (error)" + debug_echo "dbus signal not send (command not available)" fi + update_stamp $UPDATE_STAMP + UPDATED=1 else - debug_echo "dbus signal not send (command not available)" + debug_echo "download updated metadata (error)" fi - update_stamp $UPDATE_STAMP - UPDATED=1 else - debug_echo "download updated metadata (error)" - fi -else - debug_echo "download updated metadata (not run)." -fi - -# download all upgradeable packages (if it is requested) -DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp -if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then - if [ $Debdelta -eq 1 ]; then - debdelta-upgrade >/dev/null 2>&1 || true + debug_echo "download updated metadata (not run)." fi - if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then - update_stamp $DOWNLOAD_UPGRADEABLE_STAMP - debug_echo "download upgradable (success)" + + # download all upgradeable packages (if it is requested) + DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp + if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then + if [ $Debdelta -eq 1 ]; then + debdelta-upgrade >/dev/null 2>&1 || true + fi + if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then + update_stamp $DOWNLOAD_UPGRADEABLE_STAMP + debug_echo "download upgradable (success)" + else + debug_echo "download upgradable (error)" + fi else - debug_echo "download upgradable (error)" + debug_echo "download upgradable (not run)" fi -else - debug_echo "download upgradable (not run)" fi -# auto upgrade all upgradeable packages -UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp -if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then - if unattended-upgrade $XUUPOPT; then - update_stamp $UPGRADE_STAMP - debug_echo "unattended-upgrade (success)" +if [ "$1" = "install" -o -z "$1" ] ; then + # auto upgrade all upgradeable packages + UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp + if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then + if unattended-upgrade $XUUPOPT; then + update_stamp $UPGRADE_STAMP + debug_echo "unattended-upgrade (success)" + else + debug_echo "unattended-upgrade (error)" + fi else - debug_echo "unattended-upgrade (error)" + debug_echo "unattended-upgrade (not run)" fi -else - debug_echo "unattended-upgrade (not run)" -fi -# clean package archive -CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp -if check_stamp $CLEAN_STAMP $CleanInterval; then - if eval apt-get $XAPTOPT -y clean $XSTDERR; then - debug_echo "clean (success)." - update_stamp $CLEAN_STAMP + # clean package archive + CLEAN_STAMP=/var/lib/apt/periodic/clean-stamp + if check_stamp $CLEAN_STAMP $CleanInterval; then + if eval apt-get $XAPTOPT -y clean $XSTDERR; then + debug_echo "clean (success)." + update_stamp $CLEAN_STAMP + else + debug_echo "clean (error)" + fi else - debug_echo "clean (error)" + debug_echo "clean (not run)" fi -else - debug_echo "clean (not run)" -fi -# autoclean package archive -AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp -if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then - if eval apt-get $XAPTOPT -y autoclean $XSTDERR; then - debug_echo "autoclean (success)." - update_stamp $AUTOCLEAN_STAMP + # autoclean package archive + AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp + if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then + if eval apt-get $XAPTOPT -y autoclean $XSTDERR; then + debug_echo "autoclean (success)." + update_stamp $AUTOCLEAN_STAMP + else + debug_echo "autoclean (error)" + fi else - debug_echo "autoclean (error)" + debug_echo "autoclean (not run)" fi -else - debug_echo "autoclean (not run)" -fi -# check cache size -check_size_constraints + # check cache size + check_size_constraints +fi # # vim: set sts=4 ai : -- cgit v1.2.3 From 01e324a6893164feace153bc17fe6453b6fa97db Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Apr 2017 21:39:16 +0200 Subject: Run unattended-upgrade -d in download part We want to download the upgrades first, if unattended-upgrades is configured. We don't want to use the normal dist-upgrade -d thing for it, though, as unattended-upgrades only upgrades a subset. --- debian/apt.systemd.daily | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily index 54a8871ea..a8d98494b 100755 --- a/debian/apt.systemd.daily +++ b/debian/apt.systemd.daily @@ -434,6 +434,17 @@ if [ "$1" = "update" -o -z "$1" ] ; then else debug_echo "download upgradable (not run)" fi + + if which unattended-upgrade >/dev/null 2>&1 && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $UnattendedUpgradeInterval; then + if unattended-upgrade -d $XUUPOPT; then + update_stamp $DOWNLOAD_UPGRADEABLE_STAMP + debug_echo "unattended-upgrade -d (success)" + else + debug_echo "unattended-upgrade -d (error)" + fi + else + debug_echo "unattended-upgrade -d (not run)" + fi fi if [ "$1" = "install" -o -z "$1" ] ; then -- cgit v1.2.3 From ea49b66372912354143b810e2826301d651a2b37 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 28 Apr 2017 11:11:53 +0200 Subject: apt.systemd.daily: Add locking Use a lock file to make sure only one instance of the script is running at the same time. --- debian/apt.systemd.daily | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily index a8d98494b..22cbbded6 100755 --- a/debian/apt.systemd.daily +++ b/debian/apt.systemd.daily @@ -292,6 +292,16 @@ debug_echo() # ------------------------ main ---------------------------- +# Maintain a lock on fd 3, so we can't run the script twice at the same +# time. +LOCKFD=3 +eval $(apt-config shell StateDir Dir::State/d) +exec 3>${StateDir}/daily_lock +if ! flock -w 3600 $LOCKFD; then + echo "E: Could not acquire lock" >&2 + exit 1 +fi + if test -r /var/lib/apt/extended_states; then # Backup the 7 last versions of APT's extended_states file # shameless copy from dpkg cron @@ -423,9 +433,9 @@ if [ "$1" = "update" -o -z "$1" ] ; then DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then if [ $Debdelta -eq 1 ]; then - debdelta-upgrade >/dev/null 2>&1 || true + debdelta-upgrade >/dev/null 2>&1 $LOCKFD>&- || true fi - if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then + if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR $LOCKFD>&-; then update_stamp $DOWNLOAD_UPGRADEABLE_STAMP debug_echo "download upgradable (success)" else @@ -436,7 +446,7 @@ if [ "$1" = "update" -o -z "$1" ] ; then fi if which unattended-upgrade >/dev/null 2>&1 && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $UnattendedUpgradeInterval; then - if unattended-upgrade -d $XUUPOPT; then + if unattended-upgrade -d $XUUPOPT $LOCKFD>&-; then update_stamp $DOWNLOAD_UPGRADEABLE_STAMP debug_echo "unattended-upgrade -d (success)" else @@ -451,7 +461,7 @@ if [ "$1" = "install" -o -z "$1" ] ; then # auto upgrade all upgradeable packages UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then - if unattended-upgrade $XUUPOPT; then + if unattended-upgrade $XUUPOPT $LOCKFD>&-; then update_stamp $UPGRADE_STAMP debug_echo "unattended-upgrade (success)" else -- cgit v1.2.3 From 496313fb8e83af2ba71f6ce3d729be687c293dfd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 26 Apr 2017 20:03:56 +0200 Subject: Split apt-daily timer into two The timer doing downloading runs throughout the day, whereas automatic upgrade and clean actions only happen in the morning. The upgrade service and timer have After= ordering requirements on their non-upgrade counterparts to ensure that upgrading at boot takes place after downloading. LP: #1686470 --- debian/apt-daily-upgrade.service | 9 +++++++++ debian/apt-daily-upgrade.timer | 11 +++++++++++ debian/apt-daily.service | 4 ++-- debian/apt-daily.timer | 6 +++--- debian/rules | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 debian/apt-daily-upgrade.service create mode 100644 debian/apt-daily-upgrade.timer diff --git a/debian/apt-daily-upgrade.service b/debian/apt-daily-upgrade.service new file mode 100644 index 000000000..bf2776ac8 --- /dev/null +++ b/debian/apt-daily-upgrade.service @@ -0,0 +1,9 @@ +[Unit] +Description=Daily apt upgrade and clean activities +Documentation=man:apt(8) +ConditionACPower=true +After=apt-daily.service + +[Service] +Type=oneshot +ExecStart=/usr/lib/apt/apt.systemd.daily install diff --git a/debian/apt-daily-upgrade.timer b/debian/apt-daily-upgrade.timer new file mode 100644 index 000000000..79caf3b5c --- /dev/null +++ b/debian/apt-daily-upgrade.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Daily apt upgrade and clean activities +After=apt-daily.timer + +[Timer] +OnCalendar=*-*-* 6:00 +RandomizedDelaySec=60m +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/debian/apt-daily.service b/debian/apt-daily.service index 904ed5d51..4a946afdd 100644 --- a/debian/apt-daily.service +++ b/debian/apt-daily.service @@ -1,9 +1,9 @@ [Unit] -Description=Daily apt activities +Description=Daily apt download activities Documentation=man:apt(8) ConditionACPower=true [Service] Type=oneshot -ExecStart=/usr/lib/apt/apt.systemd.daily +ExecStart=/usr/lib/apt/apt.systemd.daily update diff --git a/debian/apt-daily.timer b/debian/apt-daily.timer index 8ac13b0e9..735da2440 100644 --- a/debian/apt-daily.timer +++ b/debian/apt-daily.timer @@ -1,11 +1,11 @@ [Unit] -Description=Daily apt activities +Description=Daily apt download activities After=network-online.target Wants=network-online.target [Timer] -OnCalendar=*-*-* 6:00 -RandomizedDelaySec=60m +OnCalendar=*-*-* 6,18:00 +RandomizedDelaySec=12h Persistent=true [Install] diff --git a/debian/rules b/debian/rules index 5f990c72e..247022398 100755 --- a/debian/rules +++ b/debian/rules @@ -37,7 +37,7 @@ override_dh_systemd_start: # Do not restart "apt-daily.service" because this script runs # unattended-upgrades. So if apt itself is upgraded as part of # an unattended-upgrades run it would kill itself - dh_systemd_start apt-daily.timer + dh_systemd_start apt-daily.timer apt-daily-upgrade.timer override_dh_auto_configure-arch: flags=-DWITH_DOC=OFF override_dh_auto_configure-indep: flags=-DWITH_DOC=ON -- cgit v1.2.3